/// <summary> /// The add. /// </summary> /// <param name="userInput"> /// The user input. /// </param> public void Add(EditUserInputDto userInput) { Guard.ArgumentNotNull(() => userInput); var toAdd = Mapper.Map<User>(userInput); using (var uof = EngineContext.Current.Resolve<ISkymateUnitOfWork>()) { if (toAdd.ID == Guid.Empty) { toAdd.ID = Guid.NewGuid(); } this.userRepository.Add(toAdd); uof.Commit(); } }
public ActionResult Create() { var newUser = new EditUserInputDto(); return this.Json(OperationResult.Success(string.Empty, string.Empty, newUser),JsonRequestBehavior.AllowGet); }
public ActionResult SaveUser(EditUserInputDto userInput) { try { if (userInput.Id == Guid.Empty) { this.userService.Add(userInput); } else { this.userService.Update(userInput); } return this.Json(OperationResult.Success("保存成功")); } catch (Exception e) { return this.Json(OperationResult.Error("保存失败," + e.Message)); } }
/// <summary> /// The update. /// </summary> /// <param name="userInput"> /// The user input. /// </param> public void Update(EditUserInputDto userInput) { Guard.ArgumentNotNull(() => userInput); Guard.ArgumentNotEmpty(() => userInput.Id); var toUpdate = this.userRepository.GetByKey(userInput.Id); toUpdate = Mapper.Map<EditUserInputDto, User>(userInput, toUpdate); this.userRepository.Update(toUpdate); this.userRepository.Context.Commit(); }