Пример #1
0
        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));
        }
Пример #2
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));
        }
Пример #3
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));
        }