Exemple #1
0
        public ActionResult Delete(int categoryId)
        {
            var listOfGifs = _gifRepository.GetGifsByCategory(categoryId);


            if (listOfGifs != null)
            {
                foreach (var gif in listOfGifs)
                {
                    var favorite = _favoriteRepository.GetByGif(gif.Id);
                    if (favorite != null)
                    {
                        _favoriteRepository.Delete(favorite.Id);
                    }

                    _gifRepository.Delete(gif.Id);
                }
            }

            _categoryRepository.Delete(categoryId);

            TempData["Message"] = "Your Category was successfully deleted!";

            return(RedirectToAction("Index", "Category"));
        }
Exemple #2
0
        public ActionResult Delete(int id)
        {
            var gif           = _gifRepository.Get(id);
            var favoriteGif   = _favoriteRepository.GetByGif(gif.Id);
            var favoritesList = _favoriteRepository.GetList();

            if (favoriteGif != null)
            {
                if (favoritesList.Contains(favoriteGif))
                {
                    _favoriteRepository.Delete(favoriteGif.Id);
                }
            }

            _gifRepository.Delete(gif.Id);

            TempData["Message"] = "Your Gif was successfully deleted!";

            return(RedirectToAction("Index"));
        }