Ejemplo n.º 1
0
        public string SaveBrandImage(Image image, PngFormat imageFormat, Tenant tenant)
        {
            var pathFileStorageDirectory = AppSettingConfigurationHelper.GetSection("PathFileStorageDirectory").Value;

            if (pathFileStorageDirectory == null || pathFileStorageDirectory.Equals(string.Empty))
            {
                throw new Exception("File configuration must have App Setting with key PathFileStorageDirectory");
            }

            var pathDirectoryProduct = Path.Combine(pathFileStorageDirectory, "Images", "Tenants", tenant.TenancyName);

            var directoryProductInfo = new DirectoryInfo(pathDirectoryProduct);

            if (!Directory.Exists(pathDirectoryProduct))
            {
                Directory.CreateDirectory(pathDirectoryProduct);
            }

            var resizedImage = ImageResizer.FixedSize(image, 100, 100);
            var filePath     = Path.Combine(directoryProductInfo.FullName, string.Format("{0}{1}", "brand", imageFormat.GetFileExtension()));

            var encoder = imageFormat.GetEncoder();

            resizedImage.Save(filePath, encoder);
            resizedImage.Dispose();
            return(Path.Combine("Images", "Tenants", tenant.TenancyName, "brand" + imageFormat.GetFileExtension()));
        }