Add option to consolidate one ATA from another.

This commit is contained in:
2019-11-10 01:07:12 +00:00
parent fd42b81b15
commit 5a9fa9b958
5 changed files with 56 additions and 8 deletions

View File

@@ -149,6 +149,52 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
return RedirectToAction(nameof(Index)); return RedirectToAction(nameof(Index));
} }
public IActionResult ConsolidateWithIds(int masterId, int slaveId)
{
if(_context.Ata.Count(m => m.Id == masterId) == 0)
return RedirectToAction(nameof(Compare), new
{
id = masterId, rightId = slaveId
});
if(_context.Ata.Count(m => m.Id == slaveId) == 0)
return RedirectToAction(nameof(Compare), new
{
id = masterId, rightId = slaveId
});
foreach(Device ataDevice in _context.Devices.Where(d => d.ATAId == slaveId))
{
ataDevice.ATAId = masterId;
}
foreach(Device atapiDevice in _context.Devices.Where(d => d.ATAPIId == slaveId))
{
atapiDevice.ATAPIId = masterId;
}
foreach(UploadedReport ataReport in _context.Reports.Where(d => d.ATAId == slaveId))
{
ataReport.ATAId = masterId;
}
foreach(UploadedReport atapiReport in _context.Reports.Where(d => d.ATAPIId == slaveId))
{
atapiReport.ATAPIId = masterId;
}
foreach(TestedMedia testedMedia in _context.TestedMedia.Where(d => d.AtaId == slaveId))
{
testedMedia.AtaId = masterId;
}
_context.Ata.Remove(_context.Ata.First(d => d.Id == slaveId));
_context.SaveChanges();
return RedirectToAction(nameof(Index));
}
public IActionResult Compare(int id, int rightId) public IActionResult Compare(int id, int rightId)
{ {
var model = new CompareModel(); var model = new CompareModel();
@@ -213,8 +259,8 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields()) foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields())
{ {
object? lv = fieldInfo.GetValue(leftValue); object lv = fieldInfo.GetValue(leftValue);
object? rv = fieldInfo.GetValue(rightValue); object rv = fieldInfo.GetValue(rightValue);
if(fieldInfo.FieldType.IsArray) if(fieldInfo.FieldType.IsArray)
{ {

View File

@@ -79,4 +79,6 @@
</table> </table>
<a asp-action="Index" class="btn btn-primary">Back to List</a> <a asp-action="Index" class="btn btn-primary">Back to List</a>
<a asp-action="Delete" asp-route-id="@Model.LeftId" class="btn btn-danger">Delete ID @Model.LeftId</a> <a asp-action="Delete" asp-route-id="@Model.LeftId" class="btn btn-danger">Delete ID @Model.LeftId</a>
<a asp-action="Delete" asp-route-id="@Model.RightId" class="btn btn-danger">Delete ID @Model.RightId</a> <a asp-action="Delete" asp-route-id="@Model.RightId" class="btn btn-danger">Delete ID @Model.RightId</a>
<a asp-action="ConsolidateWithIds" asp-route-masterId="@Model.LeftId" asp-route-slaveId="@Model.RightId" class="btn btn-secondary">Replace all dependencies from ID @Model.RightId with ID @Model.LeftId</a>
<a asp-action="ConsolidateWithIds" asp-route-masterId="@Model.RightId" asp-route-slaveId="@Model.LeftId" class="btn btn-secondary">Replace all dependencies from ID @Model.LeftId with ID @Model.RightId</a>

View File

@@ -65,7 +65,7 @@ namespace DiscImageChef.Server.Models
[DefaultValue(0)] [DefaultValue(0)]
public int OptimalMultipleSectorsRead { get; set; } public int OptimalMultipleSectorsRead { get; set; }
public int ATAId { get; set; } public int? ATAId { get; set; }
public int ATAPIId { get; set; } public int? ATAPIId { get; set; }
} }
} }

View File

@@ -58,7 +58,7 @@ namespace DiscImageChef.Server.Models
} }
public DateTime UploadedWhen { get; set; } public DateTime UploadedWhen { get; set; }
public int ATAId { get; set; } public int? ATAId { get; set; }
public int ATAPIId { get; set; } public int? ATAPIId { get; set; }
} }
} }