public GameUpdateRequestHandlerTests()
        {
            var fixture = new Fixture();

            fixture.Behaviors.Add(new OmitOnRecursionBehavior());

            _commandDispatcher = new Mock <ICommandDispatcher>();
            _testRequest       = fixture.Create <GameUpdateRequest>();

            _handler = new GameUpdateRequestHandler(_commandDispatcher.Object);
        }
Example #2
0
 public void Update(GameUpdateRequest model)
 {
     _dataProvider.ExecuteNonQuery(
         "dbo.Games_Update",
         inputParamMapper : delegate(SqlParameterCollection paramCol)
     {
         paramCol.AddWithValue("@Id", model.Id);
         paramCol.AddWithValue("@Title", model.Title);
         paramCol.AddWithValue("@Plain", model.Plain);
         paramCol.AddWithValue("@CurrentLow", model.SalePrice);
         paramCol.AddWithValue("@RetailPrice", model.RetailPrice);
     }
         );
 }
Example #3
0
        public async Task <ServiceResult <string> > UpdateGame(int id, GameUpdateRequest update)
        {
            var result = new ServiceResult <string>();
            var repo   = _repo;
            var exists = await repo.Get <Game>(game => game.Id == id).FirstOrDefaultAsync();

            if (exists != null)
            {
                exists.Name        = !string.IsNullOrEmpty(update.Name) ? update.Name : exists.Name;
                exists.Rating      = update.Rating != 0 ? update.Rating : exists.Rating;
                exists.Description = !string.IsNullOrEmpty(update.Description) ? update.Description : exists.Description;
                exists.ReleaseDate = update.ReleaseDate.HasValue ? update.ReleaseDate.Value : exists.ReleaseDate;
                repo.Update(exists);
                result.Value   = new string($"Successfully updated {update.Name}");
                result.Success = true;
                await repo.Commit();
            }
            return(result);
        }
Example #4
0
        public async Task <ActionResult> Update(int id, [FromBody] GameUpdateRequest gameUpdate)
        {
            if (ModelState.IsValid)
            {
                var response = await _gameService.UpdateGame(id, gameUpdate);

                if (response.Success)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest(response));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }