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 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)); }
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)); }