Esempio n. 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);
        }
Esempio n. 2
0
        public async Task SaveLogoAsync(UpdateSupplierLogoInput input)
        {
            Supplier async = await this._supplierRepository.GetAsync(input.SupplierId);

            Guid?logoId = input.LogoId;

            if (!logoId.HasValue)
            {
                logoId       = null;
                async.LogoId = logoId;
            }
            else
            {
                logoId       = input.LogoId;
                async.LogoId = new Guid?(logoId.Value);
            }
            await this._supplierRepository.UpdateAsync(async);
        }