public JsonResult Save(OperationEditViewModel model) { var result = new JsonResultBO(true); try { if (ModelState.IsValid) { if (model.Id <= 0) { Operation entity = new Operation() { Name = model.Name, Code = model.Code, URL = model.URL, IsShow = model.IsShow, Order = model.Order.ToNumber <int>(), ModuleId = model.ModuleId }; _operationService.Create(entity); _Ilog.InfoFormat("Thêm mới thao tác {0}", model.Name); } else { Operation entity = _operationService.GetById(model.Id); entity.Name = model.Name; entity.Code = model.Code; entity.URL = model.URL; entity.IsShow = model.IsShow; entity.Order = model.Order.ToNumber <int>(); _operationService.Update(entity); _Ilog.InfoFormat("Cập nhật thao tác {0}", model.Name); } return(Json(result)); } result.Message = ModelState.GetErrors(); result.Status = false; return(Json(result)); } catch (Exception ex) { result.Status = false; result.Message = "Không cập nhật được"; _Ilog.Error("Lỗi cập nhật thông tin Thao tác", ex); } return(Json(result)); }
public PartialViewResult Edit(int moduleId, long id = 0) { var viewModel = new OperationEditViewModel(); var editEntity = _operationService.GetById(id) ?? new Operation() { ModuleId = moduleId, IsShow = true }; viewModel = new OperationEditViewModel() { Id = editEntity.Id, Name = editEntity.Name, Code = editEntity.Code, URL = editEntity.URL, IsShow = editEntity.IsShow, Order = editEntity.Order.ToString(), ModuleId = moduleId }; return(PartialView("_EditPartial", viewModel)); }