public async Task <IActionResult> DeleteAFavourite(int userId, int postId)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var favouriteFromRepo = await _recipeRepo.GetFavourite(postId, userId);

            if (favouriteFromRepo == null)
            {
                return(NotFound($"Recipe with id {postId} not found in favourites"));
            }
            if (favouriteFromRepo.FavouriterId != userId)
            {
                return(Unauthorized());
            }

            _recipeRepo.Delete(favouriteFromRepo);

            if (await _recipeRepo.SaveAll())
            {
                return(Ok("Favourite successfully deleted"));
            }

            return(BadRequest("Could not delete photo from favourites"));
        }
        public async Task <IActionResult> DeleteComment(int commentId, int userId)
        {
            // Validate id of logged in user == userId
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            // Get comment from repo
            var comment = await _recipeRepo.GetComment(commentId);

            // Confirm user made the comment
            if (comment == null)
            {
                return(NotFound($"Comment {commentId} not found"));
            }
            if (comment.CommenterId != userId)
            {
                return(Unauthorized());
            }

            // Delete from repo
            _recipeRepo.Delete(comment);

            if (await _recipeRepo.SaveAll())
            {
                return(Ok("Comment was successfully deleted"));
            }

            throw new Exception("Deleting the comment failed on save");
        }
        public IActionResult Delete(int id)
        {
            var recipe = _recipeRepository.GetById <Recipe>(id);

            _recipeRepository.Delete(recipe);

            return(RedirectToAction("Index"));
        }
