Пример #1
0
        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);
        }
Пример #2
0
        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();
        }