Ejemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("GameId,Title,Description,Picture,Developer")] Games games, List <IFormFile> Picture)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in Picture)
                {
                    if (item.Length > 0)
                    {
                        using (var stream = new MemoryStream())
                        {
                            await item.CopyToAsync(stream);

                            games.Picture = stream.ToArray();
                        }
                    }
                }


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

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

            return(View(games));
        }
        public async Task <IActionResult> PutGame(int id, Game game)
        {
            if (id != game.GameId)
            {
                return(BadRequest());
            }

            _context.Entry(game).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GameExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> Create([Bind("GradeId,GradeNumber,GradeText")] Grade grade)
        {
            if (ModelState.IsValid)
            {
                _context.Add(grade);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(grade));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("GameDevId,GameId,DeveloperId,ReleaseDate")] GameDev gameDev)
        {
            if (ModelState.IsValid)
            {
                _context.Add(gameDev);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DeveloperId"] = new SelectList(_context.Developers, "DeveloperId", "Name", gameDev.DeveloperId);
            ViewData["GameId"]      = new SelectList(_context.Games, "GameId", "Title", gameDev.GameId);
            return(View(gameDev));
        }
        public async Task <IActionResult> Create([Bind("DeveloperId,Name,Adress")] Developers developers)
        {
            if (ModelState.IsValid)
            {
                foreach (var item in _context.Developers)
                {
                    if (developers.DeveloperId == item.DeveloperId)
                    {
                        developers.DeveloperId = developers.DeveloperId + 5;
                    }
                }
                _context.Add(developers);
                await _context.SaveChangesAsync();

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