Пример #4
0
        public async Task <ActionResult> Delete([FromQuery] string?id)
        {
            if (ObjectId.TryParse(id, out var recipeId))
            {
                await _recipes.Delete(recipeId);

                return(NoContent());
            }
            return(BadRequest());
        }
        public async Task <IActionResult> DeletePhoto(int postId, int id)
        {
            var postFromRepo = await _recipeRepo.GetPost(postId);

            if (postFromRepo.UserId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            if (!postFromRepo.PostPhoto.Any(p => p.PostPhotoId == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _recipeRepo.GetPostPhoto(id);

            // if (photoFromRepo.IsMain)
            //     return BadRequest("You cannot delete the main photo");

            if (photoFromRepo.PublicId != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _recipeRepo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _recipeRepo.Delete(photoFromRepo);
            }

            if (await _recipeRepo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Failed to delete the photo"));
        }
Пример #6
0
        public IActionResult OnPost()
        {
            Recipe deletedRecipe = recipeRepository.Delete(Recipe.Id);

            if (deletedRecipe == null)
            {
                return(RedirectToPage("/NotFound"));
            }

            return(RedirectToPage("Index"));
        }
Пример #7
0
        public async Task <IActionResult> DeleteRecipes(string id)
        {
            Guid recipeId = Guid.Parse(id);

            var recipe = await _recipeRepository.GetById(recipeId);

            _recipeRepository.Delete(recipe);

            var recipes = await _recipeRepository.GetAllRecipes();

            return(Ok(new { recipes }));
        }
Пример #8
0
        public IActionResult DeleteRecipe(int id)
        {
            Recipe recipe = _recipeRepository.GetBy(id);

            if (recipe == null)
            {
                return(NotFound());
            }
            _recipeRepository.Delete(recipe);
            _recipeRepository.SaveChanges();
            return(NoContent());
        }
Пример #9
0
        public async Task <IActionResult> DeleteRecipe(int id)
        {
            Recipe recipe = await _recipeRepository.GetByAsync(id);

            if (recipe == null)
            {
                return(NotFound());
            }
            _recipeRepository.Delete(recipe);
            await _recipeRepository.SaveChangesAsync();

            return(NoContent());  // Consider returning ok.
        }
Пример #10
0
        public Task <Unit> Handle(DeleteRecipeRequest request, CancellationToken cancellationToken)
        {
            var recipe = _repo.Get(request.Id);

            if (recipe == null)
            {
                throw new EntityNotFoundException(request.Id, "Recipe");
            }

            _repo.Delete(request.Id);

            return(Unit.Task);
        }
Пример #11
0
        public IActionResult Delete(int?Id)
        {
            var recipe = _recipeRepository.GetAllRecipes().Where(r => r.Id == Id);

            if (recipe == null)
            {
                ViewBag.ErrorMessage = $"Recipe with id ={Id} is NOT FOUND";
                return(View("notfound"));
            }

            _recipeRepository.Delete(Id);
            return(RedirectToAction("Index"));
        }
Пример #12
0
        public ActionResult Delete(int id)
        {
            var recipe = _repository.GetById(id);

            if (recipe == null)
            {
                return(NotFound());
            }
            else
            {
                _repository.Delete(recipe);
                return(NoContent());
            }
        }
Пример #13
0
        public async Task <bool> Delete(Guid id)
        {
            var userId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "IdUser").Value);
            var recipe = await _repository.GetById(id);

            if (recipe.IdUser == userId)
            {
                _repository.Delete(recipe);
                await _repository.SaveChanges();

                return(true);
            }

            return(false);
        }
Пример #14
0
 public IActionResult DeleteRecipe(int id)
 {
     if (_settings.AllowDelete)
     {
         if (ModelState.IsValid)
         {
             _ingredientRepository.Delete(id);
             _stepsRepository.Delete(id);
             _recipeRepository.Delete(id);
         }
         return(RedirectToAction("Index", "Recipe"));
     }
     else
     {
         return(RedirectToAction("Error", "Home"));
     }
 }
Пример #15
0
        public async Task <IActionResult> Delete([FromRoute] Guid id)
        {
            var recipe = await repository.GetRecipe(id);

            if (recipe == null)
            {
                throw new RestException(HttpStatusCode.NotFound, new { Recipe = GlobalConstants.NOT_FOUND });
            }

            repository.Delete(recipe);

            if (await repository.SaveAll())
            {
                return(Ok());
            }

            throw new Exception(GlobalConstants.ERROR_SAVING_CHANGES);
        }
Пример #16
0
        public async Task <RecipeResponse> Delete(Recipe recipe)
        {
            try
            {
                if (recipe == null)
                {
                    return(new RecipeResponse("Recipe not found", false));
                }
                _recipeRepository.Delete(recipe);
                await _unitOfWork.CompleteAsync();

                return(new RecipeResponse("Recipe deleted successfully", true));
            }
            catch (Exception ex)
            {
                return(new RecipeResponse($"An error occurred when deleting the recipe: {ex.Message}", false));
            }
        }
Пример #17
0
        private void Delete(Object obj)
        {
            if (Model.Id != Guid.Empty)
            {
                try
                {
                    recipesRepository.Delete(Model.Id);
                }
                catch
                {
                    messageBoxService.Show($"Deleting of {Model?.Name} failed!", "Deleting failed", MessageBoxButton.OK);
                }

                mediator.Send(new RecipeDeletedMessage {
                    Id = Model.Id
                });
            }

            Model = null;
        }
Пример #18
0
        public async Task <RecipeResponse> DeleteAsync(int recipeId)
        {
            var existingRecipe = await _recipeRepository.FindById(recipeId);

            if (existingRecipe == null)
            {
                return(new RecipeResponse($"Recipe could not be found"));
            }

            try
            {
                _recipeRepository.Delete(existingRecipe);
                await _unitOfWork.SaveChanges();

                return(new RecipeResponse(existingRecipe));
            }
            catch (Exception ex)
            {
                return(new RecipeResponse($"An unexpected error occured: {ex.Message}"));
            }
        }
Пример #19
0
        public async Task <IActionResult> AddPhotoForUser(int userId, [FromForm] UserPhotoForCreationDto userPhotoForCreationDto)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _recipeRepo.GetUser(userId);

            // Delete existing photo if exists
            var currentUserPhoto = userFromRepo.UserPhotos.FirstOrDefault();

            if (currentUserPhoto != null)
            {
                if (currentUserPhoto.PublicId != null)
                {
                    var deleteParams = new DeletionParams(currentUserPhoto.PublicId);

                    var result = _cloudinary.Destroy(deleteParams);

                    if (result.Result == "ok")
                    {
                        _recipeRepo.Delete(currentUserPhoto);
                    }
                }

                if (currentUserPhoto.PublicId == null)
                {
                    _recipeRepo.Delete(currentUserPhoto);
                }
            }

            // Adding new photo
            var file = userPhotoForCreationDto.File;

            var uploadResult = new ImageUploadResult();

            if (file.Length > 0)
            {
                using (var stream = file.OpenReadStream())
                {
                    var uploadParams = new ImageUploadParams()
                    {
                        File           = new FileDescription(file.Name, stream),
                        Folder         = "RecipeApp/user_photos/",
                        Transformation = new Transformation().Width(500).Height(500).Crop("fill").Gravity("face")
                    };

                    uploadResult = _cloudinary.Upload(uploadParams);
                }
            }

            userPhotoForCreationDto.Url      = uploadResult.Url.ToString();
            userPhotoForCreationDto.PublicId = uploadResult.PublicId;

            var photo = _mapper.Map <UserPhoto>(userPhotoForCreationDto);

            userFromRepo.UserPhotos.Add(photo);

            if (await _recipeRepo.SaveAll())
            {
                var photoToReturn = _mapper.Map <UserPhotosForReturnDto>(photo);
                return(CreatedAtRoute("GetUserPhoto", new { userId = userId, id = photo.UserPhotoId }, photoToReturn));
            }

            return(BadRequest("Could not add the photo"));
        }
Пример #20
0
 public void Delete(Recipe entity)
 {
     _recipeRepository.Delete(entity);
 }
Пример #21
0
        public IHttpActionResult Delete(int Id)
        {
            repository.Delete(Id);

            return(Ok());
        }
Пример #22
0
 public void Delete(int id)
 {
     _recipeRepository.Delete(id);
 }
Пример #23
0
 public void Delete(int id)
 {
     _recipeRepository.Delete(id);
     _recipeRepository.SaveChanges();
 }
Пример #24
0
 public ActionResult Delete(Guid id)
 {
     recipeRepository.Delete(id);
     return(RedirectToAction("GetAllRecipe"));
 }
Пример #25
0
 public string Delete(Recipe recipe)
 {
     return(recipeRepo.Delete(recipe));
 }
Пример #26
0
        public IActionResult Delete([FromBody] IDRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(Ok(ModelState));
            }

            var response = new BaseResponse <bool>();
            var item     = recipeRepo.GetById(request.Id);

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

            var ingredients = ingredientRepo.GetBy(x => x.RecipeID == item.Id).ToList();

            if (ingredients.Any())
            {
                ingredientRepo.DeleteRange(ingredients);
            }

            var steps = stepRepo.GetBy(x => x.RecipeID == item.Id).ToList();

            if (steps.Any())
            {
                stepRepo.DeleteRange(steps);
            }

            var images = imageRepo.GetBy(x => x.RecipeID == item.Id).ToList();

            if (images.Any())
            {
                imageRepo.DeleteRange(images);
            }

            var recipeCategory = categoryRepo.GetBy(x => x.RecipeID == item.Id).ToList();

            if (recipeCategory.Any())
            {
                categoryRepo.DeleteRange(recipeCategory);
            }

            var rates = rateRepo.GetBy(x => x.RecipeID == item.Id).ToList();

            if (rates.Any())
            {
                rateRepo.DeleteRange(rates);
            }

            var bookmarks = bookMarkRepo.GetBy(x => x.RecipeID == item.Id).ToList();

            if (bookmarks.Any())
            {
                bookMarkRepo.DeleteRange(bookmarks);
            }



            recipeRepo.Delete(item);
            response.Message = "Yemek tarifi başarıyla silinmiştir.";

            return(Ok(response));
        }
Пример #27
0
 public IActionResult Delete(int id)
 {
     _repository.Delete(id);
     return(RedirectToAction("Published"));
 }
 public void DeleteRecipe(Recipes recipe)
 {
     _recipeRepository.Delete(recipe);
     _recipeRepository.Save();
 }
Пример #29
0
 public void Delete(Recipe recipe)
 {
     recipeRepository.Delete(recipe);
 }
Пример #30
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="recipe"></param>
 public void Delete(IRecipe recipe)
 {
     _repository.Delete(recipe);
 }