예제 #1
0
        public async Task ClearLogo()
        {
            var tenant = await GetCurrentTenantAsync();

            if (!tenant.HasLogo())
            {
                return;
            }

            var logoObject = await _binaryObjectManager.GetOrNullAsync(tenant.LogoId.Value);

            if (logoObject != null)
            {
                await _binaryObjectManager.DeleteAsync(tenant.LogoId.Value);
            }

            tenant.ClearLogo();
        }
        public async Task UpdateProfilePicture(UpdateProfilePictureInput input)
        {
            var tempProfilePicturePath = Path.Combine(_appFolders.TempFileDownloadFolder, input.FileName);

            byte[] byteArray;

            using (var fsTempProfilePicture = new FileStream(tempProfilePicturePath, FileMode.Open))
            {
                using (var bmpImage = new Bitmap(fsTempProfilePicture))
                {
                    var width  = input.Width == 0 ? bmpImage.Width : input.Width;
                    var height = input.Height == 0 ? bmpImage.Height : input.Height;
                    var bmCrop = bmpImage.Clone(new Rectangle(input.X, input.Y, width, height), bmpImage.PixelFormat);

                    using (var stream = new MemoryStream())
                    {
                        bmCrop.Save(stream, bmpImage.RawFormat);
                        stream.Close();
                        byteArray = stream.ToArray();
                    }
                }
            }

            if (byteArray.LongLength > 102400) //100 KB
            {
                throw new UserFriendlyException(L("ResizedProfilePicture_Warn_SizeLimit"));
            }

            var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId());

            if (user.ProfilePictureId.HasValue)
            {
                await _binaryObjectManager.DeleteAsync(user.ProfilePictureId.Value);
            }

            var storedFile = new BinaryObject(AbpSession.TenantId, byteArray);
            await _binaryObjectManager.SaveAsync(storedFile);

            user.ProfilePictureId = storedFile.Id;

            FileHelper.DeleteIfExists(tempProfilePicturePath);
        }
예제 #3
0
        public async Task UpdateProfilePicture(UpdateProfilePictureInput input)
        {
            await SettingManager.ChangeSettingForUserAsync(
                AbpSession.ToUserIdentifier(),
                AppSettings.UserManagement.UseGravatarProfilePicture,
                input.UseGravatarProfilePicture.ToString().ToLowerInvariant()
                );

            if (input.UseGravatarProfilePicture)
            {
                return;
            }

            byte[] byteArray;

            var imageBytes = _tempFileCacheManager.GetFile(input.FileToken);

            if (imageBytes == null)
            {
                throw new UserFriendlyException("There is no such image file with the token: " + input.FileToken);
            }

            using (var bmpImage = new Bitmap(new MemoryStream(imageBytes)))
            {
                var width  = (input.Width == 0 || input.Width > bmpImage.Width) ? bmpImage.Width : input.Width;
                var height = (input.Height == 0 || input.Height > bmpImage.Height) ? bmpImage.Height : input.Height;
                var bmCrop = bmpImage.Clone(new Rectangle(input.X, input.Y, width, height), bmpImage.PixelFormat);

                using (var stream = new MemoryStream())
                {
                    bmCrop.Save(stream, bmpImage.RawFormat);
                    byteArray = stream.ToArray();
                }
            }

            if (byteArray.Length > MaxProfilPictureBytes)
            {
                throw new UserFriendlyException(L("ResizedProfilePicture_Warn_SizeLimit",
                                                  AppConsts.ResizedMaxProfilPictureBytesUserFriendlyValue));
            }

            var user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId());

            if (user.ProfilePictureId.HasValue)
            {
                await _binaryObjectManager.DeleteAsync(user.ProfilePictureId.Value);
            }

            var storedFile = new BinaryObject(AbpSession.TenantId, byteArray);
            await _binaryObjectManager.SaveAsync(storedFile);

            user.ProfilePictureId = storedFile.Id;
        }
