Example #1
0
        public void DeleteOne(int id)
        {
            var photoToTags = _providerPhotoToTag.GetAll().Where(x => x.TagId == id).ToList();

            if (photoToTags.Count() > 0)
            {
                _providerPhotoToTag.DeleteMany(photoToTags.Select(x => x.Id).ToArray());
            }

            _providerTag.DeleteOne(id);
            _providerTag.Commit();
        }
Example #2
0
        public IEnumerable <TagCloudModel> GenerateTagCloud()
        {
            var photos = _providerPhoto.GetAll();

            var cloud = _providerPhotoToTag.GetAll().Join(GetAll(), i => i.TagId, o => o.Id, (i, o) => new
            {
                Id       = i.TagId,
                TitleRu  = o.TitleRu,
                TitleEng = o.TitleEng,
            }).GroupBy(t => t.Id).Select(x => new TagCloudModel()
            {
                Id       = x.Key,
                Count    = x.Count(),
                TitleRu  = x.Select(r => r.TitleRu).FirstOrDefault(),
                TitleEng = x.Select(r => r.TitleEng).FirstOrDefault(),
            }).OrderByDescending(t => t.Count).Take(15);

            return(cloud);
        }
Example #3
0
        public Photo UpdateOne(PhotoUploadModel model, HttpPostedFileBase file, IImageProcessor processor)
        {
            var photoToTags   = _providerPhotoToTag.GetAll();
            var relatedTagIds = photoToTags.GetRelatedTags(model.Id).Select(x => x.Id).ToArray();

            if (relatedTagIds.Length > 0)
            {
                _providerPhotoToTag.DeleteMany(relatedTagIds);
                _providerPhoto.Commit(); //TODO: продумать
            }

            if (file != null)
            {
                if (file.ContentLength != 0 && file.ContentLength < 4048576)
                {
                    processor.CreateThumbnail(file, 350, 350, model.FileName);
                    file.SaveAs(HttpContext.Current.Server.MapPath(model.PhotoPath));
                }
            }

            var photos = _providerPhoto.UpdateOne(_converter.ConvertTo(model));

            _providerWatermark.UpdateOne(_converterWatermark.ConvertTo(model.ImageAttributes));

            if (model.RelatedTagIds != null)
            {
                _providerPhotoToTag.AddMany(model.RelatedTagIds
                                            .Select(x => new PhotoToTag()
                {
                    Id      = 0,
                    PhotoId = model.Id,
                    TagId   = x
                }).ToArray()
                                            );
            }

            _providerPhoto.Commit();

            return(photos);
        }
Example #4
0
        public void DeleteOne(int id)
        {
            var photo       = GetOne(id);
            var photoToTags = _providerPhotoToTag.GetAll().Where(x => x.PhotoId == id).ToList();
            var watermark   = _providerWatermark.GetAll().FirstOrDefault(x => x.PhotoId == id);

            if (photoToTags.Count() > 0)
            {
                _providerPhotoToTag.DeleteMany(photoToTags.Select(x => x.Id).ToArray());
            }

            if (watermark != null)
            {
                _providerWatermark.DeleteOne(watermark.Id);
            }

            System.IO.File.Delete(HttpContext.Current?.Server?.MapPath(photo?.PhotoPath));
            System.IO.File.Delete(HttpContext.Current?.Server?.MapPath(photo?.ThumbnailPath));

            _providerPhoto.DeleteOne(id);
            _providerPhoto.Commit();
        }
Example #5
0
 public IEnumerable <Tag> GetAll()
 {
     return(_providerTag.GetAll());
 }
Example #6
0
 public IEnumerable <Watermark> GetAll()
 {
     return(_providerWatermark.GetAll());
 }
Example #7
0
 public IEnumerable <TextAttributes> GetAll()
 {
     return(_providerAttr.GetAll().ToList());
 }
Example #8
0
 public IEnumerable <Photo> GetAll()
 {
     return(_providerPhoto.GetAll().ToList());
 }
Example #9
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);
        }
Example #10
0
 public IEnumerable <Album> GetAll()
 {
     return(_providerAlbum.GetAll());
 }