Ejemplo n.º 1
0
        /// <summary>
        /// Get detail of JobApplication (as Student)
        /// </summary>
        /// <param name="jobApplicationId">JobApplication ID</param>
        /// <param name="userId">User ID</param>
        /// <returns>JobApplication DTO</returns>
        public async Task <JobApplicationWithJoRes> GetDetailStudentAsync(int jobApplicationId, int userId)
        {
            var jobApplication = await _context.JobApplications
                                 .Include(ja => ja.JobOffer).ThenInclude(jo => jo.Group)
                                 .Include(ja => ja.JobOffer).ThenInclude(jo => jo.Address)
                                 .FirstOrDefaultAsync(ja => ja.JobApplicationId == jobApplicationId);

            // jobApplication not found
            if (jobApplication == null)
            {
                return(null);
            }

            var user = await _context.Users
                       .FirstOrDefaultAsync(us => us.UserId == userId);

            // jobApplication does not belong to student
            if (jobApplication.StudentId != user.StudentId)
            {
                throw new AppLogicException("Přihláška napatří studentovi");
            }

            int freeSpaces = await _jobOfferService.GetFreeSpacesAsync(jobApplication.JobOfferId);

            return(new JobApplicationWithJoRes(jobApplication, freeSpaces));
        }