示例#1
0
        public async Task <ActionResult <RecruiterDTO> > PutRecruiter(long companyId, string userId)
        {
            User user = await userManager.FindByIdAsync(userId);

            Company company = await _context.Companies.FindAsync(companyId);

            if (user == null)
            {
                return(NotFound("User does not exist"));
            }

            if (company == null)
            {
                return(NotFound("Company does not exist"));
            }

            Recruiter recruiter = new Recruiter()
            {
                CompanyId = company.CompanyId,
                UserId    = user.Id
            };

            _context.Recruiters.Add(recruiter);
            await _context.SaveChangesAsync();

            await userManager.AddToRoleAsync(user, UserRoles.Recruiter);

            return(CreatedAtAction("PutRecruiter", new { recruiter.UserId, recruiter.CompanyId }, await RecruiterToDTO(recruiter)));
        }
示例#2
0
        public async Task <ActionResult <ResumeDTO> > DeleteResume(long id)
        {
            User user = await userManager.FindByNameAsync(User.Identity.Name);

            Resume resume = null;

            // Admin can delete any resume by ID, user can only delete their own resumes
            if (await userManager.IsInRoleAsync(user, UserRoles.Admin))
            {
                resume = await _context.Resumes.FindAsync(id);
            }
            else
            {
                resume = _context.Resumes.Where(r => r.ResumeId == id && r.CandidateId == user.Id).FirstOrDefault();
            }

            if (resume == null)
            {
                return(NotFound());
            }

            _context.Resumes.Remove(resume);
            await _context.SaveChangesAsync();

            return(Ok(ResumeToDTO(resume)));
        }
