public async Task <IActionResult> Edit(int id, EditServiceModel serviceModel) { if (!this.ModelState.IsValid) { return(this.View(serviceModel)); } var serviceServiceModel = AutoMapperConfig.MapperInstance.Map <EditServiceServiceModel>(serviceModel); await this.servicesService.EditAsync(id, serviceServiceModel); return(this.RedirectToAction("Index")); }
public ActionResult EditService(EditServiceModel model) { try { if (ModelState.IsValid) { // Get service var service = db.CarServices.Where(r => r.serviceId == model.serviceId).FirstOrDefault(); if (service != null) { // Check service name exsited var serviceExisted = db.CarServices .Where(r => r.serviceId != model.serviceId && String.Compare(r.serviceName, model.serviceName, true) == 0) .FirstOrDefault(); if (serviceExisted == null) { // Update service service.serviceName = model.serviceName; service.groupId = model.groupId; service.iconURL = model.iconURL; service.description = model.description; db.SaveChanges(); return(RedirectToAction("ListServices", new { groupID = model.groupId })); } else { ModelState.AddModelError("", "Dịch vụ #" + model.serviceName + " đã tồn tại trong hệ thống! Vui lòng nhập tên khác"); } } else { ModelState.AddModelError("", "Dịch vụ mã #" + model.serviceId + " không tồn tại trong hệ thống!"); } } } catch (Exception ex) { ModelState.AddModelError("", ex.ToString()); EventWriter.WriteEventLog("SystemController - EditService: " + ex.ToString()); } return(View(model)); }
public ResponseWrapper <EditServiceModel> EditService(int serviceId, EditServiceInputModel model) { var entity = context .Services .Single(x => x.ServiceId == serviceId ); entity.Name = model.Name; entity.PluralName = model.PluralName; entity.ApplicationId = model.ApplicationId; context.SaveChanges(); var response = new EditServiceModel { ServiceId = entity.ServiceId, Name = entity.Name, PluralName = entity.PluralName, ApplicationId = entity.ApplicationId, }; return(new ResponseWrapper <EditServiceModel>(_validationDictionary, response)); }
public ActionResult EditService(int id) { var model = new EditServiceModel(); try { var service = db.CarServices.Where(r => r.serviceId == id).FirstOrDefault(); if (service != null) { var group = db.CarServiceGroups.Where(r => r.groupId == service.groupId).FirstOrDefault(); if (group != null) { model.serviceId = service.serviceId; model.serviceName = service.serviceName; model.groupId = service.groupId; model.groupName = group.groupName; model.iconURL = service.iconURL; model.description = service.description; } else { ModelState.AddModelError("", "Nhóm dịch vụ mã #" + service.groupId + " không tồn tại trong hệ thống!"); } } else { ModelState.AddModelError("", "Dịch vụ mã #" + id + " không tồn tại trong hệ thống!"); } } catch (Exception ex) { ModelState.AddModelError("", ex.ToString()); EventWriter.WriteEventLog("SystemController - EditService: " + ex.ToString()); } return(View(model)); }