예제 #4
0
        //[AbpAuthorize(PermissionNames.Administration_Facilities_Manage)]
        public async Task <UpdateProfilePictureOutput> UpdateIconPicture(UpdateProfilePictureInput input)
        {
            var tenant = await _tenantManager.FindByIdAsync(input.TenantId);

            if (tenant == null)
            {
                throw new UserFriendlyException(L("InvalidAction"));
            }

            byte[] data;
            using (var ms = new MemoryStream())
            {
                var newWidth  = input.Width;
                var newHeight = input.Height;

                using (var newImg = new Bitmap(newWidth, newHeight))
                {
                    var fullPath = Path.Combine(Path.GetTempPath(), input.FileName);
                    using (var img = Image.FromFile(fullPath))
                        using (var g = Graphics.FromImage(newImg))
                        {
                            g.DrawImage(img,
                                        new Rectangle(0, 0, newWidth, newHeight),
                                        new Rectangle(input.X, input.Y, input.Width, input.Height),
                                        GraphicsUnit.Pixel);
                        }
                    newImg.Save(ms, ImageFormat.Jpeg);
                }

                data = ms.ToArray();
            }

            var binaryObjectId = await _binaryObjectManager.SaveAsync(BinaryObjectTypes.TenantProfilePicture, data, "image/jpeg");

            if (tenant.ProfilePictureId != null)
            {
                await _binaryObjectManager.DeleteAsync(tenant.ProfilePictureId.Value, BinaryObjectTypes.TenantProfilePicture);
            }

            tenant.UpdateProfilePicture(binaryObjectId);
            await _tenantManager.UpdateAsync(tenant);

            return(new UpdateProfilePictureOutput
            {
                TenantId = tenant.Id,
                ProfilePictureId = tenant.ProfilePictureId
            });
        }
예제 #5
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);
        }
