Beispiel #1
0
        public IActionResult Edit(int id, Player player, IFormFile file)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (file.Length > 0)
                    {
                        var filePath = Path.Combine("wwwroot/images", file.FileName);
                        var stream   = new FileStream(filePath, FileMode.Create);
                        file.CopyToAsync(stream);

                        player.Photo = "images/" + file.FileName;

                        db.EditPlayer(player);

                        ViewBag.Msg = "Edit player successfully";
                    }
                }
            }
            catch (Exception)
            {
                ViewBag.Msg = "Failed";
            }
            return(View());
        }