public async ValueTask Load(MangasContext context, int pageId)
        {
            var page = await context.Pages.FirstAsync(p => p.Id == pageId);

            Order     = page.Order;
            Image     = page.Image;
            ChapterId = page.ChapterId;
        }
        public async ValueTask Update(MangasContext context, int tagId)
        {
            var tag = await context.Tags.FirstAsync(t => t.Id == tagId);

            if (Name != null)
            {
                tag.Name = Name;
            }
        }
        public async ValueTask Create(MangasContext context)
        {
            var author = new Author
            {
                Name = Name
            };

            await context.Authors.AddAsync(author);
        }
        public async ValueTask Create(MangasContext context)
        {
            var translator = new Translator
            {
                Name = Name
            };

            await context.Translators.AddAsync(translator);
        }
        public async ValueTask Update(MangasContext context, int typeId)
        {
            var type = await context.Types.FirstAsync(t => t.Id == typeId);

            if (Name != null)
            {
                type.Name = Name;
            }
        }
        public async ValueTask Load(MangasContext context, int chapterId)
        {
            var chapter = await context.Chapters.FirstAsync(ch => ch.Id == chapterId);

            Title      = chapter.Title;
            Order      = chapter.Order;
            UploadDate = chapter.UploadDate;
            MangaId    = chapter.MangaId;
        }
Ejemplo n.º 7
0
        public async ValueTask Update(MangasContext context, int authorId)
        {
            var author = await context.Authors.FirstAsync(t => t.Id == authorId);

            if (Name != null)
            {
                author.Name = Name;
            }
        }
 public async ValueTask Load(MangasContext context, int offset, int limit)
 {
     Types = await context.Types
             .AsNoTracking()
             .Skip(offset)
             .Take(limit)
             .Select(type => new ReadTypeItemResponse(type))
             .ToListAsync();
 }
Ejemplo n.º 9
0
        public async ValueTask Delete(MangasContext context)
        {
            var manga = await context.Mangas
                        .Include(m => m.Tags)
                        .FirstAsync(m => m.Id == MangaId);

            context.Mangas.Remove(manga);
            context.MangaTags.RemoveRange(manga.Tags);
        }
        public async ValueTask Update(MangasContext context, int translatorId)
        {
            var translator = await context.Translators.FirstAsync(t => t.Id == translatorId);

            if (Name != null)
            {
                translator.Name = Name;
            }
        }
Ejemplo n.º 11
0
        public async ValueTask Delete(MangasContext context)
        {
            var chapter = await context.Chapters
                          .Include(ch => ch.Pages)
                          .FirstAsync(ch => ch.Id == ChapterId);

            context.Chapters.Remove(chapter);
            context.Pages.RemoveRange(chapter.Pages);
        }
Ejemplo n.º 12
0
        public async ValueTask Create(MangasContext context)
        {
            var tag = new Tag
            {
                Name = Name
            };

            await context.Tags.AddAsync(tag);
        }
        public async ValueTask Create(MangasContext context)
        {
            var type = new Type
            {
                Name = Name
            };

            await context.Types.AddAsync(type);
        }
 public async ValueTask Load(MangasContext context, int offset, int limit)
 {
     Authors = await context.Authors
               .AsNoTracking()
               .OrderBy(a => a.Name)
               .Skip(offset)
               .Take(limit)
               .Select(author => new ReadAuthorItemRequest(author))
               .ToListAsync();
 }
 public async ValueTask Load(MangasContext context, int chapterId, int offset, int limit)
 {
     Pages = await context.Pages
             .Where(p => p.ChapterId == chapterId)
             .OrderBy(page => page.Order)
             .Skip(offset)
             .Take(limit)
             .Select(page => new ReadPageItemResponse(page))
             .ToListAsync();
 }
Ejemplo n.º 16
0
 public async ValueTask Load(MangasContext context, int mangaId, int offset, int limit)
 {
     Chapters = await context.Chapters
                .Where(ch => ch.MangaId == mangaId)
                .OrderBy(chapter => chapter.Order)
                .Skip(offset)
                .Take(limit)
                .Select(chapter => new ReadChapterItemResponse(chapter))
                .ToListAsync();
 }
 public async ValueTask Read(MangasContext context, int offset, int limit)
 {
     Translators = await context.Translators
                   .AsNoTracking()
                   .OrderBy(t => t.Name)
                   .Skip(offset)
                   .Take(limit)
                   .Select(t => new ReadTranslatorItemResponse(t))
                   .ToListAsync();
 }
