示例#1
0
        public void CreateGame_ItemSentToDAL_InvalidItemWithLists(GameDTO gameDto, List <Genre> genresFromDb,
                                                                  List <PlatformType> platformsFromDb)
        {
            // Arrange
            _mock.Setup(a => a.Repository <Genre>().GetAll()).Returns(genresFromDb);
            _mock.Setup(a => a.Repository <PlatformType>().GetAll()).Returns(platformsFromDb);

            // Act
            Assert.Throws <NullReferenceException>(
                () => _gameService.AddEntity(gameDto));
        }
示例#2
0
        public OrderDetailDTO GetOrderDetail(string gameKey, short quantity, bool isOrderExist)
        {
            //Adding order to sql database, if game is situated in mongobase
            if (gameKey.Length == 24 && _gameService.GetByKey(gameKey) != null)
            {
                var gameMongo = _gameService.GetByKey(gameKey);
                _gameService.AddEntity(gameMongo);
            }

            //Change total numbers of game
            var game = _gameService.GetByKey(gameKey);

            if (game == null)
            {
                throw new ValidationException("There is no game with such key", "GameNotFound");
            }

            game.UnitsInStock -= quantity;
            _gameService.EditEntity(game);


            //Get OrderDetail (new or existing)
            var orderDetailEntity =
                _unitOfWork.Repository <OrderDetail>()
                .FindBy(x => x.Game.Key == game.Key && !x.IsDeleted)
                .FirstOrDefault(x => x.IsPayed == false);
            var orderDetailDto = (orderDetailEntity != null && isOrderExist)
                ? GetExistedOrderDetail(orderDetailEntity, game, quantity)
                : GetNewOrderDetail(game, quantity);

            return(orderDetailDto);
        }
示例#3
0
        public HttpResponseMessage Post([FromBody] CreateGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            var gameDto = Mapper.Map <GameDTO>(model);

            _gameService.AddEntity(gameDto);
            return(Request.CreateResponse(HttpStatusCode.Created));
        }
示例#4
0
        public ActionResult New(CreateGameViewModel game, HttpPostedFileBase image)
        {
            if (image != null && !Regex.IsMatch(image.FileName, PatternPicture))
            {
                ModelState.AddModelError("FilePath", @GlobalRes.FilePathError);
            }

            if (!ModelState.IsValid)
            {
                game.AllGenres     = GetAllGenres().ToList();
                game.AllPublishers = GetAllPublishers().ToList();
                game.AllTypes      = GetAllTypes().ToList();
                game.Translates    = new List <TranslateViewModelDescription>
                {
                    new TranslateViewModelDescription
                    {
                        Id       = Guid.NewGuid().ToString(),
                        Language = Language.ru
                    }
                };

                return(View("New", game));
            }

            var gameViewModel = game;
            var gameDto       = Mapper.Map <GameDTO>(gameViewModel);

            if (image != null)
            {
                string fileName = image.FileName;
                image.SaveAs(Server.MapPath($"~/Content/images/{fileName}"));
                gameDto.FilePath = fileName;
            }
            else
            {
                gameDto.FilePath = DefaultPicture;
            }

            _gameService.AddEntity(gameDto);

            _logger.Info("Game is created. Id {0} Key {1} ", gameViewModel.Id, gameViewModel.Key);
            return(RedirectToAction("Index"));
        }