Exemple #1
0
        public override async Task <ContestRegistrationViewModel> HandleAsync(GetContestRegistrationForCreateQuery query)
        {
            var contest = await ReadRepository.Set <Contest>()
                          //.Include(x => x.ContestAreas).ThenInclude(y => y.Area)
                          .Include($"{nameof(Contest.ContestAreas)}.{nameof(ContestArea.Area)}")
                          .SingleOrDefaultAsync(m => m.Id == query.ContestId);

            if (contest == null)
            {
                throw new EntityNotFoundException();
            }

            var viewModel = CreateContestRegistrationViewModel(contest.ContestType);

            viewModel.ContestName                 = contest.Name;
            viewModel.ContestId                   = contest.Id;
            viewModel.ContestTrainerCont          = contest.TrainerCount;
            viewModel.ParticipantType             = contest.ParticipantType;
            viewModel.IsAreaRequired              = contest.IsAreaRequired;
            viewModel.IsProgrammingLanguageNeeded = contest.IsProgrammingLanguageNeeded;
            viewModel.IsOutOfCompetitionAllowed   = contest.IsOutOfCompetitionAllowed;
            viewModel.IsEnglishLanguage           = contest.IsEnglishLanguage;
            viewModel.ShowRegistrationInfo        = contest.ShowRegistrationInfo;

            var user = await _userManager.FindByEmailAsync(_currentUserService.Email);

            user.StudyPlace = await ReadRepository.FindAsync <StudyPlace>(user.StudyPlaceId);

            switch (user.UserType)
            {
            case UserType.Trainer:
                viewModel.TrainerId = user.Id;
                break;

            case UserType.Pupil:
                viewModel.Participant1Id = user.Id;
                break;

            case UserType.Student:
                if (contest.ParticipantType == ParticipantType.Pupil)
                {
                    viewModel.TrainerId = user.Id;
                }
                else
                {
                    viewModel.Participant1Id = user.Id;
                }
                break;
            }

            if (contest.ParticipantType == ParticipantType.Pupil && user.StudyPlace is School ||
                contest.ParticipantType == ParticipantType.Student && user.StudyPlace is Institution)
            {
                viewModel.StudyPlaceId = user.StudyPlaceId;
                viewModel.CityId       = user.StudyPlace.CityId;
            }

            return(viewModel);
        }
        public override async Task <TEntity> HandleAsync(GetEntityByIdQuery <TEntity, TKey> query)
        {
            if (query.IncludeProperties == null)
            {
                return(await ReadRepository.FindAsync <TEntity>(query.Id));
            }

            var items = ReadRepository.Set <TEntity>();

            foreach (var property in query.IncludeProperties)
            {
                items = items.Include(property);
            }

            return(await items.SingleOrDefaultAsync(x => /*x.Id == query.Id*/ x.Id.Equals(query.Id)));
        }