Example #1
0
        public ActionResult List(int page = 1)
        {
            if (page == 0)
            {
                return(RedirectToAction("PageNotFound", "Common"));
            }

            var model = new PublicInfoGalleryModel();

            model.ShowGallery = _gallerySettings.ShowGalleries;
            if (_gallerySettings.ShowGalleries)
            {
                var galleries = _galleryService.GetGalleryPages(page, _gallerySettings.ItemPerPage < 1 ? 1 : _gallerySettings.ItemPerPage);
                foreach (var gal in galleries)
                {
                    var alt = gal.GetLocalized(x => x.Description) != null?gal.GetLocalized(x => x.Description).Replace("<p>", "").Replace("</p>", "") : "";

                    model.ImageGallery.Add(new ImageGalleryModel
                    {
                        Id = gal.Id,
                        ImageGalleryPictureModel = new PictureModel
                        {
                            FullSizeImageUrl = _pictureService.GetPictureUrl(gal.PictureId),
                            ImageUrl         = _pictureService.GetPictureUrl(gal.PictureId, GalleryThumbPictureSize),
                            Title            = gal.GetLocalized(x => x.Name),
                            AlternateText    = alt,
                        }
                    });
                }

                if (_gallerySettings.ShowImageAfterGalleries)
                {
                    var count = Convert.ToInt32(Math.Ceiling(_galleryService.Counter(_gallerySettings.ItemPerPage < 1 ? 1 : _gallerySettings.ItemPerPage)));
                    if (page >= count)
                    {
                        if (count == page)
                        {
                            page = 1;
                        }
                        if (count < page)
                        {
                            page = page - count + 1;
                        }

                        model.ShowImages = true;
                        var imagesWithoutGallery = _galleryService.GetImagesPagesWithoutGallery(page, _gallerySettings.ItemPerPage < 1 ? 1 : _gallerySettings.ItemPerPage);
                        foreach (var image in imagesWithoutGallery)
                        {
                            var alt = image.GetLocalized(x => x.Description) != null?image.GetLocalized(x => x.Description).Replace("<p>", "").Replace("</p>", "") : "";

                            model.ImageModel.Add(new ImageModel
                            {
                                ShareImage = _gallerySettings.ShareImage,
                                Id         = image.Id,
                                ImageGalleryPictureModel = new PictureModel
                                {
                                    FullSizeImageUrl = _pictureService.GetPictureUrl(image.PictureId),
                                    ImageUrl         =
                                        _pictureService.GetPictureUrl(image.PictureId, GalleryThumbPictureSize),
                                    Title         = image.GetLocalized(x => x.Name),
                                    AlternateText = alt,
                                }
                            });
                        }
                    }

                    return(Json(new
                    {
                        success = true,
                        data = model,
                    }));
                    //return View("~/Plugins/Widgets.Gallery/Views/GalleryPublicInfo/GalleryWithAloneImages.cshtml", model);
                }

                return(Json(new
                {
                    success = true,
                    data = model,
                }));
                //return View("~/Plugins/Widgets.Gallery/Views/GalleryPublicInfo/GalleryList.cshtml", model);
            }

            var images = _galleryService.GetGalleryImagesPages(page, _gallerySettings.ItemPerPage < 1 ? 1 : _gallerySettings.ItemPerPage);

            foreach (var image in images)
            {
                var alt = image.GetLocalized(x => x.Description) != null?image.GetLocalized(x => x.Description).Replace("<p>", "").Replace("</p>", "") : "";

                model.ImageModel.Add(new ImageModel
                {
                    ShareImage = _gallerySettings.ShareImage,
                    Id         = image.Id,
                    ImageGalleryPictureModel = new PictureModel
                    {
                        FullSizeImageUrl = _pictureService.GetPictureUrl(image.PictureId),
                        ImageUrl         = _pictureService.GetPictureUrl(image.PictureId, GalleryThumbPictureSize),
                        Title            = image.GetLocalized(x => x.Name),
                        AlternateText    = alt,
                    }
                });
            }
            return(Json(new
            {
                success = true,
                data = model,
            }));
            //return View(_gallerySettings.SliderGallery ? "~/Plugins/Widgets.Gallery/Views/GalleryPublicInfo/GalleriaList.cshtml" : "~/Plugins/Widgets.Gallery/Views/GalleryPublicInfo/List.cshtml.cshtml", model);
        }