Exemple #1
0
        public ActionResult DeletePostGallery(int postId, int id)
        {
            ActionResult actionResult;

            if (!base.Request.IsAjaxRequest())
            {
                return(base.Json(new { success = false }));
            }
            try
            {
                PostGallery galleryImage = this._postGalleryService.Get((PostGallery x) => x.PostId == postId && x.Id == id, false);

                _postGalleryService.Delete(galleryImage);

                string path1 = base.Server.MapPath(string.Concat("~/", galleryImage.ImageBigSize));
                string path2 = base.Server.MapPath(string.Concat("~/", galleryImage.ImageMediumSize));
                string path3 = base.Server.MapPath(string.Concat("~/", galleryImage.ImageSmallSize));

                System.IO.File.Delete(path1);
                System.IO.File.Delete(path2);
                System.IO.File.Delete(path3);

                actionResult = base.Json(new { success = true });
            }
            catch (Exception ex)
            {
                actionResult = base.Json(new { success = false, messages = ex.Message });
            }
            return(actionResult);
        }
        public ActionResult PostGalleryAdd(int postId)
        {
            var byId          = _postService.GetById(postId, false);
            var titleOriginal = byId.Title;

            var files = Request.Files;

            if (files.Count > 0)
            {
                var count   = files.Count - 1;
                var num     = 0;
                var allKeys = files.AllKeys;
                for (var i = 0; i < allKeys.Length; i++)
                {
                    var str = allKeys[i];
                    if (num <= count)
                    {
                        if (!str.Equals("Image"))
                        {
                            var item = files[num];
                            if (item.ContentLength > 0)
                            {
                                var postGallery = new PostGallery
                                {
                                    PostId = postId,
                                    Status = (int)Status.Enable
                                };

                                var folderName    = Utils.FolderName(titleOriginal);
                                var fileExtension = Path.GetExtension(item.FileName);

                                var fileName1 = $"slide.{ titleOriginal}".FileNameFormat(fileExtension);
                                var fileName2 = $"slide.{ titleOriginal}".FileNameFormat(fileExtension);
                                var fileName3 = $"slide.{ titleOriginal}".FileNameFormat(fileExtension);

                                _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}{folderName}/", fileName1, ImageSize.PostGalleryWithBigSize, ImageSize.PostGalleryHeightBigSize, true);
                                _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}{folderName}/", fileName2, ImageSize.PostGalleryWithMediumSize, ImageSize.PostGalleryHeightMediumSize, true);
                                _imagePlugin.CropAndResizeImage(item, $"{Contains.PostFolder}{folderName}/", fileName3, ImageSize.PostGalleryWithSmallSize, ImageSize.PostGalleryHeightSmallSize, true);

                                postGallery.ImageBigSize    = $"{Contains.PostFolder}{folderName}/{fileName1}";
                                postGallery.ImageMediumSize = $"{Contains.PostFolder}{folderName}/{fileName2}";
                                postGallery.ImageSmallSize  = $"{Contains.PostFolder}{folderName}/{fileName3}";

                                _postGalleryService.Create(postGallery);
                            }
                            num++;
                        }
                        else
                        {
                            num++;
                        }
                    }
                }
            }

            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }
        public void Create(PostGallery Instance)
        {
            using (var db = new NEWSEntities())
            {
                try
                {
                    db.PostGalleries.Add(Instance);

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new AggregateException(ex);
                }
            }
        }
