Exemple #1
0
        public async Task <IActionResult> Purchase(Customer model, int gameId, int devId)
        {
            var customer = await _context.Customers.FirstOrDefaultAsync(c => c.Email.Equals(model.Email));

            bool duplicate = customer == null ? false : _context.Orders.Any(p => p.GameId == gameId && p.CustomerId == customer.Id);

            if (duplicate)
            {
                ModelState.AddModelError("Email", Resourses.ERROR_OrderAlreadyBought);
            }

            if (ModelState.IsValid)
            {
                if (customer == null)
                {
                    customer = model;
                    await _context.Customers.AddAsync(customer);

                    await _context.SaveChangesAsync();
                }

                var purchase = new Order()
                {
                    CustomerId = customer.Id, GameId = gameId, Date = DateTime.Now
                };
                await _context.Orders.AddAsync(purchase);

                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Games", new { id = devId, purchased = true }));
            }

            FillViewBag(gameId, devId);
            return(View(model));
        }
        public async Task <IActionResult> Create(Game game)
        {
            ViewBag.DevId     = game.DeveloperId;
            ViewBag.Developer = _context.Developers.Find(game.DeveloperId).Name;

            bool duplicate = _context.Games.Any(s => s.DeveloperId == game.DeveloperId && s.Name.Equals(game.Name));

            if (duplicate)
            {
                ModelState.AddModelError("Name", Resourses.ERROR_GameExists);
            }

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

                return(RedirectToAction("Index", new { id = game.DeveloperId }));
            }

            ViewBag.DeveloperList = new SelectList(_context.Developers, "Id", "Name", game.DeveloperId);
            ViewBag.GenreList     = new SelectList(_context.Genres, "Id", "Name", game.GenreId);
            ViewBag.StatusList    = new SelectList(_context.Statuses, "Id", "Name", game.StatusId);

            return(View(game));
        }
Exemple #3
0
        public async Task <IActionResult> Create(Genre genre)
        {
            bool duplicate = await _context.Genres.AnyAsync(d => d.Name.Equals(genre.Name));

            if (duplicate)
            {
                ModelState.AddModelError("FirstName", Resourses.ERROR_GenreExists);
            }

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

                return(RedirectToAction(nameof(Index)));
            }

            return(View(genre));
        }
Exemple #4
0
        public async Task <IActionResult> Create(Developer developer)
        {
            bool duplicate = await _context.Developers.AnyAsync(d => d.Name.Equals(developer.Name));

            if (duplicate)
            {
                ModelState.AddModelError("Name", Resourses.ERROR_DeveloperExists);
            }

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

                return(RedirectToAction(nameof(Index)));
            }

            ViewBag.CountryList = new SelectList(_context.Countries.ToList(), "Id", "Name");
            return(View(developer));
        }