public async Task <IActionResult> UpdateVisitType(int id, VisitTypeForUpdateDto visitType) { var visitTypeFromRepo = await _visitTypeRepository.GetVisitTypeAsync(id); if (visitTypeFromRepo == null) { return(NotFound()); } var validationResults = new VisitTypeForUpdateDtoValidator().Validate(visitType); validationResults.AddToModelState(ModelState, null); if (!ModelState.IsValid) { return(BadRequest(new ValidationProblemDetails(ModelState))); //return ValidationProblem(); } _mapper.Map(visitType, visitTypeFromRepo); _visitTypeRepository.UpdateVisitType(visitTypeFromRepo); await _visitTypeRepository.SaveAsync(); return(NoContent()); }
public async Task <IActionResult> Edit([FromForm] VisitTypeViewModel visitTypeVM) { if (ModelState.IsValid) { await _visitTypeRepo.UpdateVisitType(visitTypeVM.VisitType); TempData["message"] = "Your data has been updated successfully."; TempData["toasterType"] = ToasterType.success; return(RedirectToAction(nameof(Edit), new { id = visitTypeVM.VisitType.Id, returnUrl = visitTypeVM.ReturnUrl })); } else { TempData["message"] = "A problem has been ocurred while updating your data."; TempData["toasterType"] = ToasterType.info; } return(View("Edit", VisitTypeViewModelFactory.Edit(visitTypeVM.VisitType, visitTypeVM.ReturnUrl))); }