public async Task <IActionResult> PartiallyUpdateStop(int id, [FromBody] JsonPatchDocument <StopForUpdateDTO> patchDoc) { if (patchDoc == null) { return(BadRequest()); } StopForUpdateDTO stopModel = await _stopBus.GetUpdateModelForStop(id); if (stopModel == null) { return(NotFound()); } patchDoc.ApplyTo(stopModel, ModelState); TryValidateModel(stopModel); if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var stopResult = await _stopBus.UpdateStop(id, stopModel); if (stopResult == null || stopResult.Result == null) { return(StatusCode(500, "Update failure")); } return(NoContent()); }
public async Task <ResourceDataResult> UpdateStop(int stopId, StopForUpdateDTO stopModel) { ResourceDataResult result = new ResourceDataResult(); var stop = await _stopRepo.GetStopById(stopId); //upsert if (stop == null) { result.StatusCode = 201; stop = new Stop() { Id = stopId }; } stop = StopMapper.UpdateEntityToModel(stop, stopModel); if (stop != null && await _stopRepo.UpdateStop(stop)) { result.Result = StopMapper.ConvertEntityToModel(stop); return(result); } return(null); }
public static Stop UpdateEntityToModel(Stop stop, StopForUpdateDTO stopInput, bool isPartialUpdate = false) { stop.Description = stopInput.Description; stop.Name = stopInput.Name; stop.Latitude = stopInput.Latitude; stop.Longitude = stopInput.Longitude; return(stop); }
public async Task <StopForUpdateDTO> GetUpdateModelForStop(int stopId) { var stop = await _stopRepo.GetStopById(stopId); if (stop == null) { return(null); } StopForUpdateDTO updatedStop = StopMapper.ConvertEntityToModel <StopForUpdateDTO>(stop); return(updatedStop); }
public async Task <IActionResult> UpdateStop(int id, [FromBody] StopForUpdateDTO stopInput) { if (stopInput == null) { return(BadRequest()); } if (stopInput.Latitude > 360 || stopInput.Longitude > 360) { ModelState.AddModelError(nameof(StopForUpdateDTO), "Latitude and longitude can be specified up to 360 degrees"); } if (string.IsNullOrWhiteSpace(stopInput.Name)) { ModelState.AddModelError(nameof(StopForUpdateDTO), "Empty name is invalid!"); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } var stopResult = await _stopBus.UpdateStop(id, stopInput); if (stopResult == null || stopResult.Result == null) { return(StatusCode(500, "Update failure")); } StopDTO stop = stopResult.Result as StopDTO; if (stopResult.StatusCode == 201) { return(CreatedAtRoute("GetStop", new { id = stop.Id }, stop)); } return(NoContent()); }
public static Stop ConvertUpdateModelToEntity(StopForUpdateDTO stopInput) { return(AutoMapperContainer.GenericConvert <Stop>(stopInput)); }