public async Task <IActionResult> Edit(ServiceType serviceType) { if (ModelState.IsValid) { try { await _serviceTypeRepository.UpdateServiceTypeAsync(serviceType); return(RedirectToAction(nameof(Index))); } catch (DbUpdateException dbUpdateException) { if (dbUpdateException.InnerException.Message.Contains("duplicate")) { ModelState.AddModelError(string.Empty, "There are a record with the same name."); } else { ModelState.AddModelError(string.Empty, dbUpdateException.InnerException.Message); } } catch (Exception exception) { ModelState.AddModelError(string.Empty, exception.Message); } } return(View(serviceType)); }
public async Task <IActionResult> EditServiceTypeAsync(EditServiceTypeViewModel model) { var serviceType = await _serviceTypeRepository.GetServiceTypeByIdAsync(model.Id); if (serviceType == null) { ViewBag.ErrorMessage = $"User with user id ={model.Id} cannot be found"; return(View("NotFound")); } else { serviceType.ServiceName = model.ServiceTypeName; serviceType.ServiceDescription = model.Description; serviceType.Pricing = model.Pricing; await _serviceTypeRepository.UpdateServiceTypeAsync(serviceType); return(RedirectToAction("ListServiceTypes", "Admin")); } }
public async Task <IActionResult> UpdateServiceType(int id, EditServiceTypeDto serviceTypeDto) { var result = await _repository.UpdateServiceTypeAsync(id, serviceTypeDto); return(Ok(result)); }