Beispiel #1
0
        public ActionResult EditGalleryUploads(App app)
        {
            var token = Request["__RequestVerificationToken"];
            var path  = AppVar.Url + Statics.UProcessorGallery.RootPath.Replace("~/", "/") +
                        Statics.UProcessorGallery.AdditionalRoots;

            var uploadedImages = db.Galleries
                                 .Where(
                n =>
                n.GalleryCategoryID == GalleryCategoryIDs.AppPageGallery &&
                n.UploadGuid == app.UploadGuid)
                                 .OrderBy(n => n.Sequence)
                                 .AsEnumerable()
                                 .Select(n => new UploadedGalleryImageEditViewModel {
                Tile       = n.Title,
                Subtitle   = n.Subtitle,
                Sequence   = n.Sequence,
                UploadGuid = n.UploadGuid,
                Id         = app.AppID,
                ImageURL   = path + UploadProcessor.GetOrganizeNameStatic(n, true, false, ""),
                DeleteURL  = "/" + ControllerName +
                             "/DeleteGalleryImage?uploadGuid=" + n.UploadGuid +
                             "&sequence=" + n.Sequence +
                             "&__RequestVerificationToken=" + token
                             //ReUploadURL = "/" + _controllerName +
                             //"/ReuploadGalleryImage?uploadGuid=" + n.UploadGuid +
                             //"&sequence=" + n.Sequence +
                             //"&__RequestVerificationToken=" + token
            }).ToList();

            return(View(uploadedImages));
        }
