Ejemplo n.º 1
0
        public IActionResult Delete(int id, string Image)
        {
            var plays  = _played.GetAll();
            var player = _assets.GetById(id);

            foreach (var playItem in plays)
            {
                foreach (var playerItem in playItem.Players)
                {
                    if (playerItem.Player.Id == id)
                    {
                        ModelState.AddModelError("Id", "Cant delete");
                        return(RedirectToAction(nameof(Detail), new { player.Id }));
                    }
                }
            }

            _assets.Delete(player);

            //Usuwanie pliku
            if (Image != null)
            {
                var webRoot  = _env.WebRootPath;
                var filePath = Path.Combine(webRoot.ToString() + Image);
                System.IO.File.Delete(filePath);
            }

            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 2
0
        public IActionResult Index()
        {
            var model = new AssetPlayedIndex
            {
                Played = _assets.GetAll()
            };

            return(View(model));
        }