public async Task <IActionResult> ImageDelete(ProductDeleteDto productDeleteDto) { if (productDeleteDto == null) { return(Json(new JResult { Status = Status.BadRequest, Message = "Hatalı istek! Lütfen yeniden deneyiniz." })); } if (!await _productImageService.ProductImageExistsAsync(productDeleteDto.Id)) { return(Json(new JResult { Status = Status.NotFound, Message = "Silinmek istenen resim bulunamadı!" })); } var productImageInDb = await _productImageService.FindByIdAsync(productDeleteDto.Id); await _productImageService.RemoveAsync(productImageInDb); return(RedirectToAction("Index").ShowMessage(Status.Ok, "Baraşılı", "Resim başarıyla silindi")); }
public async Task <IActionResult> DeleteAsync(ProductDeleteDto model) { var validator = new ProductDeleteDtoValidator(); var result = await validator.ValidateAsync(model); if (result.IsValid) { var product = await _productRepository.GetAsync(p => p.Id == model.Id); if (product == null) { return(BadRequest("Ürün bulunamadı")); } _productRepository.Remove(product); var columnCount = await _productRepository.SavechangesAsync(); if (columnCount == 0) { ModelState.AddModelError("", "Bir problem ile karşılaştık"); return(BadRequest(ModelState.Values)); } return(NoContent()); } return(BadRequest(result.Errors)); }
public async Task <JsonResult> Delete(ProductDeleteDto productDeleteDto) { if (productDeleteDto == null) { return(Json(new JResult { Status = Status.BadRequest, Message = "Silinmek istenen ürün bulunamadı!" })); } if (!await _productService.ProductExistsAsync(productDeleteDto.Id)) { return(Json(new JResult { Status = Status.NotFound, Message = "Silinmek istenen ürün bulunamadı!" })); } var product = await _productService.FindByIdAsync(productDeleteDto.Id); product.IsDelete = false; await _productService.UpdateAsync(product); return(Json(new JResult { Status = Status.Ok, Message = "Ürün başarıyla silindi." })); }