Exemplo n.º 1
0
        public async Task <IActionResult> GenerateBill()
        {
            var basket = await _context.Baskets.Include(x => x.BasketGames).FirstOrDefaultAsync(x => x.Id == 3);

            var client = _context.Clients.FirstOrDefault(x => x.Id == 1); // chyba na sztywno najlepiej poki co

            //var basketGames = _context.BasketsGames.FirstOrDefault(x => x.BasketId == 3);
            var bill = new Bill();
            await _context.Bills.AddAsync(bill);

            await _context.SaveChangesAsync();

            foreach (var basketGame in basket.BasketGames)
            {
                var billGame   = new BillGame();
                var game       = _context.Games.FirstOrDefault(x => x.Id == basketGame.GameId);
                var gameOfUser = _context.ClientsGames.Where(x => x.GameId == basketGame.GameId &&
                                                             x.ClientId == client.Id).ToList();
                if (gameOfUser.Count != 0)
                {
                    continue; // chyba dobre bo ine doda ceny etc.
                }
                bill.SummaryPrice += game.Price;
                billGame.BillId    = bill.Id;
                billGame.GameId    = game.Id;
                await _context.BillsGames.AddAsync(billGame);

                await _context.SaveChangesAsync();
            }
            _context.Bills.Update(bill);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = bill.Id }));
            //return RedirectToAction("Details", 13);
        }
Exemplo n.º 2
0
        //public async Task<IActionResult> AddToBasket(int basketId, int gameId)
        public async Task <IActionResult> AddToBasket(int?id)
        {
            //int gameId = 1;
            var basket = await _context.Baskets.Include(x => x.BasketGames).FirstOrDefaultAsync(x => x.Id == 3);

            if (basket == null)
            {
                basket = new Basket();
                await _context.Baskets.AddAsync(basket);

                await _context.SaveChangesAsync();
            }
            var game = await _context.Games.FirstOrDefaultAsync(x => x.Id == id);

            var basketGame = new BasketGame();

            if (game != null && basket.BasketGames.Count(x => x.GameId == id) == 0)
            {
                basketGame.BasketId = basket.Id;
                basketGame.GameId   = game.Id;
                await _context.BasketsGames.AddAsync(basketGame);

                await _context.SaveChangesAsync();
            }
            return(RedirectToAction("Index", "Games"));
        }
Exemplo n.º 3
0
        //public async Task<IActionResult> Create([Bind("Id,Name,Price,Promotion,Description,PG")] Game game)
        public async Task <IActionResult> Create(CreateGameViewModel vm)
        {
            //Category category = _context.Categories.Find(vm.IdCategory);
            //Studio studio = _context.Studios.Find(vm.IdStudio);

            var game = new Game
            {
                Name        = vm.Game.Name,
                CategoryId  = vm.Game.CategoryId,
                StudioId    = vm.Game.StudioId,
                Price       = vm.Game.Price,
                Promotion   = vm.Game.Promotion,
                Description = vm.Game.Description,
                PG          = vm.Game.PG,
            };

            //if (ModelState.IsValid)
            //{
            _context.Add(game);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
            //}
            //return View(vm);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("ID,Name,Price")] Consoles consoles)
        {
            if (ModelState.IsValid)
            {
                _context.Add(consoles);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(consoles));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("ID,name,game,rating,review")] UserReview userReview)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userReview);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(userReview));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,TotalPrice")] ShoppingCart shoppingCart)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoppingCart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoppingCart));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("Id,Image,Name,DateOfRelease,Price,Quantity,Genre,Description,Trailer,Consoles")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("ID,Title,ReleaseDate,Genre,Price,Console")] Game game)
        {
            if (ModelState.IsValid)
            {
                _context.Add(game);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(game));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Login,Saldo")] Client client)
        {
            if (id != client.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(client);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ClientExists(client.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "Games"));
            }
            return(View(client));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> Register([Bind("Id,Email,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                var q = _context.User.FirstOrDefault(u => u.Email == user.Email);

                if (q == null)
                {
                    _context.Add(user);
                    await _context.SaveChangesAsync();

                    var u = _context.User.FirstOrDefault(u => u.Email == user.Email && u.Password == user.Password);

                    Signin(u);

                    return(RedirectToAction("Home", "ConsolePages"));
                }
                else
                {
                    ViewData["Error"] = "Unable to comply; cannot register this user.";
                }
            }
            return(View(user));
        }