コード例 #1
0
 public async Task SaveAsync(ChapterDomain chapter)
 {
     await chapterDatabase.ReplaceOneAsync(c => c.ChapterId == chapter.ChapterId, chapter, new ReplaceOptions()
     {
         IsUpsert = true
     });
 }
コード例 #2
0
        public async Task <ChapterDomain> CreateAsync(ChapterDomain chapterDomain)
        {
            ChapterEntity chapterEntity        = Mapper.Map <ChapterEntity>(chapterDomain);
            EntityEntry <ChapterEntity> entity = await DbSet.AddAsync(chapterEntity);

            return(Mapper.Map <ChapterDomain>(entity.Entity));
        }
コード例 #3
0
        private static async Task <StripDomain> ExtractStripAsync(HtmlNode node, ChapterDomain chapter, IEnumerable <StripDomain> stripsInDatabase)
        {
            StringExtractor stringExtractor = new(node.OuterHtml);
            DateTimeOffset  publishDate     = DateTime.ParseExact(stringExtractor.Extract("title=\"", "\" name=\"", false).Replace("th,", "", StringComparison.InvariantCultureIgnoreCase).Replace("rd,", "", StringComparison.InvariantCultureIgnoreCase).Replace("nd,", "", StringComparison.InvariantCultureIgnoreCase).Replace("st,", "", StringComparison.InvariantCultureIgnoreCase), "MMMM d yyyy", new CultureInfo("en-US"));
            int             number          = int.Parse(node.Attributes["name"].Value, CultureInfo.InvariantCulture);
            string          title           = WebUtility.HtmlDecode(stringExtractor.Extract(" - ", "<", false));
            Uri             url             = new("https://megatokyo.com/strips/" + number.ToString("D4", CultureInfo.InvariantCulture));

            if (!stripsInDatabase.Where(s => s.Number == number).Any())
            {
                StripDomain strip = new(chapter.Category, number, title, url, publishDate);
                if (await GetFileTypeAsync(strip))
                {
                    return(strip);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
 public static ChaptersResult Create(ChapterDomain chapterDomain)
 {
     return(new ChaptersResult
     {
         ChapterId = chapterDomain.ChapterId,
         Name = chapterDomain.Name
     });
 }
        public ChaptersResult AddChapters(ChapterDomain chapterDomain)
        {
            var chapter = ChaptersResult.Create(chapterDomain);

            Chapters.Add(chapter);

            return(chapter);
        }
コード例 #6
0
        private async Task SendLocalisedStripNotificationsAsync(StripDomain strip)
        {
            StripDomain stripToNotify = await _stripManager.GetStripByNumberAsync(strip.Number);

            ChapterDomain chapter = await _mediator.Send(new GetChapterQuery(stripToNotify.Category));

            Dictionary <string, string> templateParams = new()
            {
コード例 #7
0
        public async Task <ChapterCreateResponse> CreateChapterAsync(ChapterCreateRequest request)
        {
            var chapter = await ChapterDomain.CreateAsync(request.Name);

            return(new ChapterCreateResponse
            {
                ChapterId = chapter.ChapterId
            });
        }
コード例 #8
0
        private async Task SetChapter(Guid chapterId)
        {
            var mmRepo = UtilDomain.GetService <IMaturityModelRepository>();

            var chapter = (await mmRepo.GetChaptersAsync(chapterId)).FirstOrDefault();

            if (chapter == null)
            {
                throw new ChapterMaturityModelNotFoundException(this, chapterId);
            }

            this.ChapterId = chapterId;
            this.Chapter   = chapter;
        }
コード例 #9
0
        public async Task <IActionResult> GetChapter(string category)
        {
            try
            {
                ChapterDomain ChapterData = await _mediator.Send(new GetChapterQuery(category));

                ChapterOutputDTO chapter = _mapper.Map <ChapterOutputDTO>(ChapterData);
                return(Ok(chapter));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch
            {
                throw;
            }
        }
コード例 #10
0
        public async Task <bool> ParseStripsAsync(ChaptersDomain chapters)
        {
            IEnumerable <StripDomain> stripsInDatabase = await _mediator.Send(new GetAllStripsQuery());

            List <StripDomain> strips = await StripsParser.ParseAsync(Url, chapters, stripsInDatabase);

            foreach (StripDomain strip in strips)
            {
                if (!stripsInDatabase.Where(s => s.Number == strip.Number).Any())
                {
                    ChapterDomain currentChapter = await _mediator.Send(new GetChapterQuery(strip.Category));

                    StripDomain newStrip = new(currentChapter.Category, strip.Number, strip.Title, strip.Url, strip.PublishDate);
                    await _mediator.Send(new CreateStripCommand(newStrip));
                }
            }
            await _mediator.Send(new SaveStripCommand());

            return(true);
        }