/// <summary> /// Edits the <see cref="ServiceType"/> using <see cref="EditServiceTypeServiceModel"/>. /// </summary> /// <param name="model">Number of modified entities.</param> /// <returns>Service model with <c>Id</c>, <c>Name</c>, <c>Description</c> and <c>IsShownInMainMenu</c>.</returns> public async Task <int> EditAsync(EditServiceTypeServiceModel model) { ServiceType serviceType = this.dbContext.ServiceTypes.Find(model.Id); serviceType.Name = model.Name; serviceType.Description = model.Description; serviceType.IsShownInMainMenu = model.IsShownInMainMenu; int modifiedEntities = await this.dbContext.SaveChangesAsync(); return(modifiedEntities); }
public async Task <IActionResult> Edit(ServiceTypeInputModel model) { if (!this.serviceTypesService.Exists(model.Id)) { return(this.BadRequest()); } if (!ModelState.IsValid) { return(this.RedirectToAction("Error", "Home")); } EditServiceTypeServiceModel serviceModel = new EditServiceTypeServiceModel { Id = model.Id, Name = model.ServiceTypeName, Description = model.ServiceTypeDescription, IsShownInMainMenu = model.IsShownInMainMenu, }; await this.serviceTypesService.EditAsync(serviceModel); return(this.RedirectToAction("Details", "ServiceTypes", new { id = serviceModel.Id })); }