Example #1
0
        public Album GetOne(int id)
        {
            var album = _providerAlbum.GetOne(id);

            if (album == null)
            {
                return(null);
            }

            return(new Album()
            {
                Id = album.Id,
                ParentId = album.ParentId,
                DescriptionEng = album.DescriptionEng,
                DescriptionRu = album.DescriptionRu,
                TitleEng = album.TitleEng,
                TitleRu = album.TitleRu,
                CoverPath = album.CoverPath,
                ViewPattern = album.ViewPattern
            });
        }
Example #2
0
 public Watermark GetOne(int id)
 {
     return(_providerWatermark.GetOne(id));
 }
Example #3
0
 public TextAttributes GetOne(int id)
 {
     return(_providerAttr.GetOne(id));
 }
Example #4
0
 public Photo GetOne(int id)
 {
     return(_providerPhoto.GetOne(id));
 }
Example #5
0
        public PhotoUploadListModel Upload(IEnumerable <HttpPostedFileBase> files, PhotoUploadListModel listModel, IImageProcessor processor)
        {
            var model  = HttpContext.Current.Session["Uploads"] != null ? HttpContext.Current.Session["Uploads"] as PhotoUploadListModel : new PhotoUploadListModel();
            int maxId  = 0;
            int order  = 0;
            var photos = GetAll().ToList();

            // Если в БД уже есть фотографии, значит получаем макс. Id фотографии
            if (photos.Count > 0)
            {
                maxId = photos.Max(x => x.Id);
                order = photos.Max(x => x.Order);
            }

            // Проверяем, имеются ли в сессии уже загруженные фотогарфии, если да, то берем за макс Id значение из сессии
            if (model.Uploads.Any())
            {
                maxId = model.Uploads.Max(x => x.Id);
                order = model.Uploads.Max(x => x.Order);
            }

            foreach (var file in files)
            {
                var filename = $"photo_AS-S{++maxId}";

                var photoUploadModel = new PhotoUploadModel()
                {
                    Id              = maxId,
                    FileName        = filename,
                    PhotoPath       = "~/SysData/PhotoGallery/Photos/" + filename + Path.GetExtension(file.FileName).ToLower(),
                    ThumbnailPath   = "~/SysData/PhotoGallery/Thumbs/" + filename + "s" + Path.GetExtension(file.FileName).ToLower(),
                    CreationDate    = TimeZone.CurrentTimeZone.ToLocalTime(DateTime.Now),
                    ShowRandom      = false,
                    IsForBackground = false,
                    ImageAttributes = new ImageAttrModel()
                    {
                        Id                    = listModel.ImageAttributes.Id,
                        PhotoId               = 0,
                        IsWatermarkApplied    = listModel.ImageAttributes.IsWatermarkApplied,
                        IsWatermarkBlack      = listModel.ImageAttributes.IsWatermarkBlack,
                        IsSignatureApplied    = listModel.ImageAttributes.IsSignatureApplied,
                        IsSignatureBlack      = listModel.ImageAttributes.IsSignatureBlack,
                        IsWebSiteTitleApplied = listModel.ImageAttributes.IsWebSiteTitleApplied,
                        IsWebSiteTitleBlack   = listModel.ImageAttributes.IsWebSiteTitleBlack,
                        IsRightSide           = listModel.ImageAttributes.IsRightSide
                    },
                    Album = _providerAlbum.GetOne(listModel.AlbumId),
                    Order = ++order
                };

                if (file.ContentLength < 4048576)
                {
                    if (file != null)
                    {
                        processor.CreateThumbnail(file, 350, 350, filename);
                        photoUploadModel.ImageAttributes.PhotoId = photoUploadModel.Id;
                        file.SaveAs(HttpContext.Current.Server.MapPath(photoUploadModel.PhotoPath));
                        model.Uploads.Add(photoUploadModel);
                        HttpContext.Current.Session["Uploads"] = model;
                    }
                }
            }
            model.Albums = _providerAlbum.GetAll().Select(x => new SelectListItem()
            {
                Value = x.Id.ToString(),
                Text  = x.TitleRu
            });

            return(model);
        }