Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Batting,Bowling,GameId,PlayerId")] Stat stats)
        {
            if (id != stats.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (!StatsExistsForPlayerThisGame(stats.Id, stats.GameId, stats.PlayerId))
                {
                    try
                    {
                        _context.Update(stats);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!StatsExists(stats.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction("Details", "Games", new { Id = stats.GameId }));
                }

                ModelState.AddModelError("PlayerId", "The selected player has already been assigned statistics for this game.");
            }
            return(View(stats));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,GameNumber,PlayerOfMatchId")] Game game)
        {
            if (id != game.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                if (!GameIsDuplicate(game.Id, game.GameNumber))
                {
                    try
                    {
                        _context.Update(game);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!GameExists(game.Id))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError("GameNumber", "The game already exists.");
            }
            return(View(game));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Photo")] Player players)
        {
            if (id != players.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                char[] seperators = { '/' };
                if (Request.Form.Files.Count > 0)
                {
                    if
                    (
                        Request.Form.Files[0].ContentType.Split(seperators, StringSplitOptions.RemoveEmptyEntries)[0] == "image" &&
                        Request.Form.Files[0].Length <= 204800
                    )
                    {
                        players.Photo = await ImageUploadToBase64(Request.Form.Files[0]);
                    }
                    else
                    {
                        ModelState.AddModelError("Photo", "Photo is not a valid image type or is over 200 KiB.");
                        return(View(players));
                    }
                }
                else
                {
                    players.Photo = await _context.Players.Where(p => p.Id == id).Select(p => p.Photo).SingleOrDefaultAsync();
                }

                try
                {
                    _context.Update(players);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlayersExists(players.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction("Index"));
            }
            return(View(players));
        }