public IActionResult Update(DestinationCreateViewModel dest) { if (ModelState.IsValid) { string fileName = dest.ImageFile; // Delete old image DeleteImage(fileName); if (dest.Image != null) { // Save new image fileName = SaveImage(dest); } else if (dest.ImageUrl != null) { // No image has been specified so save the static map as the image fileName = dest.ImageUrl; } Destination updatedDest = _destinationRepo.Get(dest.Id, User.Identity.Name); Console.WriteLine("updatedDest" + updatedDest); Console.WriteLine(dest.Address); updatedDest.Address = dest.Address; updatedDest.Lat = dest.Lat; updatedDest.Lng = dest.Lng; updatedDest.Details = dest.Details; updatedDest.ImageFile = fileName; updatedDest.Visited = dest.Visited; _destinationRepo.Update(updatedDest); return(RedirectToAction("Show", new { id = updatedDest.Id })); } return(View("Edit", dest)); }
public async Task <ActionResult> PartialDestinationUpdateAsync(int id, JsonPatchDocument <DestinationUpdateDto> patchDoc) { var destinationModelFromRepo = await _repository.GetByIdAsync(id); if (destinationModelFromRepo == null) { return(NotFound()); } var destinationToPatch = _mapper.Map <DestinationUpdateDto>(destinationModelFromRepo); patchDoc.ApplyTo(destinationToPatch, ModelState); if (!TryValidateModel(destinationToPatch)) { return(ValidationProblem(ModelState)); } _mapper.Map(destinationToPatch, destinationModelFromRepo); _repository.Update(destinationModelFromRepo); await _repository.SaveChangesAsync(); return(NoContent()); }