コード例 #1
0
        public async Task <TheaterPerformanceDTO> GetTheaterPerformance(int id)
        {
            TheaterPerformance theaterPerformance =
                await _theaterPerformanceRepository.GetTheaterPerformance(id);

            return(_mapper.Map <TheaterPerformanceDTO>(theaterPerformance));
        }
コード例 #2
0
        private async Task <IEnumerable <User> > GetUsersToSentEmail(TheaterPerformance theaterPerformance)
        {
            List <User> usersToSendEmails        = new List <User>();
            bool        needToSendEmail          = false;
            IEnumerable <UserAnswer> userAnswers = await _userAnswerRepository.GetUserAnswersWithVariants();

            IEnumerable <IGrouping <int, UserAnswer> > groupedUserAnswers =
                userAnswers.GroupBy(ans => ans.UserId);

            foreach (var key in groupedUserAnswers)
            {
                needToSendEmail = false;
                foreach (var ans in key)
                {
                    switch (ans.Variant.QuestionId)
                    {
                    case 1:
                        if (PerformanceGenreMapper.GetPerformanceGenre(ans.Variant.VariantText)
                            == theaterPerformance.Performance.PerformanceGenre)
                        {
                            needToSendEmail = true;
                        }
                        break;

                    case 2:
                        if (ans.Variant.VariantText.ToLower() == theaterPerformance.Performance.Author?.ToLower())
                        {
                            needToSendEmail = true;
                        }
                        break;

                    case 3:
                        if (ans.Variant.VariantText.ToLower() == theaterPerformance.Performance.Composer?.ToLower())
                        {
                            needToSendEmail = true;
                        }
                        break;

                    case 4:
                        if (TheaterTypeMapper.GetTheaterType(ans.Variant.VariantText)
                            == theaterPerformance.Theater.TheaterType)
                        {
                            needToSendEmail = true;
                        }
                        break;
                    }
                }
                if (needToSendEmail)
                {
                    usersToSendEmails.Add(_userRepository.Get(key.Key));
                }
            }



            return(usersToSendEmails);
        }
コード例 #3
0
        public async Task <AddAndUpdateTheaterPerformanceDTO> UpdateTheaterPerformance
            (int id, AddAndUpdateTheaterPerformanceDTO theaterPerformanceDTO)
        {
            TheaterPerformance theaterPerformance = _mapper.Map <TheaterPerformance>(theaterPerformanceDTO);

            theaterPerformance.Id = id;
            await _theaterPerformanceRepository.UpdateAsync(theaterPerformance);

            return(_mapper.Map <AddAndUpdateTheaterPerformanceDTO>(theaterPerformance));
        }
コード例 #4
0
        public async Task <bool> DeleteTheaterPerformance(int id)
        {
            TheaterPerformance tpToDelete = _theaterPerformanceRepository.Get(id);

            if (tpToDelete == null)
            {
                return(false);
            }
            _theaterPerformanceRepository.Delete(tpToDelete);
            _theaterPerformanceRepository.Save();
            return(true);
        }
コード例 #5
0
        public async Task <AddAndUpdateTheaterPerformanceDTO> AddTheaterPerformance
            (AddAndUpdateTheaterPerformanceDTO theaterPerformanceDTO)
        {
            TheaterPerformance theaterPerformance = _mapper.Map <TheaterPerformance>(theaterPerformanceDTO);

            _theaterPerformanceRepository.Insert(theaterPerformance);
            _theaterPerformanceRepository.Save();


            TheaterPerformance addedTheaterPerformance =
                await _theaterPerformanceRepository.GetTheaterPerformance(theaterPerformance.Id);

            IEnumerable <User> usersToSendEmail = await GetUsersToSentEmail(addedTheaterPerformance);

            await _emailService.SendNewPerformanceEmail(_mapper.Map <IEnumerable <UserDTO> >(usersToSendEmail),
                                                        _mapper.Map <TheaterPerformanceDTO>(addedTheaterPerformance));


            return(_mapper.Map <AddAndUpdateTheaterPerformanceDTO>(theaterPerformance));
        }