mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Update only changed fields on editing.
This commit is contained in:
@@ -43,30 +43,34 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost, ValidateAntiForgeryToken]
|
[HttpPost, ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(int id, [Bind("Id,Manufacturer,Model,Offset,Submissions,Agreement")]
|
public async Task<IActionResult> Edit(int id, [Bind("Id,Manufacturer,Model,Offset,Submissions,Agreement")]
|
||||||
CompactDiscOffset compactDiscOffset)
|
CompactDiscOffset changedModel)
|
||||||
{
|
{
|
||||||
if(id != compactDiscOffset.Id)
|
if(id != changedModel.Id)
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
if(!ModelState.IsValid)
|
if(!ModelState.IsValid)
|
||||||
return View(compactDiscOffset);
|
return View(changedModel);
|
||||||
|
|
||||||
|
CompactDiscOffset model = await _context.CdOffsets.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
|
if(model is null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
model.Manufacturer = changedModel.Manufacturer;
|
||||||
|
model.Model = changedModel.Model;
|
||||||
|
model.Offset = changedModel.Offset;
|
||||||
|
model.Submissions = changedModel.Submissions;
|
||||||
|
model.Agreement = changedModel.Agreement;
|
||||||
|
model.ModifiedWhen = DateTime.UtcNow;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
compactDiscOffset.ModifiedWhen = DateTime.UtcNow;
|
_context.Update(model);
|
||||||
_context.Update(compactDiscOffset);
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch(DbUpdateConcurrencyException)
|
catch(DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if(!CompactDiscOffsetExists(compactDiscOffset.Id))
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
@@ -101,8 +105,6 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CompactDiscOffsetExists(int id) => _context.CdOffsets.Any(e => e.Id == id);
|
|
||||||
|
|
||||||
public IActionResult Update() => throw new NotImplementedException();
|
public IActionResult Update() => throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,34 +42,35 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost, ValidateAntiForgeryToken]
|
[HttpPost, ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(int id, [Bind("Id,Manufacturer,Model,Revision,Bus")]
|
public async Task<IActionResult> Edit(int id, [Bind("Id,Manufacturer,Model,Revision,Bus")]
|
||||||
DeviceStat deviceStat)
|
DeviceStat changedModel)
|
||||||
{
|
{
|
||||||
if(id != deviceStat.Id)
|
if(id != changedModel.Id)
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
if(!ModelState.IsValid)
|
||||||
|
return View(changedModel);
|
||||||
|
|
||||||
|
DeviceStat model = await _context.DeviceStats.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
|
if(model is null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
model.Manufacturer = changedModel.Manufacturer;
|
||||||
|
model.Model = changedModel.Model;
|
||||||
|
model.Revision = changedModel.Revision;
|
||||||
|
model.Bus = changedModel.Bus;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
_context.Update(model);
|
||||||
{
|
await _context.SaveChangesAsync();
|
||||||
_context.Update(deviceStat);
|
}
|
||||||
await _context.SaveChangesAsync();
|
catch(DbUpdateConcurrencyException)
|
||||||
}
|
{
|
||||||
catch(DbUpdateConcurrencyException)
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||||
{
|
|
||||||
if(!DeviceStatExists(deviceStat.Id))
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(deviceStat);
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: Admin/DeviceStats/Delete/5
|
// GET: Admin/DeviceStats/Delete/5
|
||||||
@@ -100,7 +101,5 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeviceStatExists(int id) => _context.DeviceStats.Any(e => e.Id == id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,30 +119,35 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
[HttpPost, ValidateAntiForgeryToken]
|
[HttpPost, ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(
|
public async Task<IActionResult> Edit(
|
||||||
int id, [Bind("OptimalMultipleSectorsRead,Id,CompactFlash,Manufacturer,Model,Revision,Type")]
|
int id, [Bind("OptimalMultipleSectorsRead,Id,CompactFlash,Manufacturer,Model,Revision,Type")]
|
||||||
Device device)
|
Device changedModel)
|
||||||
{
|
{
|
||||||
if(id != device.Id)
|
if(id != changedModel.Id)
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
if(!ModelState.IsValid)
|
if(!ModelState.IsValid)
|
||||||
return View(device);
|
return View(changedModel);
|
||||||
|
|
||||||
|
Device model = await _context.Devices.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
|
if(model is null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
model.OptimalMultipleSectorsRead = changedModel.OptimalMultipleSectorsRead;
|
||||||
|
model.CompactFlash = changedModel.CompactFlash;
|
||||||
|
model.Manufacturer = changedModel.Manufacturer;
|
||||||
|
model.Model = changedModel.Model;
|
||||||
|
model.Revision = changedModel.Revision;
|
||||||
|
model.Type = changedModel.Type;
|
||||||
|
model.ModifiedWhen = DateTime.UtcNow;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
device.ModifiedWhen = DateTime.UtcNow;
|
_context.Update(model);
|
||||||
_context.Update(device);
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch(DbUpdateConcurrencyException)
|
catch(DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if(!DeviceExists(device.Id))
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
|
|||||||
@@ -45,34 +45,36 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
[HttpPost, ValidateAntiForgeryToken]
|
[HttpPost, ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(
|
public async Task<IActionResult> Edit(
|
||||||
int id, [Bind("Id,VendorID,ProductID,Manufacturer,Product,RemovableMedia")]
|
int id, [Bind("Id,VendorID,ProductID,Manufacturer,Product,RemovableMedia")]
|
||||||
FireWire fireWire)
|
FireWire changedModel)
|
||||||
{
|
{
|
||||||
if(id != fireWire.Id)
|
if(id != changedModel.Id)
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
if(!ModelState.IsValid)
|
||||||
|
return View(changedModel);
|
||||||
|
|
||||||
|
FireWire model = await _context.FireWire.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
|
if(model is null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
model.VendorID = changedModel.VendorID;
|
||||||
|
model.ProductID = changedModel.ProductID;
|
||||||
|
model.Manufacturer = changedModel.Manufacturer;
|
||||||
|
model.Product = changedModel.Product;
|
||||||
|
model.RemovableMedia = changedModel.RemovableMedia;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
_context.Update(model);
|
||||||
{
|
await _context.SaveChangesAsync();
|
||||||
_context.Update(fireWire);
|
}
|
||||||
await _context.SaveChangesAsync();
|
catch(DbUpdateConcurrencyException)
|
||||||
}
|
{
|
||||||
catch(DbUpdateConcurrencyException)
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||||
{
|
|
||||||
if(!FireWireExists(fireWire.Id))
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(fireWire);
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: Admin/FireWires/Delete/5
|
// GET: Admin/FireWires/Delete/5
|
||||||
|
|||||||
@@ -106,29 +106,33 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost, ValidateAntiForgeryToken]
|
[HttpPost, ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(int id, [Bind("Id,CompactFlash,Manufacturer,Model,Revision,Type")]
|
public async Task<IActionResult> Edit(int id, [Bind("Id,CompactFlash,Manufacturer,Model,Revision,Type")]
|
||||||
UploadedReport uploadedReport)
|
UploadedReport changedModel)
|
||||||
{
|
{
|
||||||
if(id != uploadedReport.Id)
|
if(id != changedModel.Id)
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
if(!ModelState.IsValid)
|
if(!ModelState.IsValid)
|
||||||
return View(uploadedReport);
|
return View(changedModel);
|
||||||
|
|
||||||
|
UploadedReport model = await _context.Reports.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
|
if(model is null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
model.CompactFlash = changedModel.CompactFlash;
|
||||||
|
model.Manufacturer = changedModel.Manufacturer;
|
||||||
|
model.Model = changedModel.Model;
|
||||||
|
model.Revision = changedModel.Revision;
|
||||||
|
model.Type = changedModel.Type;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_context.Update(uploadedReport);
|
_context.Update(model);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch(DbUpdateConcurrencyException)
|
catch(DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if(!UploadedReportExists(uploadedReport.Id))
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
|
|||||||
@@ -75,34 +75,37 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
[HttpPost, ValidateAntiForgeryToken]
|
[HttpPost, ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(
|
public async Task<IActionResult> Edit(
|
||||||
int id, [Bind("Id,Blocks,BlockSize,LongBlockSize,Manufacturer,MediumTypeName,Model")]
|
int id, [Bind("Id,Blocks,BlockSize,LongBlockSize,Manufacturer,MediumTypeName,Model")]
|
||||||
TestedMedia testedMedia)
|
TestedMedia changedModel)
|
||||||
{
|
{
|
||||||
if(id != testedMedia.Id)
|
if(id != changedModel.Id)
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
if(ModelState.IsValid)
|
if(!ModelState.IsValid)
|
||||||
|
return View(changedModel);
|
||||||
|
|
||||||
|
TestedMedia model = await _context.TestedMedia.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
|
if(model is null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
model.Blocks = changedModel.Blocks;
|
||||||
|
model.BlockSize = changedModel.BlockSize;
|
||||||
|
model.LongBlockSize = changedModel.LongBlockSize;
|
||||||
|
model.Manufacturer = changedModel.Manufacturer;
|
||||||
|
model.MediumTypeName = changedModel.MediumTypeName;
|
||||||
|
model.Model = changedModel.Model;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
_context.Update(model);
|
||||||
{
|
await _context.SaveChangesAsync();
|
||||||
_context.Update(testedMedia);
|
}
|
||||||
await _context.SaveChangesAsync();
|
catch(DbUpdateConcurrencyException)
|
||||||
}
|
{
|
||||||
catch(DbUpdateConcurrencyException)
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||||
{
|
|
||||||
if(!TestedMediaExists(testedMedia.Id))
|
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return View(testedMedia);
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
// GET: Admin/TestedMedias/Delete/5
|
// GET: Admin/TestedMedias/Delete/5
|
||||||
|
|||||||
@@ -43,29 +43,31 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||||
[HttpPost, ValidateAntiForgeryToken]
|
[HttpPost, ValidateAntiForgeryToken]
|
||||||
public async Task<IActionResult> Edit(int id, [Bind("Id,Manufacturer,MediumTypeName,Model")]
|
public async Task<IActionResult> Edit(int id, [Bind("Id,Manufacturer,MediumTypeName,Model")]
|
||||||
TestedSequentialMedia testedSequentialMedia)
|
TestedSequentialMedia changedModel)
|
||||||
{
|
{
|
||||||
if(id != testedSequentialMedia.Id)
|
if(id != changedModel.Id)
|
||||||
{
|
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
|
||||||
|
|
||||||
if(!ModelState.IsValid)
|
if(!ModelState.IsValid)
|
||||||
return View(testedSequentialMedia);
|
return View(changedModel);
|
||||||
|
|
||||||
|
TestedSequentialMedia model = await _context.TestedSequentialMedia.FirstOrDefaultAsync(m => m.Id == id);
|
||||||
|
|
||||||
|
if(model is null)
|
||||||
|
return NotFound();
|
||||||
|
|
||||||
|
model.Manufacturer = changedModel.Manufacturer;
|
||||||
|
model.MediumTypeName = changedModel.MediumTypeName;
|
||||||
|
model.Model = changedModel.Model;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_context.Update(testedSequentialMedia);
|
_context.Update(model);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
catch(DbUpdateConcurrencyException)
|
catch(DbUpdateConcurrencyException)
|
||||||
{
|
{
|
||||||
if(!TestedSequentialMediaExists(testedSequentialMedia.Id))
|
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||||
{
|
|
||||||
return NotFound();
|
|
||||||
}
|
|
||||||
|
|
||||||
throw;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
@@ -100,7 +102,5 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
|||||||
|
|
||||||
return RedirectToAction(nameof(Index));
|
return RedirectToAction(nameof(Index));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TestedSequentialMediaExists(int id) => _context.TestedSequentialMedia.Any(e => e.Id == id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user