예제 #6
0
        public virtual async Task <JsonResult> UpdateTitleImage(long titleId)
        {
            JsonResult jsonResult;
            Guid?      imageId;

            try
            {
                if (this.Request.Files.Count <= 0 || this.Request.Files[0] == null)
                {
                    throw new UserFriendlyException(this.L("TitleImage_Change_Error"));
                }
                HttpPostedFileBase item = this.Request.Files[0];
                if (item.ContentLength > 512000)
                {
                    throw new UserFriendlyException(this.L("TitleImage_Warn_SizeLimit"));
                }
                GetTitleForEditOutput titleForEdit = await this._titleAppService.GetTitleForEdit(new NullableIdInput <long>(new long?(titleId)));

                GetTitleForEditOutput nullable = titleForEdit;
                if (nullable.Title.ImageId.HasValue)
                {
                    IBinaryObjectManager binaryObjectManager = this._binaryObjectManager;
                    imageId = nullable.Title.ImageId;
                    await binaryObjectManager.DeleteAsync(imageId.Value);
                }
                BinaryObject binaryObject = new BinaryObject(item.InputStream.GetAllBytes());
                await this._binaryObjectManager.SaveAsync(binaryObject);

                nullable.Title.ImageId = new Guid?(binaryObject.Id);
                UpdateTitleImageInput updateTitleImageInput = new UpdateTitleImageInput()
                {
                    TitleId = nullable.Title.Id.Value
                };
                imageId = nullable.Title.ImageId;
                updateTitleImageInput.ImageId = new Guid?(imageId.Value);
                await this._titleAppService.SaveTitleImageAsync(updateTitleImageInput);

                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }
예제 #7
0
        public async Task DeleteFile(Guid guid)
        {
            var file = await _binaryObjectManager.GetOrNullAsync(guid);

            if (file != null)
            {
                var filePath = System.Web.Hosting.HostingEnvironment.MapPath(file.Url);
                if (File.Exists(filePath))
                {
                    if (filePath != null)
                    {
                        File.Delete(filePath);
                        await _binaryObjectManager.DeleteAsync(guid);
                    }
                }
            }
        }
예제 #8
0
        protected virtual async Task UpdateIconizTeamMemberAsync(TeamMemberEditDto input)
        {
            var iconizTeamMember = await _iconizTeamMemberRepository.GetAsync(input.Id.Value);

            if (!string.IsNullOrEmpty(input.ProfilePictureFileName))
            {
                if (iconizTeamMember.ProfilePictureId.HasValue)
                {
                    await _binaryObjectManager.DeleteAsync(iconizTeamMember.ProfilePictureId.Value);
                }
                input.ProfilePictureId = iconizTeamMember.ProfilePictureId = await StoreProfilePicture(input.ProfilePictureFileName);
            }

            ObjectMapper.Map(input, iconizTeamMember);
            await _iconizTeamMemberRepository.UpdateAsync(iconizTeamMember);

            await CurrentUnitOfWork.SaveChangesAsync();
        }
예제 #9
0
        public virtual async Task <JsonResult> ChangeProfilePicture()
        {
            try
            {
                //Check input
                if (Request.Files.Count <= 0 || Request.Files[0] == null)
                {
                    throw new UserFriendlyException(L("ProfilePicture_Change_Error"));
                }

                var file = Request.Files[0];

                if (file.ContentLength > 30720) //30KB.
                {
                    throw new UserFriendlyException(L("ProfilePicture_Warn_SizeLimit"));
                }

                //Get user
                var user = await _userManager.GetUserByIdAsync(AbpSession.GetUserId());

                //Delete old picture
                if (user.ProfilePictureId.HasValue)
                {
                    await _binaryObjectManager.DeleteAsync(user.ProfilePictureId.Value);
                }

                //Save new picture
                var storedFile = new BinaryObject(AbpSession.TenantId, file.InputStream.GetAllBytes());
                await _binaryObjectManager.SaveAsync(storedFile);

                //Update new picture on the user
                user.ProfilePictureId = storedFile.Id;

                //Return success
                return(Json(new AjaxResponse()));
            }
            catch (UserFriendlyException ex)
            {
                //Return error message
                return(Json(new AjaxResponse(new ErrorInfo(ex.Message))));
            }
        }
예제 #10
0
        private async Task <byte[]> UpdateCompanyLogo(TenantExtendedUnitInput input)
        {
            var tempProfilePicturePath = Path.Combine(_appFolders.TempFileDownloadFolder, input.ComapanyLogo.FileName);

            byte[] byteArray;

            using (var fsTempProfilePicture = new FileStream(tempProfilePicturePath, FileMode.Open))
            {
                using (var bmpImage = new Bitmap(fsTempProfilePicture))
                {
                    var width  = input.ComapanyLogo.Width == 0 ? bmpImage.Width : input.ComapanyLogo.Width;
                    var height = input.ComapanyLogo.Height == 0 ? bmpImage.Height : input.ComapanyLogo.Height;
                    var bmCrop = bmpImage.Clone(new Rectangle(input.ComapanyLogo.X, input.ComapanyLogo.Y, width, height), bmpImage.PixelFormat);

                    using (var stream = new MemoryStream())
                    {
                        bmCrop.Save(stream, bmpImage.RawFormat);
                        stream.Close();
                        byteArray = stream.ToArray();
                    }
                }
            }

            if (byteArray.LongLength > 1024000) //1000 KB
            {
                throw new UserFriendlyException(L("ResizedProfilePicture_Warn_SizeLimit"));
            }


            if (input.CompanyLogoId.HasValue)
            {
                await _binaryObjectManager.DeleteAsync(input.CompanyLogoId.Value);
            }

            var storedFile = new BinaryObject(AbpSession.TenantId, byteArray);
            await _binaryObjectManager.SaveAsync(storedFile);

            input.CompanyLogoId = storedFile.Id;
            return(byteArray);
        }
예제 #11
0
        /// <summary>
        /// 修改用户头像
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task UpdateHeadImage(UpdateHeadImageInput input)
        {
            string fixedFilePath = String.Empty, absoluteFilePath = String.Empty;
            string absolutePath = "/AppData/FileUpload/Image/HeadImage/";
            string fixedPath    = _environment.ContentRootPath + absolutePath;
            var    imageBytes   = _tempFileCacheManager.GetFile(input.FileToken);

            if (imageBytes == null)
            {
                throw new UserFriendlyException("There is no such image file with the token: " + input.FileToken);
            }
            using (var bmpImage = new Bitmap(new MemoryStream(imageBytes)))
            {
                var width  = (input.Width == 0 || input.Width > bmpImage.Width) ? bmpImage.Width : input.Width;
                var height = (input.Height == 0 || input.Height > bmpImage.Height) ? bmpImage.Height : input.Height;
                var bmCrop = bmpImage.Clone(new Rectangle(input.X, input.Y, width, height), bmpImage.PixelFormat);
                // TODO:限制裁剪后图片大小 1、先将图片保存成流 2、判断大小 3、大了结束。小了再将流保存成图片
                if (!Directory.Exists(fixedPath))
                {
                    Directory.CreateDirectory(fixedPath);
                }
                absoluteFilePath = absolutePath + input.FileToken + ".jpg";
                fixedFilePath    = fixedPath + input.FileToken + ".jpg";
                bmCrop.Save(fixedFilePath, bmpImage.RawFormat);
            }

            User user = await UserManager.GetUserByIdAsync(AbpSession.GetUserId());

            if (user.ProfilePictureId.HasValue)
            {
                await _binaryObjectManager.DeleteAsync(user.ProfilePictureId.Value);
            }

            var storedFile = new BinaryObject(AbpSession.TenantId, absoluteFilePath);
            await _binaryObjectManager.SaveAsync(storedFile);

            user.ProfilePictureId = storedFile.Id;
        }
예제 #12
0
        public virtual async Task <JsonResult> UpdateTenantLogos(TenantLogosUploadModel model)
        {
            JsonResult   jsonResult;
            Guid?        headerImageId;
            BinaryObject binaryObject;
            BinaryObject binaryObject1;
            BinaryObject binaryObject2;
            BinaryObject binaryObject3;

            try
            {
                bool flag = false;
                ITenantSettingsAppService tenantSettingsAppService = this._tenantSettingsAppService;
                int?tenantId = this.AbpSession.TenantId;
                TenantLogosEditDto tenantLogos = await tenantSettingsAppService.GetTenantLogos(tenantId.Value);

                if (this.Request.Files.Count > 0)
                {
                    foreach (object key in this.Request.Files.Keys)
                    {
                        HttpPostedFileBase item = this.Request.Files[key.ToString()];
                        if (item.ContentLength > 512000)
                        {
                            throw new UserFriendlyException(this.L("TenantCompanyLogo_Warn_SizeLimit"));
                        }
                        string str = key.ToString();
                        if (str == "HeaderImage")
                        {
                            headerImageId = tenantLogos.HeaderImageId;
                            if (headerImageId.HasValue)
                            {
                                headerImageId = tenantLogos.HeaderImageId;
                                if (headerImageId.Value != Guid.Empty)
                                {
                                    IBinaryObjectManager binaryObjectManager = this._binaryObjectManager;
                                    headerImageId = tenantLogos.HeaderImageId;
                                    await binaryObjectManager.DeleteAsync(headerImageId.Value);
                                }
                            }
                            binaryObject = new BinaryObject(item.InputStream.GetAllBytes());
                            await this._binaryObjectManager.SaveAsync(binaryObject);

                            tenantLogos.HeaderImageId = new Guid?(binaryObject.Id);
                            flag = true;
                        }
                        else if (str == "HeaderMobileImage")
                        {
                            headerImageId = tenantLogos.HeaderMobileImageId;
                            if (headerImageId.HasValue)
                            {
                                headerImageId = tenantLogos.HeaderMobileImageId;
                                if (headerImageId.Value != Guid.Empty)
                                {
                                    IBinaryObjectManager binaryObjectManager1 = this._binaryObjectManager;
                                    headerImageId = tenantLogos.HeaderMobileImageId;
                                    await binaryObjectManager1.DeleteAsync(headerImageId.Value);
                                }
                            }
                            binaryObject1 = new BinaryObject(item.InputStream.GetAllBytes());
                            await this._binaryObjectManager.SaveAsync(binaryObject1);

                            tenantLogos.HeaderMobileImageId = new Guid?(binaryObject1.Id);
                            flag = true;
                        }
                        else if (str == "MailImage")
                        {
                            headerImageId = tenantLogos.MailImageId;
                            if (headerImageId.HasValue)
                            {
                                headerImageId = tenantLogos.MailImageId;
                                if (headerImageId.Value != Guid.Empty)
                                {
                                    IBinaryObjectManager binaryObjectManager2 = this._binaryObjectManager;
                                    headerImageId = tenantLogos.MailImageId;
                                    await binaryObjectManager2.DeleteAsync(headerImageId.Value);
                                }
                            }
                            binaryObject2 = new BinaryObject(item.InputStream.GetAllBytes());
                            await this._binaryObjectManager.SaveAsync(binaryObject2);

                            tenantLogos.MailImageId = new Guid?(binaryObject2.Id);
                            flag = true;
                        }
                        else if (str == "InvoiceImage")
                        {
                            headerImageId = tenantLogos.InvoiceImageId;
                            if (headerImageId.HasValue)
                            {
                                headerImageId = tenantLogos.InvoiceImageId;
                                if (headerImageId.Value != Guid.Empty)
                                {
                                    IBinaryObjectManager binaryObjectManager3 = this._binaryObjectManager;
                                    headerImageId = tenantLogos.InvoiceImageId;
                                    await binaryObjectManager3.DeleteAsync(headerImageId.Value);
                                }
                            }
                            binaryObject3 = new BinaryObject(item.InputStream.GetAllBytes());
                            await this._binaryObjectManager.SaveAsync(binaryObject3);

                            tenantLogos.InvoiceImageId = new Guid?(binaryObject3.Id);
                            flag = true;
                        }
                        binaryObject  = null;
                        binaryObject1 = null;
                        binaryObject2 = null;
                        binaryObject3 = null;
                        item          = null;
                    }
                }
                if (model.ClearHeaderImageId.HasValue && model.ClearHeaderImageId.Value)
                {
                    headerImageId = model.HeaderImageId;
                    if (headerImageId.HasValue)
                    {
                        IBinaryObjectManager binaryObjectManager4 = this._binaryObjectManager;
                        headerImageId = tenantLogos.HeaderImageId;
                        await binaryObjectManager4.DeleteAsync(headerImageId.Value);

                        headerImageId             = null;
                        tenantLogos.HeaderImageId = headerImageId;
                        flag = true;
                    }
                }
                if (model.ClearHeaderMobileImageId.HasValue && model.ClearHeaderMobileImageId.Value)
                {
                    headerImageId = model.HeaderMobileImageId;
                    if (headerImageId.HasValue)
                    {
                        IBinaryObjectManager binaryObjectManager5 = this._binaryObjectManager;
                        headerImageId = tenantLogos.HeaderMobileImageId;
                        await binaryObjectManager5.DeleteAsync(headerImageId.Value);

                        headerImageId = null;
                        tenantLogos.HeaderMobileImageId = headerImageId;
                        flag = true;
                    }
                }
                if (model.ClearMailImageId.HasValue && model.ClearMailImageId.Value)
                {
                    headerImageId = model.MailImageId;
                    if (headerImageId.HasValue)
                    {
                        IBinaryObjectManager binaryObjectManager6 = this._binaryObjectManager;
                        headerImageId = tenantLogos.MailImageId;
                        await binaryObjectManager6.DeleteAsync(headerImageId.Value);

                        headerImageId           = null;
                        tenantLogos.MailImageId = headerImageId;
                        flag = true;
                    }
                }
                if (model.ClearInvoiceImageId.HasValue && model.ClearInvoiceImageId.Value)
                {
                    headerImageId = model.InvoiceImageId;
                    if (headerImageId.HasValue)
                    {
                        IBinaryObjectManager binaryObjectManager7 = this._binaryObjectManager;
                        headerImageId = tenantLogos.InvoiceImageId;
                        await binaryObjectManager7.DeleteAsync(headerImageId.Value);

                        headerImageId = null;
                        tenantLogos.InvoiceImageId = headerImageId;
                        flag = true;
                    }
                }
                if (flag)
                {
                    await this._tenantSettingsAppService.UpdateTenantLogos(tenantLogos);
                }
                jsonResult = this.Json(new MvcAjaxResponse());
            }
            catch (UserFriendlyException userFriendlyException1)
            {
                UserFriendlyException userFriendlyException = userFriendlyException1;
                jsonResult = this.Json(new MvcAjaxResponse(new ErrorInfo(userFriendlyException.Message), false));
            }
            return(jsonResult);
        }