示例#3
0
        public async Task <ActionResult> DeleteInterview(long applicationId)
        {
            User user = await userManager.FindByIdAsync(User.Identity.Name);

            Interview interview = null;

            if (await userManager.IsInRoleAsync(user, UserRoles.Admin))
            {
                // Admin can delete any interview
                interview = await _context.Interviews.FindAsync(applicationId);
            }
            else
            {
                // Recruiter can only delete their own interviews
                var query = from qInterview in _context.Interviews
                            join app in _context.Applications on qInterview.ApplicationId equals app.ApplicationId
                            join recruiter in _context.Recruiters on user.Id equals recruiter.UserId
                            join job in _context.JobPosts on recruiter.CompanyId equals job.CompanyId
                            where qInterview.ApplicationId == applicationId
                            select qInterview;

                interview = await query.FirstOrDefaultAsync();
            }

            if (interview == null)
            {
                return(NotFound());
            }

            _context.Interviews.Remove(interview);
            await _context.SaveChangesAsync();

            return(Ok(InterviewToDTO(interview)));
        }
        public async Task <ActionResult <JobPostDTO> > PatchJobPost(long id, JobPostDTO postDTO)
        {
            JobPost post = DTOToJobPost(postDTO);

            if (id != post.JobPostId)
            {
                return(BadRequest());
            }

            User user = await userManager.FindByIdAsync(User.Identity.Name);

            IList <string> roles = await userManager.GetRolesAsync(user);

            if (!roles.Contains(UserRoles.Admin))
            {
                // check if the job post is owned by a companyt hat the recruiter is part of
                var query = from jobpost in _context.JobPosts
                            join queryRecruiter in _context.Recruiters on jobpost.CompanyId equals queryRecruiter.CompanyId
                            where jobpost.JobPostId == post.JobPostId && queryRecruiter.UserId == user.Id
                            select jobpost;
                if (!query.Any())
                {
                    return(Unauthorized("You are not a recruiter for the currenet company specified in the job post"));
                }

                Recruiter recruiter = await _context.Recruiters.FindAsync(user.Id, post.CompanyId);

                if (recruiter == null)
                {
                    return(Unauthorized("You are not a recruiter for the new company specified in the job post"));
                }
            }

            _context.Entry(post).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!JobPostExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(AcceptedAtAction("PatchJobPost", new { JobPostId = post.JobPostId }, postDTO));
        }
        public async Task <IActionResult> PatchOffer(long appId, long offerId, OfferDTO offerDTO)
        {
            Offer offer = DTOToOffer(offerDTO);

            if (offerId != offerDTO.OfferId || appId != offerDTO.ApplicationId)
            {
                return(BadRequest());
            }

            User user = await userManager.FindByNameAsync(User.Identity.Name);

            IList <string> roles = await userManager.GetRolesAsync(user);

            if (!roles.Contains(UserRoles.Admin))
            {
                var query = from queryOffer in _context.Offers
                            join application in _context.Applications on queryOffer.ApplicationId equals application.ApplicationId
                            join jobPost in _context.JobPosts on application.JobId equals jobPost.JobPostId
                            join recruiter in _context.Recruiters on user.Id equals recruiter.UserId
                            where jobPost.CompanyId == recruiter.CompanyId &&
                            queryOffer.ApplicationId == offer.ApplicationId &&
                            queryOffer.OfferId == offer.OfferId
                            select queryOffer;
                if (!await query.AnyAsync())
                {
                    return(Unauthorized("Cannot make an offer for that application"));
                }
            }

            _context.Entry(offer).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OfferExists(appId, offerId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(AcceptedAtAction("PatchOffer", new { ApplicationId = offer.ApplicationId, OfferId = offer.OfferId }, offerDTO));
        }
示例#6
0
        public async Task <IActionResult> PatchReferral(long appId, long refId, ReferralDTO referralDTO)
        {
            Referral referral = DTOToReferral(referralDTO);

            if (appId != referralDTO.ApplicationId || refId != referralDTO.ReferralId)
            {
                return(BadRequest("One of the query params does not match the body params"));
            }

            User user = await userManager.FindByNameAsync(User.Identity.Name);

            IList <string> roles = await userManager.GetRolesAsync(user);

            if (!roles.Contains(UserRoles.Admin))
            {
                var query = from queryReferral in _context.Referrals
                            join application in _context.Applications on queryReferral.ApplicationId equals application.ApplicationId
                            join jobPost in _context.JobPosts on application.JobId equals jobPost.JobPostId
                            join recruiter in _context.Recruiters on user.Id equals recruiter.UserId
                            where jobPost.CompanyId == recruiter.CompanyId &&
                            queryReferral.ApplicationId == referral.ApplicationId &&
                            queryReferral.ReferralId == referral.ReferralId
                            select queryReferral;
                if (!await query.AnyAsync())
                {
                    return(Unauthorized("Cannot modify the referral for that application"));
                }
            }

            _context.Entry(referral).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ReferralExists(appId, refId))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(AcceptedAtAction("PatchReferral", new { ApplicationId = referral.ApplicationId, ReferralId = referral.ReferralId }, referralDTO));
        }
        public async Task <IActionResult> PatchUser(string username, UserDTO userDTO)
        {
            if (username != userDTO.UserName)
            {
                return(BadRequest());
            }

            if (!UserExists(username))
            {
                return(NotFound());
            }


            User authenticatedUser = await userManager.FindByNameAsync(User.Identity.Name);

            if (!(await userManager.IsInRoleAsync(authenticatedUser, UserRoles.Admin)) && !(authenticatedUser.UserName == userDTO.UserName))
            {
                return(Unauthorized("Cannot edit the details of another user unless admin"));
            }

            var user = await userManager.FindByNameAsync(username);

            user.Email       = userDTO.Email;
            user.PhoneNumber = userDTO.PhoneNumber;
            user.FirstName   = userDTO.FirstName;
            user.LastName    = userDTO.LastName;

            _context.Update(user);

            await _context.SaveChangesAsync();

            return(AcceptedAtAction("PatchUser", new { UserName = userDTO.UserName }, userDTO));
        }
