Exemplo n.º 1
0
        public async Task <MyApplicationDetailsViewModel> GetMyApplicationDetails(string applicationId, string userId)
        {
            _logger.LogInformation($"Executing GetMyApplicationDetails with applicationId={applicationId}. (UserID: {userId})");

            var application = _context.Applications
                              .Include(x => x.JobPosition)
                              .Include(x => x.User)
                              .Include(x => x.ApplicationStages)
                              .FirstOrDefault(x => x.Id == applicationId);

            if (application == null)
            {
                _logger.LogError($"Application with ID:{applicationId} not found. (UserID: {userId})");
                throw new NotFoundException(_stringLocalizer["Application with ID:{0} not found.", applicationId]);
            }
            if (userId != application.UserId)
            {
                _logger.LogError($"User with ID:{userId} aren't owner of application with ID:{applicationId}. (UserID: {userId})");
                throw new PermissionException(_stringLocalizer["You aren't owner of application with ID:{0}.", applicationId]);
            }

            await _applicationsViewHistoriesService.AddApplicationsViewHistory(applicationId, userId);

            var vm = new MyApplicationDetailsViewModel()
            {
                Id               = application.Id,
                User             = _mapper.Map <ApplicationUser, UserDetailsViewModel>(application.User),
                JobPosition      = _mapper.Map <JobPosition, JobPositionViewModel>(application.JobPosition),
                CvFileUrl        = _cvStorageService.UriFor(application.CvFileName),
                CreatedAt        = application.CreatedAt.ToLocalTime(),
                ApplicationViews = await _context.ApplicationsViewHistories
                                   .Where(x => x.ApplicationId == application.Id && x.UserId != userId)
                                   .CountAsync(),
                ApplicationViewsAll = await _context.ApplicationsViewHistories
                                      .Where(x => x.ApplicationId == application.Id)
                                      .CountAsync(),
                ApplicationStages = application.ApplicationStages
                                    .OrderBy(x => x.Level).ToList(),
                //ConfirmedInterviewAppointment = _context.InterviewAppointments
                //                                            .Include(x => x.Interview)
                //                                                .ThenInclude(x => x.Application)
                //                                            .Where(x => x.Interview.Application.Id == application.Id).FirstOrDefault()
            };

            var confirmedInterviewAppointment = _context.InterviewAppointments
                                                .Include(x => x.Interview)
                                                .ThenInclude(x => x.Application)
                                                .Where(x => x.Interview.Application.Id == application.Id &&
                                                       x.InterviewAppointmentState == InterviewAppointmentState.Confirmed)
                                                .FirstOrDefault();

            if (confirmedInterviewAppointment != null)
            {
                confirmedInterviewAppointment.StartTime = confirmedInterviewAppointment.StartTime.ToLocalTime();
                confirmedInterviewAppointment.EndTime   = confirmedInterviewAppointment.EndTime.ToLocalTime();
                vm.ConfirmedInterviewAppointment        = confirmedInterviewAppointment;
            }

            return(vm);
        }
Exemplo n.º 2
0
        public async Task <ApplicationDetailsViewModel> GetViewModelForApplicationDetails(string applicationId, string userId)
        {
            _logger.LogInformation($"Executing GetViewModelForApplicationDetails with applicationId={applicationId}. (UserID: {userId})");

            var application = _context.Applications
                              .Include(x => x.JobPosition)
                              .Include(x => x.User)
                              .FirstOrDefault(x => x.Id == applicationId);

            if (application == null)
            {
                _logger.LogError($"Application with ID:{applicationId} not found. (UserID: {userId})");
                throw new NotFoundException(_stringLocalizer["Application with ID:{0} not found.", applicationId]);
            }

            await _applicationsViewHistoriesService.AddApplicationsViewHistory(applicationId, userId);

            var applicationStages = _context.ApplicationStages
                                    .Include(x => x.ResponsibleUser)
                                    .Include(x => x.AcceptedBy)
                                    .Where(x => x.ApplicationId == application.Id).OrderBy(x => x.Level);

            var viewHistories = await _context.ApplicationsViewHistories
                                .Where(x => x.ApplicationId == application.Id)
                                .OrderByDescending(x => x.ViewTime)
                                .Take(10)
                                .ToListAsync();

            foreach (var viewHistory in viewHistories)
            {
                viewHistory.ViewTime = viewHistory.ViewTime.ToLocalTime();
            }

            var vm = new ApplicationDetailsViewModel()
            {
                Id          = application.Id,
                User        = _mapper.Map <ApplicationUser, UserDetailsViewModel>(application.User),
                JobPosition = _mapper.Map <JobPosition, JobPositionViewModel>(application.JobPosition),
                CvFileUrl   = _cvStorageService.UriFor(application.CvFileName),
                CreatedAt   = application.CreatedAt.ToLocalTime(),
                ApplicationsViewHistories = viewHistories,
                ApplicationStages         = applicationStages.ToList()
            };

            return(vm);
        }