public UserApiModel AddUser(UserApiModel model) { var bsModel = this._dbContext.Users.SingleOrDefault(c => c.UserId == model.UserId); if (bsModel == null) { bsModel = model.ToUserBSModel(); _dbContext.Add(bsModel); _dbContext.SaveChanges(); return(bsModel.ToUserAPIModel()); } return(null); }
public void Execute(IEnumerable <ICommand> commands) { foreach (var command in commands) { var validator = _dispatcher.GetValidator(command); var validationResult = validator.Validate(command); if (!validationResult.IsValid) { throw new CommandValidationException(validationResult.ErrorMessages); } var handler = _dispatcher.GetHandler(command); handler.Handle(command); } _context.SaveChanges(); }