Ejemplo n.º 18
0
        public async ValueTask ReadById(MangasContext context, int mangaId)
        {
            var manga = await context.Mangas
                        .Include(m => m.Type)
                        .FirstAsync(m => m.Id == mangaId);

            Title       = manga.Title;
            Description = manga.Description;
            Image       = manga.Image;
            Type        = new ReadTypeItemResponse(manga.Type);
        }
 public async ValueTask Read(MangasContext context, int mangaId, int offset, int limit)
 {
     Translators = await context.MangaTranslators
                   .AsNoTracking()
                   .Where(ma => ma.MangaId == mangaId)
                   .Select(ma => ma.Translator)
                   .OrderBy(a => a.Name)
                   .Skip(offset)
                   .Take(limit)
                   .Select(translator => new ReadTranslatorsByIdItemResponse(translator))
                   .ToListAsync();
 }
        public async ValueTask Create(MangasContext context, int chapterId)
        {
            var chapter = await context.Chapters.FirstAsync(ch => ch.Id == chapterId);

            var page = new Page
            {
                Order   = Order,
                Chapter = chapter,
                Image   = Image
            };

            await context.Pages.AddAsync(page);
        }
        public async ValueTask Read(MangasContext context, int mangaId, int offset, int limit)
        {
            var manga = await context.Mangas.FirstAsync(m => m.Id == mangaId);

            Authors = await context.MangaAuthors
                      .AsNoTracking()
                      .Where(ma => ma.Manga == manga)
                      .Select(ma => ma.Author)
                      .OrderBy(a => a.Name)
                      .Skip(offset)
                      .Take(limit)
                      .Select(a => new ReadAuthorsByIdItemResponse(a))
                      .ToListAsync();
        }
        public async ValueTask Update(MangasContext context, int pageId)
        {
            var page = await context.Pages.FirstAsync(p => p.Id == pageId);

            if (Order != null)
            {
                page.Order = Order.Value;
            }

            if (Image != null)
            {
                page.Image = Image;
            }
        }
        public async ValueTask Create(MangasContext context, int mangaId)
        {
            var manga = await context.Mangas.FirstAsync(m => m.Id == mangaId);

            var chapter = new Chapter
            {
                Title      = Title,
                Order      = Order,
                UploadDate = UploadDate,
                Manga      = manga
            };

            await context.Chapters.AddAsync(chapter);
        }
Ejemplo n.º 24
0
        public async ValueTask Update(MangasContext context, int chapterId)
        {
            var chapter = await context.Chapters.FirstAsync(ch => ch.Id == chapterId);

            if (Title != null)
            {
                chapter.Title = Title;
            }

            if (Order != null)
            {
                chapter.Order = Order.Value;
            }

            if (UploadDate != null)
            {
                chapter.UploadDate = UploadDate.Value;
            }
        }
Ejemplo n.º 25
0
        public async ValueTask Create(MangasContext context)
        {
            var type = await context.Types
                       .FirstAsync(t => t.Id == Type.Id);

            var tagsIds = Tags.Select(t => t.Id).ToList();

            var tags = await context.Tags
                       .Where(tag => tagsIds.Contains(tag.Id))
                       .ToListAsync();

            var translatorsIds = Translators.Select(t => t.Id).ToList();

            var translators = await context.Translators
                              .Where(translator => translatorsIds.Contains(translator.Id))
                              .ToListAsync();

            var authorsIds = Authors.Select(a => a.Id).ToList();

            var authors = await context.Authors
                          .Where(author => authorsIds.Contains(author.Id))
                          .ToListAsync();

            var manga = new Manga
            {
                Title       = Title,
                Description = Description,
                Image       = Image,
                Type        = type
            };

            await context.MangaTags
            .AddRangeAsync(tags.Select(tag => new MangaTag(tag, manga)));

            await context.MangaTranslators
            .AddRangeAsync(translators.Select(translator => new MangaTranslator(translator, manga)));

            await context.MangaAuthors
            .AddRangeAsync(authors.Select(author => new MangaAuthor(author, manga)));

            await context.Mangas.AddAsync(manga);
        }
        public async ValueTask Read(MangasContext context,
                                    int accountId,
                                    int?mangaId,
                                    int?chapterId,
                                    int?pageId,
                                    int offset,
                                    int limit)
        {
            var bookmarks = context.Bookmarks
                            .AsNoTracking()
                            .Where(b => b.AccountId == accountId);

            if (mangaId != null)
            {
                var manga = await context.Mangas.FirstAsync(m => m.Id == mangaId);

                bookmarks = bookmarks.Where(b => b.Manga == manga);
            }

            if (chapterId != null)
            {
                var chapter = await context.Chapters.FirstAsync(ch => ch.Id == chapterId);

                bookmarks = bookmarks.Where(b => b.Chapter == chapter);
            }

            if (pageId != null)
            {
                var page = await context.Pages.FirstAsync(p => p.Id == pageId);

                bookmarks = bookmarks.Where(b => b.Page == page);
            }

            Bookmarks = await bookmarks
                        .OrderByDescending(b => b.Created)
                        .Skip(offset)
                        .Take(limit)
                        .Select(bookmark => new ReadBookmarkItemResponse(bookmark))
                        .ToListAsync();
        }
