Exemplo n.º 1
0
        public ActionResult Edit(Gallery gallery)
        {
            var viewOf = ViewTapping(ViewStates.EditPost, gallery);

            if (gallery.File != null)
            {
                gallery.Extension = UploadProcessor.GetExtension(gallery.File);
            }
            if (ModelState.IsValid)
            {
                db.Entry(gallery).State = EntityState.Modified;
                var state = SaveDatabase(ViewStates.Edit, gallery);
                DoUpload(gallery);
                if (state)
                {
                    AppVar.SetSavedStatus(ViewBag, _editedSaved); // Saved Successfully.
                }
                else
                {
                    AppVar.SetErrorStatus(ViewBag, _editedError); // Failed to Save
                }

                return(RedirectToAction("Index"));
            }

            GetDropDowns(gallery);
            AppVar.SetErrorStatus(ViewBag, _editedError); // Failed to save
            return(View(gallery));
        }
Exemplo n.º 2
0
        public ActionResult Create(Gallery gallery)
        {
            var viewOf = ViewTapping(ViewStates.CreatePost, gallery);

            if (gallery.File != null)
            {
                gallery.Extension = UploadProcessor.GetExtension(gallery.File);
            }
            GetDropDowns(gallery);
            if (ModelState.IsValid)
            {
                gallery.GalleryID  = Guid.NewGuid();
                gallery.UploadGuid = gallery.GalleryID;
                db.Galleries.Add(gallery);
                var state = SaveDatabase(ViewStates.Create, gallery);
                DoUpload(gallery);
                if (state)
                {
                    AppVar.SetSavedStatus(ViewBag, _createdSaved); // Saved Successfully.
                }
                else
                {
                    AppVar.SetErrorStatus(ViewBag, _createdError); // Failed to save
                }

                return(View(gallery));
            }
            AppVar.SetErrorStatus(ViewBag, _createdError); // Failed to Save
            return(View(gallery));
        }
Exemplo n.º 3
0
        public JsonResult ProcessSingleUploads(App app, HttpPostedFileBase file, int galleryId,
                                               UploadProcessor uploadProcessorSepecific)
        {
            if (file != null && app.UploadGuid != null)
            {
                //look for cache if sequence exist before
                var fileName = app.UploadGuid.ToString();
                if (file.ContentLength > 0)
                {
                    // first save gallery and temp record.
                    //upload the image
                    uploadProcessorSepecific.UploadFile(file, fileName, 0, true, true);
                    //successfully uploaded now save a gallery info
                    var galleryCategory = db.GalleryCategories.Find(galleryId);
                    var gallery         =
                        db.Galleries.FirstOrDefault(
                            n =>
                            n.UploadGuid == app.UploadGuid &&
                            n.GalleryCategoryID == galleryCategory.GalleryCategoryID);
                    if (gallery == null)
                    {
                        gallery                   = new Gallery();
                        gallery.GalleryID         = Guid.NewGuid();
                        gallery.UploadGuid        = app.UploadGuid;
                        gallery.Title             = app.AppName;
                        gallery.Extension         = UploadProcessor.GetExtension(file);
                        gallery.GalleryCategoryID = galleryCategory.GalleryCategoryID;
                        gallery.Sequence          = 0;
                        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);
                        db.SaveChanges();
                    }
                    // resize
                    //new Thread(() => {

                    uploadProcessorSepecific.ResizeImageAndProcessImage(gallery, galleryCategory);
                    uploadProcessorSepecific.RemoveTempImage(gallery);
                    //}).Start();
                }
                return(Json(new { isUploaded = true, message = "successfully done" }, "text/html"));
            }
            return(Json(new { isUploaded = false, message = "No file send." }, "text/html"));
        }
Exemplo n.º 4
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"));
        }