Beispiel #2
0
        /// <summary>
        /// Returns image http url.
        /// </summary>
        /// <param name="gallery"></param>
        /// <param name="categoryId">
        /// If category given then returns based on category not in the gallery category.
        /// Useful while working with thumbs on gallery/ gallery icon.
        /// </param>
        /// <returns></returns>
        public static string GetHtppUrl(this Gallery gallery, int?categoryId = null)
        {
            var location = "";

            if (gallery != null && categoryId == null)
            {
                if (gallery.GalleryCategoryID == GalleryCategoryIDs.AppPageGallery)
                {
                    location = Statics.UProcessorGallery.GetCombinePathWithAdditionalRoots();
                }
                else if (gallery.GalleryCategoryID == GalleryCategoryIDs.GalleryIcon)
                {
                    location = Statics.UProcessorGalleryIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (gallery.GalleryCategoryID == GalleryCategoryIDs.HomePageFeatured)
                {
                    location = Statics.UProcessorHomeFeatured.GetCombinePathWithAdditionalRoots();
                }
                else if (gallery.GalleryCategoryID == GalleryCategoryIDs.HomePageIcon)
                {
                    location = Statics.UProcessorHomeIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (gallery.GalleryCategoryID == GalleryCategoryIDs.SearchIcon)
                {
                    location = Statics.UProcessorSearchIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (gallery.GalleryCategoryID == GalleryCategoryIDs.SuggestionIcon)
                {
                    location = Statics.UProcessorSuggestionIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (gallery.GalleryCategoryID == GalleryCategoryIDs.Advertise)
                {
                    location = Statics.UProcessorAdvertiseImages.GetCombinePathWithAdditionalRoots();
                }
                else if (gallery.GalleryCategoryID == GalleryCategoryIDs.YoutubeCoverImage)
                {
                    location = Statics.UProcessorYoutubeCover.GetCombinePathWithAdditionalRoots();
                }
            }
            else if (gallery != null && categoryId != null)
            {
                if (categoryId == GalleryCategoryIDs.AppPageGallery)
                {
                    location = Statics.UProcessorGallery.GetCombinePathWithAdditionalRoots();
                }
                else if (categoryId == GalleryCategoryIDs.GalleryIcon)
                {
                    location = Statics.UProcessorGalleryIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (categoryId == GalleryCategoryIDs.HomePageFeatured)
                {
                    location = Statics.UProcessorHomeFeatured.GetCombinePathWithAdditionalRoots();
                }
                else if (categoryId == GalleryCategoryIDs.HomePageIcon)
                {
                    location = Statics.UProcessorHomeIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (categoryId == GalleryCategoryIDs.SearchIcon)
                {
                    location = Statics.UProcessorSearchIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (categoryId == GalleryCategoryIDs.SuggestionIcon)
                {
                    location = Statics.UProcessorSuggestionIcons.GetCombinePathWithAdditionalRoots();
                }
                else if (categoryId == GalleryCategoryIDs.Advertise)
                {
                    location = Statics.UProcessorAdvertiseImages.GetCombinePathWithAdditionalRoots();
                }
                else if (categoryId == GalleryCategoryIDs.YoutubeCoverImage)
                {
                    location = Statics.UProcessorYoutubeCover.GetCombinePathWithAdditionalRoots();
                }
            }

            if (gallery != null)
            {
                var fileName = UploadProcessor.GetOrganizeNameStatic(gallery, true);
                return(AppVar.Url + location + fileName);
            }

            return(null);
        }
Beispiel #3
0
        public async Task <JsonResult> UploadGallery(App app, IEnumerable <HttpPostedFileBase> galleries)
        {
            if (galleries != null && app.UploadGuid != null)
            {
                //look for cache if sequence exist before
                var nextSequence = GetSequenceNumber(app.UploadGuid);
                var nextCount    = GetHowManyGalleryImageExist(app.UploadGuid);

                if (nextCount > AppVar.Setting.GalleryMaxPictures)
                {
                    ResetSessionForUploadSequence(app.UploadGuid);
                    return(Json(new { isUploaded = false, uploadedFiles = 0, message = "You are out of your limit." },
                                "text/html"));
                }
                var fileName  = app.UploadGuid.ToString();
                var firstTime = true;
                var countDone = 0;
                foreach (var file in galleries)
                {
                    if (file.ContentLength > 0)
                    {
                        // first save gallery and temp record.

                        if (!firstTime)
                        {
                            nextSequence = GetSequenceNumber(app.UploadGuid);
                            nextCount    = GetHowManyGalleryImageExist(app.UploadGuid);
                            if (nextCount > AppVar.Setting.GalleryMaxPictures)
                            {
                                ResetSessionForUploadSequence(app.UploadGuid);
                                return
                                    (Json(
                                         new {
                                    isUploaded = true,
                                    uploadedFiles = countDone,
                                    message = "You are out of your limit."
                                }, "text/html"));
                            }
                        }
                        else
                        {
                            firstTime = false;
                        }

                        //upload app-details page gallery image
                        Statics.UProcessorGallery.UploadFile(file, fileName, nextSequence, true, true);

                        //successfully uploaded now save a gallery info
                        var galleryCategory = await db.GalleryCategories.FindAsync(GalleryCategoryIDs.AppPageGallery);

                        //var thumbsCategory = await db.GalleryCategories.FindAsync(GalleryCategoryIDs.GalleryIcon);
                        var gallery =
                            await
                            db.Galleries.FirstOrDefaultAsync(
                                n =>
                                n.UploadGuid == app.UploadGuid &&
                                n.GalleryCategoryID == galleryCategory.GalleryCategoryID &&
                                n.Sequence == nextSequence);

                        // saving in the database
                        if (gallery == null)
                        {
                            // we didn't get the error
                            // image sequence and guid is correct.
                            gallery            = new Gallery();
                            gallery.GalleryID  = Guid.NewGuid();
                            gallery.UploadGuid = app.UploadGuid;
                            if (!string.IsNullOrEmpty(app.AppName))
                            {
                                gallery.Title = app.AppName + "-" + nextSequence;
                            }
                            gallery.Extension         = UploadProcessor.GetExtension(file);
                            gallery.GalleryCategoryID = galleryCategory.GalleryCategoryID;
                            gallery.Sequence          = nextSequence;
                            db.Galleries.Add(gallery);
                            // try to add a temp record as well.
                            var tempUpload = new TempUpload();
                            tempUpload.TempUploadID = Guid.NewGuid();
                            tempUpload.UserID       = UserManager.GetLoggedUserId();
                            tempUpload.GalleryID    = gallery.GalleryID;
                            tempUpload.RelatingUploadGuidForDelete = app.UploadGuid;
                            db.TempUploads.Add(tempUpload);
                            await db.SaveChangesAsync();
                        }

                        // resize
                        //new Thread(() => {

                        // resize app-details page gallery image

                        Statics.UProcessorGallery.ResizeImageAndProcessImage(gallery, galleryCategory);
                        //var source = "~/Uploads/Images/" + Variables.ADDITIONAL_ROOT_GALLERY_LOCATION +
                        //             UploadProcessor.GetOrganizeNameStatic(gallery, true, true);
                        //var target = "~/Uploads/Images/" + Variables.ADDITIONAL_ROOT_GALLERY_ICON_LOCATION +
                        //             UploadProcessor.GetOrganizeNameStatic(gallery, true);

                        // #apps detail page gallery thumbs generate
                        //Statics.uProcessorGallery.ResizeImageAndProcessImage(source, target, thumbsCategory.Width,
                        //    thumbsCategory.Height, gallery.Extension);

                        var source = "~/Uploads/Images/" + Variables.AdditionalRootGalleryLocation +
                                     UploadProcessor.GetOrganizeNameStatic(gallery, true, true);
                        //removing temp image what was exact uploaded after resizing it.
                        if (FileSys.Exists(Statics.UProcessorGallery.VirtualPathtoAbsoluteServerPath(source)))
                        {
                            // if processed image exist then remove  the temp.
                            Statics.UProcessorGallery.RemoveTempImage(gallery);
                        }
                        countDone++;
                        //}).Start();
                    }
                }
                var countUploaded = galleries.Count();
                return
                    (Json(
                         new {
                    isUploaded = true,
                    uploadedFiles = countUploaded,
                    message = "+" + countUploaded + " files successfully done."
                }, "text/html"));
            }
            return(Json(new { isUploaded = false, uploadedFiles = 0, message = "No file send." }, "text/html"));
        }