Ejemplo n.º 27
0
        public async ValueTask Load(MangasContext context, FilterByMangaRequest filter)
        {
            var query = context.Mangas.AsNoTracking();

            if (filter.Title != null)
            {
                query = query.Where(m => m.Title.Contains(filter.Title));
            }

            if (filter.Tags != null)
            {
                query = query.Include(m => m.Tags)
                        .Where(m => m.Tags.Any(t => filter.Tags.Contains(t.TagId)));
            }

            Mangas = await query
                     .OrderByDescending(m => m.Id)
                     .Skip(filter.Offset)
                     .Take(filter.Limit)
                     .Select(manga => new ReadMangaItemResponse(manga))
                     .ToListAsync();
        }
Ejemplo n.º 28
0
        public async ValueTask Create(MangasContext context, int accountId)
        {
            var manga = await context.Mangas.FirstAsync(m => m.Id == MangaId);

            var chapter = ChapterId == null
                                ? null
                                : await context.Chapters.FirstAsync(ch => ch.Id == ChapterId);

            var page = PageId == null
                                ? null
                                : await context.Pages.FirstAsync(p => p.Id == PageId);

            var bookmark = new Bookmark
            {
                Name      = Name,
                AccountId = accountId,
                Created   = DateTime.UtcNow,
                Manga     = manga,
                Chapter   = chapter,
                Page      = page
            };

            await context.Bookmarks.AddAsync(bookmark);
        }
        public async ValueTask Update(MangasContext context, int mangaId)
        {
            var manga = await context.Mangas
                        .Include(m => m.Tags)
                        .Include(m => m.Translators)
                        .Include(m => m.Authors)
                        .FirstAsync(m => m.Id == mangaId);

            if (Title != null)
            {
                manga.Title = Title;
            }

            if (Description != null)
            {
                manga.Description = Description;
            }

            if (Type != null)
            {
                var type = await context.Types.FirstAsync(t => t.Id == Type.Id);

                manga.Type = type;
            }

            if (Tags != null)
            {
                var modelTagIds = Tags.Select(t => t.Id).ToList();
                var mangaTagIds = manga.Tags.Select(t => t.Tag.Id).ToList();

                var mangaTagsToRemove = mangaTagIds.Except(modelTagIds)
                                        .Select(tagId => manga.Tags.First(t => t.Tag.Id == tagId))
                                        .ToList();

                var mangaTagsToAdd = modelTagIds.Except(mangaTagIds)
                                     .Select(tagId => context.Tags.First(t => t.Id == tagId))
                                     .Select(tag => new MangaTag(tag, manga))
                                     .ToList();

                context.MangaTags.RemoveRange(mangaTagsToRemove);
                await context.MangaTags.AddRangeAsync(mangaTagsToAdd);
            }

            if (Translators != null)
            {
                var modelTranslatorIds = Translators.Select(t => t.Id).ToList();
                var mangaTranslatorIds = manga.Translators.Select(t => t.Translator.Id).ToList();

                var mangaTranslatorsToRemove = mangaTranslatorIds.Except(modelTranslatorIds)
                                               .Select(translatorId => manga.Translators.First(t => t.Translator.Id == translatorId))
                                               .ToList();

                var mangaTranslatorsToAdd = modelTranslatorIds.Except(mangaTranslatorIds)
                                            .Select(translatorId => context.Translators.First(t => t.Id == translatorId))
                                            .Select(translator => new MangaTranslator(translator, manga))
                                            .ToList();

                context.MangaTranslators.RemoveRange(mangaTranslatorsToRemove);
                await context.MangaTranslators.AddRangeAsync(mangaTranslatorsToAdd);
            }

            if (Authors != null)
            {
                var modelAuthorIds = Authors.Select(t => t.Id).ToList();
                var mangaAuthorIds = manga.Authors.Select(t => t.Author.Id).ToList();

                var mangaAuthorsToRemove = mangaAuthorIds.Except(modelAuthorIds)
                                           .Select(authorId => manga.Authors.First(t => t.Author.Id == authorId))
                                           .ToList();

                var mangaAuthorsToAdd = modelAuthorIds.Except(mangaAuthorIds)
                                        .Select(authorId => context.Authors.First(t => t.Id == authorId))
                                        .Select(author => new MangaAuthor(author, manga))
                                        .ToList();

                context.MangaAuthors.RemoveRange(mangaAuthorsToRemove);
                await context.MangaAuthors.AddRangeAsync(mangaAuthorsToAdd);
            }
        }
Ejemplo n.º 30
0
 public PagesController(MangasContext context)
 {
     this.context = context;
 }