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:
@@ -106,29 +106,33 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
||||
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
||||
[HttpPost, ValidateAntiForgeryToken]
|
||||
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();
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
_context.Update(uploadedReport);
|
||||
_context.Update(model);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch(DbUpdateConcurrencyException)
|
||||
{
|
||||
if(!UploadedReportExists(uploadedReport.Id))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
throw;
|
||||
ModelState.AddModelError("Concurrency", "Concurrency error, please report to the administrator.");
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
|
||||
Reference in New Issue
Block a user