Esempio n. 1
0
        public async Task GetTranslations()
        {
            var logger = testConfig.GetLoggerFactory().CreateLogger <EventTranslationHandlers>();

            EventTranslationHandlers eventHandlers = new EventTranslationHandlers(testConfig.GetDbContext(), logger);
            EventTranslationQuery    query         = new EventTranslationQuery();
            IList <EventTranslation> res           = await eventHandlers.Handle(query, new CancellationToken());

            Assert.AreEqual(3, res.Count);

            EventTranslationQuery queryWithLanguageEvent = new EventTranslationQuery()
            {
                LanguageId = 1, EventId = 1
            };
            IList <EventTranslation> resWithLanguageEvent = await eventHandlers.Handle(queryWithLanguageEvent, new CancellationToken());

            Assert.AreEqual(1, resWithLanguageEvent.Count);
            Assert.AreEqual("Title en", resWithLanguageEvent.FirstOrDefault().Title);
            Assert.AreEqual("Name", resWithLanguageEvent.FirstOrDefault().Event.Name);

            EventTranslationQuery queryWithLanguage = new EventTranslationQuery()
            {
                LanguageId = 1
            };
            IList <EventTranslation> resWithLanguage = await eventHandlers.Handle(queryWithLanguage, new CancellationToken());

            Assert.AreEqual(2, resWithLanguage.Count);
        }
Esempio n. 2
0
        public async Task <IList <EventTranslation> > Handle(EventTranslationQuery query, CancellationToken cancellationToken)
        {
            IQueryable <EventTranslation> result = db.EventTranslations.Include(et => et.Event).ThenInclude(e => e.Image);

            if (query.LanguageId.HasValue && query.EventId.HasValue)
            {
                result = result.Where(e => e.EventId == query.EventId && e.LanguageId == query.LanguageId);
            }
            else if (query.LanguageId.HasValue)
            {
                result = result.Where(e => e.LanguageId == query.LanguageId);
            }
            else if (query.EventId.HasValue)
            {
                result = result.Where(e => e.EventId == query.EventId);
            }

            IList <EventTranslation> ets = await result.ToListAsync();

            return(ets);
        }
Esempio n. 3
0
        public async Task <IActionResult> GetTranslations(EventTranslationQuery query)
        {
            IEnumerable <EventTranslation> result = await mediatr.Send(query);

            return(Json(result));
        }