Пример #1
0
        public async Task <IActionResult> DeleteDeveloper([FromRoute] int?id, [FromForm] int formId)
        {
            if (id != formId)
            {
                return(BadRequest());
            }

            var devForDeletion = await _repo.GetDeveloper(id);

            if (devForDeletion == null)
            {
                return(NotFound());
            }

            List <string> photosForDeletion = new List <string>();

            if (devForDeletion.PhotoId != null)
            {
                photosForDeletion.Add(devForDeletion.PhotoId);
            }

            if (devForDeletion.Games.ToList().Count > 0)
            {
                foreach (Game game in devForDeletion.Games)
                {
                    if (!String.IsNullOrEmpty(game.PhotoId))
                    {
                        photosForDeletion.Add(game.PhotoId);
                    }
                }
            }

            if (photosForDeletion.Count > 0)
            {
                var delParams = new DelResParams()
                {
                    PublicIds = photosForDeletion
                };

                _cloudinary.DeleteResources(delParams);
            }

            _repo.Delete(devForDeletion);

            if (await _repo.SaveAll())
            {
                SetMessage("info", "Developer deleted");
                return(RedirectToAction(nameof(Index)));
            }

            SetMessage("danger", "Something went wrong. Could not complete request");
            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        public async Task <IActionResult> DeleteGame([FromRoute] int id, [FromForm] int formId)
        {
            if (id != formId)
            {
                return(BadRequest());
            }

            var game = await _repo.GetGame(id);

            if (game == null)
            {
                return(NotFound());
            }

            if (game.PhotoId != null)
            {
                var deleteParams = new DeletionParams(game.PhotoId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result != "ok")
                {
                    return(BadRequest());
                }
            }

            _repo.Delete(game);

            if (await _repo.SaveAll())
            {
                SetMessage("danger", "Game deleted");
                return(RedirectToAction(nameof(Index)));
            }

            return(BadRequest());
        }
 /// <summary>
 /// Returns false if it can't delete the item
 /// </summary>
 /// <returns>bool</returns>
 public bool DeleteDeveloper(int developerId)
 {
     return(developerRepo.Delete(developerId));
 }
 public RedirectToActionResult Delete(int id)
 {
     developerRepo.Delete(id);
     return(RedirectToAction("Index"));
 }