public async Task <Guid> CreateBookAsync(Book book, Stream image = null, string imageContentType = null) { if (book == null) { throw new ArgumentNullException(nameof(book)); } _logger.LogInformation($"Create book {book.Id} ({book.Title})"); if (book.Id == default(Guid)) { book.Id = Guid.NewGuid(); } var containsImage = _imagesService.SaveImage(book, image, imageContentType); try { return(await _repository.CreateBookAsync(book)); } catch (Exception ex) { _logger.LogError(ex, ex.Message); if (containsImage) { _imagesService.DeleteImage(book); } throw; } }
public async Task <IActionResult> DeleteImage(string id) { var isModerator = User.IsInRole("Moderator"); await _imageService.DeleteImage(id, this.GetUserId(), isModerator); return(NoContent()); }
public async Task <IActionResult> OnPostDeleteImageAsync(Guid?imageId, Guid?recordId) { if (imageId != null && imageId.Value != Guid.Empty) { await _imagesService.DeleteImage(imageId.Value); } return((recordId != null && recordId != Guid.Empty) ? Redirect($"/Records/View?recordid={recordId.Value}") : Redirect("/images/index")); }
public async Task <IActionResult> DeleteImage([FromRoute] string fileName) { if (string.IsNullOrWhiteSpace(fileName)) { return(BadRequest("Image fileName not provided!")); } await _imageService.DeleteImage(fileName); return(Ok()); }
public async Task <ActionResult> DeleteImage(int id) { var completed = await imagesService.DeleteImage(id); if (!completed) { return(NotFound()); } else { return(Ok()); } }
public async Task <ActionResult <Image> > DeleteImage(int id) { var completed = await imagesService.DeleteImage(id); if (!completed) { return(NotFound()); } else { await cashService.RemoveCashResponseAsync(CashUtilities.GenerateKeyCashKeyFromRequest(this.Request)); return(Ok()); } }
public ActionResult DeleteImage([Bind(Include = "Id")] int Id) { Image currentImage = imageRepository.GetImages().Where(x => x.Id == Id).FirstOrDefault(); //Delete from Azure Storage bool Deleted = AzureStorage.DeleteImage(currentImage); // Delete current Image if (Deleted) { imageRepository.DeleteImage(Id); } TempData["SuccessfulDelete"] = "Successfully Deleted"; return(RedirectToAction("Index", "Home"));; }
public async Task <ActionResult> DeleteImage(string name) { try { Uri uri = new Uri(name); string filename = Path.GetFileName(uri.LocalPath); await _imagesService.DeleteImage(filename, _accountService.GetContainerNamePhotos(ClaimsPrincipal.Current)); return(RedirectToAction("UploadPhotos")); } catch (Exception ex) { ViewData["message"] = ex.Message; ViewData["trace"] = ex.StackTrace; return(View("Error")); } }
public string DeleteImage(long id, string path) { var response = _IImagesService.DeleteImage(id); if (response?.StatusCode == (int)RESULT_STATUS_CODE.SUCCESS) { response.StatusMessage = Utility.getResourceString("DeleteSuccess"); } string imPpath = string.Format(@"~\" + path); if (!Directory.Exists(Server.MapPath(imPpath))) { Directory.Delete(Server.MapPath(path)); } string json = JsonConvert.SerializeObject(response); return(json); }
public async Task <IActionResult> DeleteProduct(ProductId id) { try { var product = await _productService.FindProductById(id.Id); if (product != null) { var image = _imagesService.FindImageById(id.Id); foreach (var item in image) { //DirectoryInfo di = new DirectoryInfo(item.Path); //foreach (FileInfo file in di.GetFiles()) //{ // file.Delete(); //} _imagesService.DeleteImage(item); } _unitOfWork.Commit(); _productService.DeleteProduct(product); return(Ok(new Result() { Code = 200, Data = "Xóa sản phẩm thành công", Error = null })); } else { return(Ok(new Result() { Code = 200, Data = null, Error = "Không tìm thấy sản phẩm" })); } } catch (Exception ex) { _logger.LogError("Thêm sản phẩm thất bại: " + ex); return(Ok(new Result() { Code = ex.GetHashCode(), Data = null, Error = "Xóa sản phẩm thất bại" })); } }
public async Task <IActionResult> DeleteImage(Guid id) { await _imagesService.DeleteImage(id); return(NoContent()); }