Exemple #4
0
        public async Task RunAsync(DateTimeOffset?favoratedTime        = null,
                                   Action <double>?onProgress          = null,
                                   CancellationToken cancellationToken = default)
        {
            IEnumerable <(string tagScopeName, string tagName)> tagsInfo =
                Illust.Tags.Select(x => ("Pixiv:Tag", x.Name))
                .Append(("Pixiv:ArtistId", Illust.User.Id.ToString(NumberFormatInfo.InvariantInfo)));

            var post = new Post
            {
                PublishedTime = Illust.Created,
                FavoritedTime = favoratedTime ?? DateTimeOffset.Now,
                Title         = Illust.Title,
                DetailText    = Illust.Description,
                Url           = new Uri($"https://www.pixiv.net/artworks/{Illust.Id}"),
                Provider      = "Pixiv:Illust",
                Identifier    = Illust.Id
            };

            await DownloadAsync(post.Images, onProgress, cancellationToken).ConfigureAwait(false);

            using var eContext = _eFactory.CreateDbContext();

            var tags = await tagsInfo
                       .ToAsyncEnumerable()
                       .SelectMany(x => eContext.MapTag(x.tagScopeName, x.tagName))
                       .Distinct()
                       .ToArrayAsync(cancellationToken)
                       .ConfigureAwait(false);

            eContext.Posts.Add(post);
            if (Illust.Pages.Count == 1)
            {
                post.Images[0].Tags.AddRange(tags.Select(x => new ImageTag(x.tagScopeName, x.tagName)));
            }
            else
            {
                var gallery = new PostGallery {
                    Name = Illust.Title, Post = post
                };
                gallery.Tags.AddRange(tags.Select(x => new GalleryTag(x.tagScopeName, x.tagName)));
                eContext.Add(gallery);
            }

            await eContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false);
        }
        public void Update(PostGallery Instance)
        {
            using (var db = new NEWSEntities())
            {
                try
                {
                    var existItem = db.PostGalleries.SingleOrDefault(d => d.ID == Instance.ID);

                    existItem.ID   = Instance.ID;
                    existItem.Name = Instance.Name;

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    throw new AggregateException(ex);
                }
            }
        }
Exemple #6
0
        public ActionResult PostGalleryEdit(PostGalleryViewModel model)
        {
            PostGallery postGallery = _postGalleryService.GetById(model.Id);

            if (postGallery != null)
            {
                model.ImageSmallSize  = postGallery.ImageSmallSize;
                model.ImageBigSize    = postGallery.ImageBigSize;
                model.ImageMediumSize = postGallery.ImageMediumSize;

                PostGallery postGalleryMap = Mapper.Map <PostGalleryViewModel, PostGallery>(model, postGallery);
                _postGalleryService.Update(postGalleryMap);
            }

            return(base.Json(
                       new
            {
                succes = true
            }
                       , JsonRequestBehavior.AllowGet));
        }
        public void Save(PostGallery Instance)
        {
            using (var db = new NEWSEntities())
            {
                try
                {
                    var existItem = db.PostGalleries.SingleOrDefault(d => d.ID == Instance.ID);

                    if (existItem != null)
                    {
                        Update(Instance);
                    }
                    else
                    {
                        Create(Instance);
                    }
                }
                catch (Exception ex)
                {
                    throw new AggregateException(ex);
                }
            }
        }
Exemple #8
0
		public JsonResult SavePostGallery(GalleryViewModel model)
		{
			model.PostGalleries = _postGalleryRepository.GetAll();

			try
			{
				if (model.PostGalleryID == null) model.PostGalleryID = 0;

				var postgallery = new PostGallery
				{
					ID = (long)model.PostGalleryID,
					Name = model.PostGalleryName,
				};

				_postGalleryRepository.Save(postgallery);

				return Json(model, JsonRequestBehavior.AllowGet);
			}
			catch (Exception e)
			{
				ModelState.AddModelError(String.Empty, e.Message);
				return Json(model, JsonRequestBehavior.AllowGet);
			}
		}
Exemple #9
0
        public ActionResult PostGalleryAdd(int postId)
        {
            List <PostGallery> lstPostGallery = new List <PostGallery>();

            HttpFileCollectionBase files = Request.Files;

            if (files.Count > 0)
            {
                int      count   = files.Count - 1;
                int      num     = 0;
                string[] allKeys = files.AllKeys;
                for (int i = 0; i < (int)allKeys.Length; i++)
                {
                    string str = allKeys[i];
                    if (num <= count)
                    {
                        if (!str.Equals("Image"))
                        {
                            HttpPostedFileBase item = files[num];
                            if (item.ContentLength > 0)
                            {
                                PostGallery postGallery = new PostGallery()
                                {
                                    PostId = postId
                                };

                                string fileNameNonAccent = string.Format("{0}", item.FileName.NonAccent());
                                string folderName        = string.Format("{0:ddMMyyyy}", DateTime.UtcNow);

                                string fileExtension = Path.GetExtension(item.FileName);

                                string fileName1 = fileNameNonAccent.FileNameFormat(fileExtension);
                                string fileName2 = fileNameNonAccent.FileNameFormat(fileExtension);
                                string fileName3 = fileNameNonAccent.FileNameFormat(fileExtension);

                                //string str3 = string.Format("{0}.jpg", fileNameNonAccent);
                                //string str4 = string.Format("{0}-{1}.jpg", fileNameNonAccent, Guid.NewGuid());
                                //string str5 = string.Format("{0}-{1}.jpg", fileNameNonAccent, Guid.NewGuid());

                                this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName1, ImageSize.WithBigSize, ImageSize.HeightBigSize, false);
                                this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName2, ImageSize.WithMediumSize, ImageSize.HeightMediumSize, false);
                                this._imagePlugin.CropAndResizeImage(item, string.Format("{0}{1}/", Contains.PostFolder, folderName), fileName3, ImageSize.WithSmallSize, ImageSize.HeightSmallSize, false);

                                postGallery.ImageBigSize    = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName1);
                                postGallery.ImageMediumSize = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName2);
                                postGallery.ImageSmallSize  = string.Format("{0}{1}/{2}", Contains.PostFolder, folderName, fileName3);

                                _postGalleryService.Create(postGallery);
                            }
                            num++;
                        }
                        else
                        {
                            num++;
                        }
                    }
                }
            }

            return(Json(new { Result = true }, JsonRequestBehavior.AllowGet));
        }
