Exemplo n.º 1
0
        public IActionResult Edit(long id)
        {
            var gallery          = galleryService.GetGallery(id);
            GalleryViewModel svm = new GalleryViewModel();

            svm.Name         = gallery.Name;
            svm.IsPublished  = gallery.IsPublished;
            svm.Id           = gallery.Id;
            svm.ModifiedBy   = gallery.ModifiedBy;
            svm.ModifiedDate = gallery.ModifiedDate;
            svm.AddedBy      = gallery.AddedBy;
            svm.AddedDate    = gallery.AddedDate;
            return(View(svm));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync()
        {
            Gallery gallery = await _galleryService.GetGallery(Id);

            if (gallery == null)
            {
                return(NotFound());
            }
            int pageSize   = 12; //每页展示的漫画个数
            int comicCount = await _comicService.GetComicCount(Id);

            int maxPage = (comicCount + 1) / 12 + 1;

            GalleryName = gallery.Name;
            Console.WriteLine(PageNumber);
            Comics = await _comicService.GetComics(gallery, PageNumber.GetValueOrDefault(1) - 1, pageSize);

            Pagination = new PaginationModel()
            {
                StartPage   = 1,
                EndPage     = maxPage,
                CurrentPage = PageNumber.GetValueOrDefault(1),
            };
            Pagination.CreatePaginationItems();
            Pagination.Route       = "/Read/Gallery1";
            Pagination.RouteParams = new Dictionary <string, string>();
            //{
            //    {"id",Id.ToString() },
            //};
            foreach (var kv in RouteData.Values)
            {
                Pagination.RouteParams.Add(kv.Key, kv.Value.ToString());
            }
            return(Page());
        }
 public async Task <ActionResult <GalleryDto> > Get()
 {
     return(await Execute("An error occurred trying to load the gallery.", async() =>
     {
         var result = await _galleryService.GetGallery();
         return Ok(result);
     }));
 }
Exemplo n.º 4
0
        public async Task WhenICallGalleryService_ToGetAll_ICallCorrectMethods()
        {
            _albumService.Setup(x => x.GetAlbums()).ReturnsAsync(MockAlbums());
            _photoService.Setup(x => x.GetPhotos()).ReturnsAsync(MockPhotos());
            _galleryService = new GalleryService(_albumService.Object, _photoService.Object);
            await _galleryService.GetGallery();

            _albumService.Verify(x => x.GetAlbums(), Times.Once);
            _photoService.Verify(x => x.GetPhotos(), Times.Once);
        }
Exemplo n.º 5
0
        public async Task WhenICallGalleryService_AndMapToPhotosAlbums_IGetCorrectPhotos()
        {
            _albumService.Setup(x => x.GetAlbums()).ReturnsAsync(MockAlbums());
            _photoService.Setup(x => x.GetPhotos()).ReturnsAsync(MockPhotos());
            _galleryService = new GalleryService(_albumService.Object, _photoService.Object);
            GalleryDto gallery = await _galleryService.GetGallery();

            Assert.AreEqual(1, gallery.Albums.Where(x => x.Id == 1).Select(p => p.Photos.Count).First());
            Assert.AreEqual(2, gallery.Albums.Where(x => x.Id == 2).Select(p => p.Photos.Count).First());
            Assert.AreEqual(1, gallery.Albums.Where(x => x.Id == 3).Select(p => p.Photos.Count).First());
        }
Exemplo n.º 6
0
        public async Task Scan()
        {
            Scanning = true;
            await SendScanStatus();

            DirectoryInfo  rootDir   = new DirectoryInfo(_options.Value.RootDir);
            List <Gallery> galleries = await _galleryService.GetAllGalleries();

            int maxIndex = 0;

            if (galleries.Count() != 0)
            {
                maxIndex = galleries.Select(g => g.Index).OrderByDescending(i => i).FirstOrDefault() + 1;
            }
            List <Gallery> newGalleries = new List <Gallery>();

            await SendMessage("开始扫描");

            foreach (var galleryDir in rootDir.GetDirectories())
            {
                if (galleryDir.Name.StartsWith(".") || galleryDir.Name.StartsWith("@"))
                {
                    continue;
                }
                if (await _galleryService.GetGallery(galleryDir.FullName) == null)
                {
                    Gallery newGallery = new Gallery
                    {
                        Name       = galleryDir.Name,
                        Index      = maxIndex,
                        DefaultDir = galleryDir.FullName
                    };
                    maxIndex++;
                    await SendMessage($"新增分类:{newGallery.Name}");

                    await _galleryService.AddGallery(newGallery);

                    newGalleries.Add(newGallery);
                }
            }
            galleries.AddRange(newGalleries);
            int newComicCount = 0;

            foreach (var gallery in galleries)
            {
                DirectoryInfo dir = new DirectoryInfo(gallery.DefaultDir);
                newComicCount += await scanComic(dir, gallery.Id);
            }
            await SendMessage($"扫描完毕,共增加{newGalleries.Count}个分类,{newComicCount}个漫画");

            Scanning = false;
            await SendScanStatus();
        }
Exemplo n.º 7
0
        public ActionResult Feed(string format, string galleryName)
        {
            var baseUri = Request.Url;

            var settings   = GalleryService.GetGallerySettings(galleryName);
            var gallery    = GalleryService.GetGallery(galleryName, true, User, null, "bydate");
            var galleryUrl = Url.Action("Show", "Gallery", new { galleryName });

            var contentFormat = "<img src=\"{0}\" />" + (settings.StatsEnabled ? "<div>Voted by {1} user(s), Uploaded by {2}</div>" : null);

            var items = from photo in gallery.Photos
                        let title = photo.Title ?? photo.Name
                                    let itemUri = new Uri(baseUri, galleryUrl + "#" + photo.GetHash())
                                                  let imageUri = new Uri(baseUri, Url.ThumbnailUrl(galleryName, photo.Name))
                                                                 let author = photo.User != null && settings.StatsEnabled ? Regex.Replace(photo.User, ".*\\\\(.*)|(.*)@.*", "$1$2") : "Anonymous" // remove domain / email
                                                                              let description = new TextSyndicationContent(string.Format(contentFormat, imageUri, photo.TotalVotes, author), TextSyndicationContentKind.Html)
                                                                                                select new SyndicationItem(title, description, itemUri, itemUri.ToString(), photo.Date)
            {
                Title   = new TextSyndicationContent(title),
                Summary = description,
                Authors = { new SyndicationPerson {
                                Name = author
                            } },
                PublishDate = photo.PublishDate
            };

            var gallerySummary = string.Format("Publish date: {0}, {1} vote(s), {2} photo(s) by {3} user(s)", gallery.PublishDate.ToShortDateString(), gallery.TotalVotes, gallery.Photos.Count(), gallery.TotalUsers);
            var galleryUri     = new Uri(baseUri, galleryUrl);
            var feed           = new SyndicationFeed(galleryName, gallerySummary, galleryUri, items)
            {
                Id              = galleryUri.ToString(),
                Title           = new TextSyndicationContent(galleryName),
                LastUpdatedTime = gallery.Date,
                Description     = new TextSyndicationContent(gallerySummary),
            };

            return(new SyndicationActionResult {
                Feed = feed, Format = format
            });
        }