Ejemplo n.º 1
0
        public async Task <IActionResult> Create(CreateGameViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Genres     = _context.Genres;
                model.Developers = _context.Developers;
                return(View(model));
            }

            var game = new Game
            {
                Author      = await GetCurrentUser(),
                Genre       = await _context.Genres.SingleOrDefaultAsync(c => c.GenreId == model.GenreId),
                Developer   = await _context.Developers.SingleOrDefaultAsync(c => c.DeveloperId == model.DeveloperId),
                PEGI        = model.PEGI,
                Title       = model.Title,
                Description = model.Description,
                Realeased   = DateTime.Now,
                Price       = model.Price
            };

            _context.Add(game);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create(CreateDeveloperViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var developer = new Developer {
                Name = model.Name
            };

            _context.Add(developer);
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create(CreateGenreViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var genre = new Genre {
                Name = model.Name
            };

            _context.Add(genre);
            await _context.SaveChangesAsync();

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