public async Task <IActionResult> DeletePhoto(int idProduct, int id) { var product = await _repo.GetProduct(idProduct); if (!product.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } var photoFromRepo = await _repo.GetPhoto(id); if (photoFromRepo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (photoFromRepo.PublicId != null) { var deleteParams = new DeletionParams(photoFromRepo.PublicId); var result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { _repo.Delete(photoFromRepo); } } if (photoFromRepo.PublicId == null) { _repo.Delete(photoFromRepo); } if (await _repo.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the photo")); }
public async Task <ActionResult <Manufacturer> > DeleteManufacturer(int id) { var manufacturer = await _repo.GetManufacturer(id); if (manufacturer == null) { return(NotFound()); } _repo.Delete <Manufacturer>(manufacturer); await _repo.SaveAll(); return(manufacturer); }
public async Task <ActionResult <Product> > DeleteProduct(int id) { var product = await _repo.GetProduct(id); if (product == null) { return(NotFound()); } _repo.Delete <Product>(product); await _repo.SaveAll(); return(product); }
public async Task <ActionResult <User> > DeleteUser(int id) { var user = await _repo.GetUser(id); if (user == null) { return(NotFound()); } _repo.Delete <User>(user); await _repo.SaveAll(); return(user); }
public async Task <IActionResult> Delete(string code) { var productFromRepo = await _repository.GetProduct(code); if (productFromRepo == null) { return(NotFound()); } _repository.Delete(productFromRepo); if (await _repository.SaveAllChangesAsync()) { return(Ok()); } return(BadRequest($"An Error occurred while trying to delete product with code {productFromRepo.Code}")); }