public async Task <IActionResult> EditMachine(AgriculturalMachineryWithOwnerNameModel model) { if (ModelState.IsValid) { try { var userId = this.User.GetUserId(); if (userId == null) { throw new NullReferenceException("User does not exist"); } await this.agriculturalMachineryService.EditMachineAsync(model, userId); return(Ok()); } catch (Exception e) { var msg = e; var error = StatusCode(500, msg); return(error); } } else { var msg = ModelState.GetErrors(); var error = StatusCode(500, msg); return(error); } }
public async Task EditMachineAsync(AgriculturalMachineryWithOwnerNameModel model, string userId) { var machine = _context.AgriculturalMachinery.Where(am => am.Id == model.Id && !am.Deleted).FirstOrDefault(); if (machine != null) { machine.RegistrationNumber = model.RegistrationNumber; machine.FrameNumber = model.FrameNumber; machine.Type = model.Type; SetUpdateStamp(machine, userId); await _context.SaveChangesAsync(); } }