Example #1
0
        public virtual async Task <JsonResult> UpdateSupplierLogo(SupplierLogoUploadModel model)
        {
            JsonResult jsonResult;
            Guid?      logoId;

            try
            {
                if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null)
                {
                    throw new UserFriendlyException(this.L("SupplierLogo_Change_Error"));
                }
                HttpPostedFileBase item = this.Request.Files[0];
                if (item.ContentLength > 512000)
                {
                    throw new UserFriendlyException(this.L("SupplierLogo_Warn_SizeLimit"));
                }
                GetSupplierForEditOutput supplierForEdit = await this._supplierAppService.GetSupplierForEdit(new NullableIdInput <long>(new long?((long)model.SupplierId)));

                GetSupplierForEditOutput nullable = supplierForEdit;
                if (nullable.Supplier.LogoId.HasValue)
                {
                    IBinaryObjectManager binaryObjectManager = this._binaryObjectManager;
                    logoId = nullable.Supplier.LogoId;
                    await binaryObjectManager.DeleteAsync(logoId.Value);
                }
                BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes());
                await this._binaryObjectManager.SaveAsync(binaryObject);

                nullable.Supplier.LogoId = new Guid?(binaryObject.Id);
                model.Id = nullable.Supplier.LogoId;
                UpdateSupplierLogoInput updateSupplierLogoInput = new UpdateSupplierLogoInput()
                {
                    SupplierId = nullable.Supplier.Id.Value
                };
                logoId = nullable.Supplier.LogoId;
                updateSupplierLogoInput.LogoId = new Guid?(logoId.Value);
                await this._supplierAppService.SaveLogoAsync(updateSupplierLogoInput);

                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }
Example #2
0
 public PartialViewResult ChangeSupplierLogo(SupplierLogoUploadModel model)
 {
     return(this.PartialView("_ChangeSupplierLogoModal", model));
 }