public async Task <IActionResult> UpdateModel(UpdateModelDto updateModel) { ServiceResponse <Model> response = await _modelService.Update(updateModel); if (response.Data == null) { return(NotFound(response)); } return(Ok(response)); }
public async Task <ActionResult <ReadModelDto> > UpdateVehicleModel(UpdateModelDto updatedModel) { var targetModel = (await ReadVehicleModel(updatedModel.Id)).Value; if (targetModel != null) { _context.Entry(targetModel).CurrentValues.SetValues(updatedModel); await _context.SaveChangesAsync(); } return(targetModel); }
public async Task <ServiceResponse <Model> > Update(UpdateModelDto updateModel) { ServiceResponse <Model> serviceResponse = new ServiceResponse <Model>(); try { var updatedModel = _context.Models.FirstOrDefault(m => m.Id == updateModel.Id); updatedModel.Name = updateModel.Name; _context.SaveChanges(); serviceResponse.Data = updatedModel; } catch (Exception ex) { serviceResponse.Success = false; serviceResponse.Message = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; } return(serviceResponse); }