Exemplo n.º 1
0
        public IActionResult Buy(decimal?itemPrice, int quantity, string name)
        {
            db = new GameShopDBContext();
            List <AspNetUsers> userList = db.AspNetUsers.ToList();
            List <Items>       itemList = db.Items.ToList();

            foreach (Items item in itemList)
            {
                if (item.Name == name)
                {
                    item.Quantity = quantity;
                    //db.Items.Update(item);
                    db.SaveChanges();
                }
            }

            foreach (AspNetUsers user in userList)
            {
                if (user.Email == User.Identity.Name)
                {
                    user.Funds -= itemPrice;
                    db.AspNetUsers.Update(user);
                    db.SaveChanges();

                    return(View("Shop", db));
                }
            }
            return(View("Shop", db));
        }
Exemplo n.º 2
0
        public CreateOrderDto CreateOrder([FromBody] CreateOrderDto orderDto)
        {
            using (GameShopDBContext gameShopDBContext = new GameShopDBContext())
            {
                var GameId = gameShopDBContext.Games
                             .Where(x => x.GameName == orderDto.GameName)
                             .Select(x => x.Id).FirstOrDefault();

                var PlayerId = gameShopDBContext.Players
                               .Where(x => x.PlayerName == orderDto.PlayerName)
                               .Select(x => x.Id).FirstOrDefault();

                Order SaveOrder = new Order();
                SaveOrder.gameid        = GameId;
                SaveOrder.playerid      = PlayerId;
                SaveOrder.DiscountPrice = orderDto.DiscountPrice;

                gameShopDBContext.Orders.Add(SaveOrder);
                gameShopDBContext.SaveChanges();

                orderDto.Id = SaveOrder.Id;

                return(orderDto);
            }
        }
Exemplo n.º 3
0
        public GameDto CreateGame([FromBody] GameDto gameDto)
        {
            using (GameShopDBContext gameShopDBContext = new GameShopDBContext())
            {
                Game game = new Game();
                game.GameName    = gameDto.GameName;
                game.GameType    = gameDto.GameType;
                game.PlayTime    = gameDto.PlayTime;
                game.Publisher   = gameDto.Publisher;
                game.ReleaseDate = gameDto.ReleaseDate;
                game.Price       = gameDto.Price;

                gameShopDBContext.Games.Add(game);
                gameShopDBContext.SaveChanges();

                return(gameDto);
            }
        }
Exemplo n.º 4
0
        public CreatePlayerDto CreatePlayer([FromBody] CreatePlayerDto playerDto)
        {
            using (GameShopDBContext gameShopDBContext = new GameShopDBContext())
            {
                Player player = new Player();
                player.PlayerName = playerDto.PlayerName;
                player.Email      = playerDto.Email;
                player.Phone      = playerDto.Phone;
                player.BirthDate  = playerDto.BirthDate;
                player.Gender     = playerDto.Gender;
                player.Password   = playerDto.Password;

                gameShopDBContext.Players.Add(player);
                gameShopDBContext.SaveChanges();

                return(playerDto);
            }
        }