Ejemplo n.º 1
0
        //
        // GET: /Gallery/Edit/5

        public ActionResult Edit(int id)
        {
            DeleteTempGallery();

            // Get Gallery
            Gallery         gallery  = db.GallerySet.Find(id);
            string          path     = "";
            GalleryCategory category = gallery.Category;

            while (category != null)
            {
                path     = "/" + category.Title + path;
                category = category.Parent;
            }
            ViewBag.Path = path;

            // Get next imageId
            int imageId;

            try
            {
                imageId = gallery.Images.Select(e => e.ImageId).OrderByDescending(e => e).First() + 1;
            }
            catch (Exception)
            {
                imageId = 0;
            }

            ViewBag.NextImageId = imageId;

            return(View(gallery));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the gallery category with the name "categoryName", and with the parent "parent". If this category not exists, it will be created
        /// </summary>
        /// <param name="title"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        private GalleryCategory GetCategory(string[] pathArray, GalleryCategory parent = null, int level = 0)
        {
            GalleryCategory category;
            var             title = pathArray[level];

            if (parent == null)
            {
                category = db.GalleryCategorySet.Where(e => e.Parent == null && e.Title == title).FirstOrDefault();
            }
            else
            {
                category = parent.SubCategories.Where(e => e.Title == title).FirstOrDefault();
            }
            if (category == null)
            {
                category = new GalleryCategory {
                    Title = pathArray[level], Parent = parent
                };
                db.GalleryCategorySet.Add(category);
                if (parent != null)
                {
                    parent.SubCategories.Add(category);
                }
            }

            if (pathArray.Length > level + 1)
            {
                return(GetCategory(pathArray, category, level + 1));
            }

            return(category);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Always tap once before going into the view.
        /// </summary>
        /// <param name="ViewStates">Say the view state, where it is calling from.</param>
        /// <param name="GalleryCategory">Gives the model if it is a editing state or creating posting state or when deleting.</param>
        /// <returns>If successfully saved returns true or else false.</returns>
        private bool ViewTapping(ViewStates view, GalleryCategory galleryCategory = null)
        {
            switch (view)
            {
            case ViewStates.Index:
                break;

            case ViewStates.Create:
                break;

            case ViewStates.CreatePost:     // before saving it
                break;

            case ViewStates.Edit:
                break;

            case ViewStates.Details:
                break;

            case ViewStates.EditPost:     // before saving it
                break;

            case ViewStates.Delete:
                break;
            }
            return(true);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Better approach to save things into database(than db.SaveChanges()) for this controller.
        /// </summary>
        /// <param name="ViewStates">Say the view state, where it is calling from.</param>
        /// <param name="GalleryCategory">Your model information to send in email to developer when failed to save.</param>
        /// <returns>If successfully saved returns true or else false.</returns>
        private bool SaveDatabase(ViewStates view, GalleryCategory galleryCategory = null)
        {
            // working those at HttpPost time.
            switch (view)
            {
            case ViewStates.Create:
                break;

            case ViewStates.Edit:
                break;

            case ViewStates.Delete:
                break;
            }

            try {
                var changes = db.SaveChanges(galleryCategory);
                if (changes > 0)
                {
                    return(true);
                }
            } catch (Exception ex) {
                throw new Exception("Message : " + ex.Message + " Inner Message : " + ex.InnerException.Message);
            }
            return(false);
        }
Ejemplo n.º 5
0
        public async Task <IEnumerable <GalleryInfo> > SearchGalleries(GalleryCategory categoriesForSearch = GalleryCategory.All,
                                                                       string searchString = "")
        {
            var dic = new Dictionary <string, string>();

            dic.Add("f_doujinshi", (categoriesForSearch.HasFlag(GalleryCategory.Doujinshi) ? 1 : 0).ToString());
            dic.Add("f_manga", (categoriesForSearch.HasFlag(GalleryCategory.Manga) ? 1 : 0).ToString());
            dic.Add("f_artistcg", (categoriesForSearch.HasFlag(GalleryCategory.ArtistCgSets) ? 1 : 0).ToString());
            dic.Add("f_gamecg", (categoriesForSearch.HasFlag(GalleryCategory.GameCgSets) ? 1 : 0).ToString());
            dic.Add("f_western", (categoriesForSearch.HasFlag(GalleryCategory.Western) ? 1 : 0).ToString());
            dic.Add("f_non-h", (categoriesForSearch.HasFlag(GalleryCategory.NonH) ? 1 : 0).ToString());
            dic.Add("f_imageset", (categoriesForSearch.HasFlag(GalleryCategory.ImageSets) ? 1 : 0).ToString());
            dic.Add("f_cosplay", (categoriesForSearch.HasFlag(GalleryCategory.Cosplay) ? 1 : 0).ToString());
            dic.Add("f_asianporn", (categoriesForSearch.HasFlag(GalleryCategory.AsianPorn) ? 1 : 0).ToString());
            dic.Add("f_misc", (categoriesForSearch.HasFlag(GalleryCategory.Misc) ? 1 : 0).ToString());

            dic.Add("f_search", searchString);
            dic.Add("f_apply", "Apply+Filter");

            var result = await EHentaiRequest(String.Empty, RequestType.Get, dic);

            IEnumerable <GalleryInfo> gals = ParseGalleries(result);

            return(gals);
        }
Ejemplo n.º 6
0
        public int SaveGalleryCategory(string CategoryTitle)
        {
            GalleryCategory gc = db.GalleryCategories.FirstOrDefault(c => c.Title == CategoryTitle);

            if (gc == null)
            {
                gc       = new GalleryCategory();
                gc.Title = CategoryTitle;
                db.GalleryCategories.InsertOnSubmit(gc);
                db.SubmitChanges();
            }

            return(gc.GalleryCategoryID);
        }
Ejemplo n.º 7
0
        public void SaveCategoryCollection(int categoryID, string[] galleries)
        {
            GalleryCategory gc = db.GalleryCategories.FirstOrDefault(cat => cat.GalleryCategoryID == categoryID);

            if (gc != null)
            {
                foreach (string s in galleries)
                {
                    if (s.Contains("Gallery") && !s.Contains("GalleryCategoryID"))
                    {
                        int     galleryid = int.Parse(s.Replace("Gallery", ""));
                        Gallery g         = db.Galleries.FirstOrDefault(gl => gl.GalleryID == galleryid);
                        g.GalleryCategoryID = categoryID;
                        db.SubmitChanges();
                    }
                }
            }
        }
        public IActionResult AddGallery(AddGalleryImageViewModel model)
        {
            if (!ModelState.IsValid)
            {
                ViewData["GeneralError"] = Messages.RequiredInput;
                ViewData["Categories"]   = (List <CategoryImage>)(_categoryImageService.GetAll()).Data.Where(x => x.IsActive);
                return(View(model));
            }

            var source = _galleryService.UploadGalleryImage(model.File, ImageSavePaths.GallerySavePath);

            if (source.Success)
            {
                GalleryImage galleryImage = new GalleryImage();
                galleryImage.Source      = source.Data;
                galleryImage.Description = model.Description;

                var image = _galleryService.Add(galleryImage);

                if (image.Success)
                {
                    foreach (var categoryId in model.CategoriesId)
                    {
                        GalleryCategory galleryCategory = new GalleryCategory();

                        galleryCategory.GalleryImageId  = galleryImage.Id;
                        galleryCategory.CategoryImageId = categoryId;

                        _galleryCategoryService.Add(galleryCategory);
                    }
                    ViewData["GeneralSuccess"] = image.Message;
                    return(RedirectToAction("ListGallery", "ManagementPanel"));
                }

                _galleryService.Delete(galleryImage);
            }

            _galleryService.DeleteGalleryImage(source.Data);
            ViewData["GeneralError"] = Messages.GeneralError;
            ViewData["Categories"]   = (List <CategoryImage>)(_categoryImageService.GetAll()).Data;
            return(View(model));
        }
Ejemplo n.º 9
0
            public ViewModel(Models.GalleryCategory category)
            {
                // check for admin preview
                if (Web.Request["preview"] == "adminonly")
                {
                    // force login if not already
                    if (!Security.IsLoggedIn)
                    {
                        throw new Beweb.ProgrammingErrorException("force login required");
                    }
                }
                else if (!category.GetIsActive())
                {
                    throw new Beweb.BadUrlException("Category not available with ID of [" + category.ID + "]");
                }
                Category     = category;
                PageTitleTag = category.Title;
                //category.CheckUserAccess();           // uncomment this if using page user access control

                TrackingBreadcrumb.Current.AddBreadcrumb(2, category.Title);
            }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="categoriesForSearch">NotSupported</param>
        /// <param name="searchString"></param>
        /// <returns></returns>
        public async Task <IEnumerable <GalleryInfo> > SearchGalleries(GalleryCategory categoriesForSearch = GalleryCategory.All,
                                                                       string searchString = "")
        {
            List <ViewerGallery> searchResult;

            using (var db = new LocalDbSourceContext())
            {
                var request =
                    db.ViewerGallery.Where(
                        g => (g.Title ?? String.Empty).IndexOf(searchString, StringComparison.OrdinalIgnoreCase) >= 0);

                searchResult = await request.Take(20).ToListAsync();
            }

            return(searchResult.Select(viewerGallery => new GalleryInfo
            {
                FullName = viewerGallery.Title,
                Id = Convert.ToInt32(viewerGallery.Gid),
                Source = Source.LocalDb,
            }).ToList());
        }
Ejemplo n.º 11
0
        public ActionResult Create(GalleryCategory galleryCategory)
        {
            var viewOf = ViewTapping(ViewStates.CreatePost, galleryCategory);

            GetDropDowns(galleryCategory);
            if (ModelState.IsValid)
            {
                db.GalleryCategories.Add(galleryCategory);
                var state = SaveDatabase(ViewStates.Create, galleryCategory);
                if (state)
                {
                    AppVar.SetSavedStatus(ViewBag, _createdSaved); // Saved Successfully.
                }
                else
                {
                    AppVar.SetErrorStatus(ViewBag, _createdError); // Failed to save
                }

                return(View(galleryCategory));
            }
            AppVar.SetErrorStatus(ViewBag, _createdError); // Failed to Save
            return(View(galleryCategory));
        }
Ejemplo n.º 12
0
        public ActionResult Edit(GalleryCategory galleryCategory)
        {
            var viewOf = ViewTapping(ViewStates.EditPost, galleryCategory);

            if (ModelState.IsValid)
            {
                db.Entry(galleryCategory).State = EntityState.Modified;
                var state = SaveDatabase(ViewStates.Edit, galleryCategory);
                if (state)
                {
                    AppVar.SetSavedStatus(ViewBag, _editedSaved); // Saved Successfully.
                }
                else
                {
                    AppVar.SetErrorStatus(ViewBag, _editedError); // Failed to Save
                }

                return(RedirectToAction("Index"));
            }

            GetDropDowns(galleryCategory);
            AppVar.SetErrorStatus(ViewBag, _editedError); // Failed to save
            return(View(galleryCategory));
        }
 public IResult Add(GalleryCategory galleryCategory)
 {
     _galleryCategoryDal.Add(galleryCategory);
     return(new SuccessResult());
 }
 public IResult Update(GalleryCategory galleryCategory)
 {
     _galleryCategoryDal.Update(galleryCategory);
     return(new SuccessResult());
 }
Ejemplo n.º 15
0
 public void GetDropDowns(GalleryCategory galleryCategory = null)
 {
 }
        public IActionResult UpdateGallery(UpdateGalleryPageModel model)
        {
            var data = _galleryService.GetById(model.Id);

            if (!ModelState.IsValid)
            {
                ViewData["GeneralError"] = Messages.GeneralError;
                var selectBox = GetCategoryImageSelectBoxView(data.Data);

                ViewData["AllCategories"] = selectBox;
                return(View(model));
            }

            string oldImage = data.Data.Source;

            data.Data.Description = model.Description;

            if (model.File != null)
            {
                var source = _galleryService.UploadGalleryImage(model.File, ImageSavePaths.GallerySavePath);
                if (source.Success)
                {
                    data.Data.Source = source.Data;
                    var result = _galleryService.Update(data.Data, oldImage);

                    if (result.Success)
                    {
                        bool isSuccess     = true;
                        var  oldCategories = _galleryCategoryService.GetGalleryId(data.Data.Id);

                        foreach (var oldCat in oldCategories.Data)
                        {
                            var res = _galleryCategoryService.Delete(oldCat);
                            isSuccess = res.Success;
                            if (!isSuccess)
                            {
                                break;
                            }
                        }

                        if (!isSuccess)
                        {
                            foreach (var oldCat in oldCategories.Data)
                            {
                                _galleryCategoryService.Add(oldCat);
                            }
                        }
                        else
                        {
                            foreach (var newCat in model.CategoriesId)
                            {
                                GalleryCategory galleryCategory = new GalleryCategory();
                                galleryCategory.GalleryImageId  = model.Id;
                                galleryCategory.CategoryImageId = newCat;
                                _galleryCategoryService.Add(galleryCategory);
                            }
                        }

                        ViewData["GeneralSuccess"] = result.Message;
                        return(RedirectToAction("ListGallery", "ManagementPanel"));
                    }
                }
            }
            else
            {
                var result = _galleryService.Update(data.Data, "");
                if (result.Success)
                {
                    bool isSuccess     = true;
                    var  oldCategories = _galleryCategoryService.GetGalleryId(data.Data.Id);

                    foreach (var oldCat in oldCategories.Data)
                    {
                        var res = _galleryCategoryService.Delete(oldCat);
                        isSuccess = res.Success;
                        if (!isSuccess)
                        {
                            break;
                        }
                    }

                    if (!isSuccess)
                    {
                        foreach (var oldCat in oldCategories.Data)
                        {
                            _galleryCategoryService.Add(oldCat);
                        }
                    }
                    else
                    {
                        foreach (var newCat in model.CategoriesId)
                        {
                            GalleryCategory galleryCategory = new GalleryCategory();
                            galleryCategory.GalleryImageId  = model.Id;
                            galleryCategory.CategoryImageId = newCat;
                            _galleryCategoryService.Add(galleryCategory);
                        }
                    }
                    ViewData["GeneralSuccess"] = result.Message;
                    return(RedirectToAction("ListGallery", "ManagementPanel"));
                }
            }


            ViewData["GeneralError"] = Messages.GeneralError;
            return(RedirectToAction("ListGallery", "ManagementPanel"));
        }
Ejemplo n.º 17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="categoriesForSearch">Not supported</param>
 /// <param name="searchString"></param>
 /// <returns></returns>
 public async Task <IEnumerable <GalleryInfo> > SearchGalleries(GalleryCategory categoriesForSearch = GalleryCategory.All, string searchString = "")
 {
     return(await SearchGalleries(searchString));
 }