public virtual async Task <JsonResult> UpdateProductImage(long productId) { JsonResult jsonResult; Guid? imageId; try { if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null) { throw new UserFriendlyException(this.L("ProductImage_Change_Error")); } HttpPostedFileBase item = this.Request.Files[0]; if (item.ContentLength > 512000) { throw new UserFriendlyException(this.L("ProductImage_Warn_SizeLimit")); } GetProductForEditOutput productForEdit = await this._productAppService.GetProductForEdit(new NullableIdInput <long>(new long?(productId))); GetProductForEditOutput nullable = productForEdit; if (nullable.Product.ImageId.HasValue) { IBinaryObjectManager binaryObjectManager = this._binaryObjectManager; imageId = nullable.Product.ImageId; await binaryObjectManager.DeleteAsync(imageId.Value); } BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes()); await this._binaryObjectManager.SaveAsync(binaryObject); nullable.Product.ImageId = new Guid?(binaryObject.Id); UpdateProductImageInput updateProductImageInput = new UpdateProductImageInput() { ProductId = nullable.Product.Id.Value }; imageId = nullable.Product.ImageId; updateProductImageInput.ImageId = new Guid?(imageId.Value); await this._productAppService.SaveProductImageAsync(updateProductImageInput); jsonResult = this.Json(new MvcAjaxResponse()); } catch (UserFriendlyException userFriendlyException1) { UserFriendlyException userFriendlyException = userFriendlyException1; jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false)); } return(jsonResult); }
public async Task SaveProductImageAsync(UpdateProductImageInput input) { Product async = await this._productRepository.GetAsync(input.ProductId); Guid?imageId = input.ImageId; if (!imageId.HasValue) { imageId = null; async.ImageId = imageId; } else { imageId = input.ImageId; async.ImageId = new Guid?(imageId.Value); } await this._productRepository.UpdateAsync(async); }