Exemple #10
0
        public ActionResult PostGalleryAdd(int postId)
        {
            var byId          = _postService.GetById(postId, false);
            var titleOriginal = byId.Title;

            var files = Request.Files;

            if (files.Count > 0)
            {
                var count   = files.Count - 1;
                var num     = 0;
                var allKeys = files.AllKeys;
                for (var i = 0; i < allKeys.Length; i++)
                {
                    var str = allKeys[i];
                    if (num <= count)
                    {
                        if (!str.Equals("Image"))
                        {
                            var item = files[num];
                            if (item.ContentLength > 0)
                            {
                                var postGallery = new PostGallery
                                {
                                    OrderDisplay = _postGalleryService.GetMaxOrderDiplay(postId),
                                    //IsAvatar = i == 0 ? (int)Status.Enable : (int)Status.Disable,
                                    PostId = postId,
                                    Status = (int)Status.Enable
                                };

                                var folderName    = CommonHelper.FolderName(titleOriginal);
                                var fileExtension = Path.GetExtension(item.FileName);

                                var fileNameBg = $"slide.{ titleOriginal}".FileNameFormat(fileExtension);
                                var fileNameMd = $"slide.{ titleOriginal}".FileNameFormat(fileExtension);
                                var fileNameSm = $"slide.{ titleOriginal}".FileNameFormat(fileExtension);

                                var sizeWidthBg  = _settingService.GetSetting("Post.GalleryWidthBigSize", ImageSize.WidthDefaultSize);
                                var sizeHeightBg = _settingService.GetSetting("Post.GalleryHeightBigSize", ImageSize.HeightDefaultSize);
                                var sizeWidthMd  = _settingService.GetSetting("Post.GalleryWidthMediumSize", ImageSize.WidthDefaultSize);
                                var sizeHeightMd = _settingService.GetSetting("Post.GalleryHeightMediumSize", ImageSize.HeightDefaultSize);
                                var sizeWidthSm  = _settingService.GetSetting("Post.GalleryWidthSmallSize", ImageSize.WidthDefaultSize);
                                var sizeHeightSm = _settingService.GetSetting("Post.GalleryHeightSmallSize", ImageSize.HeightDefaultSize);

                                _imageService.CropAndResizeImage(item, $"{Constant.PostFolder}{folderName}/", fileNameBg, sizeWidthBg, sizeHeightBg);
                                _imageService.CropAndResizeImage(item, $"{Constant.PostFolder}{folderName}/", fileNameMd, sizeWidthMd, sizeHeightMd);
                                _imageService.CropAndResizeImage(item, $"{Constant.PostFolder}{folderName}/", fileNameSm, sizeWidthSm, sizeHeightSm);

                                postGallery.ImageBigSize    = $"{Constant.PostFolder}{folderName}/{fileNameBg}";
                                postGallery.ImageMediumSize = $"{Constant.PostFolder}{folderName}/{fileNameMd}";
                                postGallery.ImageSmallSize  = $"{Constant.PostFolder}{folderName}/{fileNameSm}";

                                _postGalleryService.Create(postGallery);
                            }
                            num++;
                        }
                        else
                        {
                            num++;
                        }
                    }
                }
            }

            return(Json(new { success = true }, JsonRequestBehavior.AllowGet));
        }