示例#8
0
        public async Task <IActionResult> PatchCompany(long id, CompanyDTO companyDTO)
        {
            Company sanitizedCompany = DTOToCompany(companyDTO);

            if (id != sanitizedCompany.CompanyId)
            {
                return(BadRequest());
            }

            if (!CompanyExists(id))
            {
                return(NotFound());
            }

            _context.Update(sanitizedCompany);
            await _context.SaveChangesAsync();

            return(AcceptedAtAction("PatchCompany", new { id = sanitizedCompany.CompanyId }, companyDTO));
        }
        public async Task <IActionResult> PatchApplication(long id, ApplicationDTO appDTO)
        {
            if (id != appDTO.ApplicationId)
            {
                return(BadRequest("Application Id is different in the URL and body of the request"));
            }

            User user = await userManager.FindByNameAsync(User.Identity.Name);

            IList <string> roles = await userManager.GetRolesAsync(user);

            if ((appDTO.DateSubmitted == null) || (!roles.Contains(UserRoles.Admin) && !roles.Contains(UserRoles.Recruiter)))
            {
                appDTO.DateSubmitted = DateTime.UtcNow;
            }
            Application app = DTOToApplication(appDTO);

            bool authorized = false;

            if (roles.Contains(UserRoles.Admin))
            {
                authorized = true;
            }
            else if (roles.Contains(UserRoles.Recruiter))
            {
                var query = from application in _context.Applications
                            join jobPost in _context.JobPosts on application.JobId equals jobPost.JobPostId
                            join recruiter in _context.Recruiters on user.Id equals recruiter.UserId
                            where jobPost.CompanyId == recruiter.CompanyId && application.ApplicationId == app.ApplicationId
                            select application;
                if (await query.AnyAsync())
                {
                    authorized = true;
                }
            }

            if (!authorized)
            {
                return(Unauthorized("Not authorized to update this application or the application does not exist"));
            }

            _context.Entry(app).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ApplicationExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(AcceptedAtAction("PatchApplication", new { applicationId = app.ApplicationId }, appDTO));
        }
示例#10
0
        public static async Task AddSampleData(JobHunterDBContext _context, UserManager <User> userManager, RoleManager <IdentityRole> roleManager)
        {
            if (!_context.Users.Any())
            {
                await AddSampleUserData(userManager);
            }
            if (!_context.Companies.Any())
            {
                _context.Companies.AddRange(SampleCompanyData());
            }
            if (!_context.Resumes.Any())
            {
                _context.Resumes.AddRange(SampleResumeData());
            }
            if (!_context.JobPosts.Any())
            {
                _context.JobPosts.AddRange(SampleJobPostData());
            }
            if (!_context.Skills.Any())
            {
                _context.Skills.AddRange(SampleSkillData());
            }

            if (!_context.Certifications.Any())
            {
                _context.Certifications.AddRange(SampleCertificationData());
            }
            if (!_context.Education.Any())
            {
                _context.Education.AddRange(SampleEducationData());
            }
            if (!_context.Experiences.Any())
            {
                _context.Experiences.AddRange(SampleExperienceData());
            }
            if (!_context.Awards.Any())
            {
                _context.Awards.AddRange(SampleAwardData());
            }
            if (!_context.Projects.Any())
            {
                _context.Projects.AddRange(SampleProjectData());
            }

            if (!_context.Applications.Any())
            {
                _context.Applications.AddRange(SampleApplicationData());
            }
            if (!_context.Referrals.Any())
            {
                _context.Referrals.AddRange(SampleReferralData());
            }
            if (!_context.Recruiters.Any())
            {
                _context.Recruiters.AddRange(SampleRecruiterData());
            }

            if (!_context.Offers.Any())
            {
                _context.Offers.AddRange(SampleOfferData());
            }
            if (!_context.Interviews.Any())
            {
                _context.Interviews.AddRange(SampleInterviewData());
            }
            await _context.SaveChangesAsync();
        }