public void EditOne(Department_AddEditDTO editOne, string updater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Department> commonService = new CommonService <Department>(dbContext); bool isExist = commonService.AnyByIdNoMarkDeleted(editOne.Id); if (!isExist) { throw new PushToUserException("Current Department item is not exist"); } bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Name.Equals(editOne.Name) && d.Id != editOne.Id).Any(); if (hasExist) { throw new PushToUserException($"A Department item with the same name '{editOne.Name}' already exists"); } Department updateOne = CoffeeMapper <Department_AddEditDTO, Department> .AutoMap(editOne, (_out, _in) => { _out.Updater = updater; _out.UpdateTime = DateTime.Now; }); dbContext.Update <Department>(d => new { d.Name, d.ParentId, d.RemarkInfo, d.SortNumber, d.Updater, d.UpdateTime }, updateOne) .Where(d => d.Id.Equals(updateOne.Id)).Done(); } }
public ActionResult editItem(Department_AddEditDTO editOne) { if (!ModelState.IsValid) { throw new PushToUserException(MVCHelper.GetValidMsgStr(ModelState)); } DepartmentService.EditOne(editOne, LoginUserId); return(Json(new AjaxResult { Status = "success", SendData = new { Result = "success" } })); }
public string AddNewOne(Department_AddEditDTO addOne, string creater) { using (MiniSenDbContext dbContext = new MiniSenDbContext()) { CommonService <Department> commonService = new CommonService <Department>(dbContext); bool hasExist = commonService.WhereNoMarkDeleted().Where(d => 0 == d.DelFlag && d.Name.Equals(addOne.Name)).Any(); if (hasExist) { throw new PushToUserException($"A Department item with the same name '{addOne.Name}' already exists"); } Department newOne = CoffeeMapper <Department_AddEditDTO, Department> .AutoMap(addOne, (_out, _in) => { _out.Id = Utils.GetGuidStr(); _out.Creater = creater; }); return(commonService.Insert(newOne)); } }