public async Task <ActionResult <CustomerViewModel> > Update(int id, CustomerViewModel customer) { if (ModelState.IsValid) { var customerModel = _mapper.Map <CustomerProfile>(customer); var(custProfile, errorMsg) = await _repository.UpdateCustomerProfile(id, customerModel); if (custProfile != null) { var customerProfileVM = _mapper.Map <CustomerViewModel>(custProfile); return(Ok(customerProfileVM)); } return(BadRequest(errorMsg)); } return(BadRequest(ModelState)); }
public ActionResult Update(CustomerProfileViewModel model) { if (ModelState.IsValid) { (var customerProfile, string errorMsg) = _customerProfileRepository.UpdateCustomerProfile(model); if (string.IsNullOrEmpty(errorMsg)) { return(RedirectToAction("Index")); } TempData["ErrorMessage"] = errorMsg; } else { TempData["ErrorMessage"] = "Error while updating customer profile."; } TempData.Keep("ErrorMessage"); return(RedirectToAction($"Edit/{model.Id}")); }