Пример #1
0
        public string UploadProductImageAsync <T>(IEnumerable <HttpPostedFileBase> attachments, string entityInput, ResizedVersion resizedVersion) where T : IImage
        {
            Guid entityId;

            if (Guid.TryParse(entityInput, out entityId))
            {
                foreach (var file in attachments)
                {
                    var fileName = Path.GetFileName(file.FileName);

                    //if (CheckIfImageForProductExist (Repository.Data.Get<T> (entityId).Image, fileName))
                    //return String.Empty;

                    FileType fileType;
                    Enum.TryParse(file.ContentType.Replace("image/", String.Empty), out fileType);

                    if (fileType != FileType.other && fileType < FileType.gif)
                    {
                        HttpPostedFileBase file1 = file;
                        LFile image          = CreateImageEntity(fileName, file1);
                        LFile scallableImage = CreateScallableImageEnity(file1, image, resizedVersion);

                        //Repository.Data.Save (image);
                        scallableImage.EntityId = entityId;
                        Repository.Data.Save(scallableImage);

                        var entity = Repository.Data.Get <T>(entityId);
                        entity.HasImage = true;

                        //entity.Image.Add (image);
                        Repository.Data.Save(entity);
                    }
                    else
                    {
                        return(StoreResourceStrings.OnlyImagesIsAllovedToUpload);
                    }
                }
            }
            return(String.Empty);
        }
Пример #2
0
        private LFile CreateScallableImageEnity(HttpPostedFileBase file1, LFile image, ResizedVersion resizedVersion)
        {
            var scallableImage = (LFile)image.Clone();

            int width  = 100;
            int height = 125;

            if (resizedVersion == ResizedVersion.To100x125)
            {
                width = 100; height = 125;
            }
            if (resizedVersion == ResizedVersion.To620x195)
            {
                width = 620; height = 195;
            }

            Stream imageStream = ScalableImageUtility.GetResizedVersionStream(width, height, file1.InputStream, ImageFormat.Jpeg, true);

            scallableImage.FileStream = new Lazy <Stream> (() => imageStream);
            scallableImage.ResizedTo  = resizedVersion;
            scallableImage.Name       = String.Format("Resized{0}_{1}", resizedVersion, image.Name);
            return(scallableImage);
        }