示例#1
0
        public ActionResult AddGameToOrder(string gameKey)
        {
            var userId = CurrentUser.Id;

            if (userId == Guid.Empty)
            {
                userId = GetUserId();
                string userInformation = HttpContext.Request.Cookies["userInformation"].Value;
                var    userFromDB      = _userService.GetById(userId);

                if (userInformation == "Girl 18+")
                {
                    if (userFromDB == null)
                    {
                        var user = new UserDTO()
                        {
                            Id        = userId,
                            Adulthood = true,
                            IsWoman   = true
                        };
                        _userService.AddNew(user);
                    }
                    else
                    {
                        userFromDB.Adulthood = true;
                        userFromDB.IsWoman   = true;
                        _userService.Update(userFromDB);
                    }
                }
                else if (userInformation == "Boy 18+")
                {
                    if (userFromDB == null)
                    {
                        var user = new UserDTO()
                        {
                            Id        = userId,
                            Adulthood = true,
                            IsWoman   = false
                        };
                        _userService.AddNew(user);
                    }
                    else
                    {
                        userFromDB.Adulthood = true;
                        userFromDB.IsWoman   = false;
                        _userService.Update(userFromDB);
                    }
                }
                else if (userInformation == "Girl less than 18")
                {
                    if (userFromDB == null)
                    {
                        var user = new UserDTO()
                        {
                            Id        = userId,
                            Adulthood = false,
                            IsWoman   = true
                        };
                        _userService.AddNew(user);
                    }
                    else
                    {
                        userFromDB.Adulthood = false;
                        userFromDB.IsWoman   = true;
                        _userService.Update(userFromDB);
                    }
                }
                else if (userInformation == "Boy less than 18")
                {
                    if (userFromDB == null)
                    {
                        var user = new UserDTO()
                        {
                            Id        = userId,
                            Adulthood = false,
                            IsWoman   = false
                        };
                        _userService.AddNew(user);
                    }
                    else
                    {
                        userFromDB.Adulthood = false;
                        userFromDB.IsWoman   = false;
                        _userService.Update(userFromDB);
                    }
                }
            }



            var gameDTO = _gameService.GetByKey(gameKey);
            var game    = _mapper.Map <DetailsGameViewModel>(gameDTO);

            if (game.UnitsInStock >= 1 && game.IsDelete == false)
            {
                _ordersService.AddNewOrderDetails(userId, game.Id);

                var basket = new BasketViewModel()
                {
                    GameName = game.Name,
                    Price    = game.Price
                };

                return(View(basket));
            }

            return(View("NotEnoughGameInStock"));
        }