Beispiel #1
0
    public async Task SaveJob(Guid jobID)
    {
        Utils.CheckNullOrEmpty(new List<string> { "Id", "ApplicantStatus" }, jobID);

        using (AppDbContext context = new AppDbContext())
        {
            User user = await GetCurrentUser(context);

            if (user.UserType == UserType.JobSeeker)
            {
                Applicant applicant = await context.Applicants.FirstOrDefaultAsync(p => p.JobSeekerId == user.Id && p.JobId == jobID);

                if (applicant != null)
                {
                    if (applicant.ApplicantStatus == ApplicantStatus.Applied)
                    {
                        throw new UserException(ErrorCode.JOB_ALREADY_APPLIED.ToString());
                    }
                    else if (applicant.ApplicantStatus == ApplicantStatus.Saved)
                    {
                        throw new UserException(ErrorCode.JOB_ALREADY_SAVED.ToString());
                    }
                    else
                    {
                        applicant.ApplicantStatus = ApplicantStatus.Saved;
                        await context.SaveChangesAsync();
                    }
                }
                else
                {
                    Applicant newApplicant = new Applicant
                    {
                        Id = Guid.NewGuid(),
                        JobSeekerId = user.Id,
                        JobId = jobID,
                        ApplicantStatus = ApplicantStatus.Saved,
                        CreatedDateUtc = DateTime.UtcNow,
                        UpdatedDateUtc = DateTime.UtcNow
                    };
                    context.Applicants.Add(newApplicant);

                    await context.SaveChangesAsync();
                }
            }
            else
            {
                throw new UserException(ErrorCode.NO_PERMISSION.ToString());
            }
        }
    }
Beispiel #2
0
    public async Task ApplyJob(Guid jobID)
    {
        Utils.CheckNullOrEmpty(new List<string> { "Id" }, jobID);

        using (AppDbContext context = new AppDbContext())
        {
            User user = await GetCurrentUser(context);

            if (user.UserType == UserType.JobSeeker)
            {
                Applicant applicant = await context.Applicants.FirstOrDefaultAsync(p => p.JobSeekerId == user.Id && p.JobId == jobID);
                Job job = await context.Jobs.Include(p => p.Employer.User).FirstOrDefaultAsync(p => p.Id == jobID);
                JobSeeker jobSeeker = await context.JobSeekers.FirstOrDefaultAsync(p => p.UserId == user.Id);


                if (applicant != null)
                {
                    if (applicant.ApplicantStatus == ApplicantStatus.Applied)
                    {
                        throw new UserException(ErrorCode.JOB_ALREADY_APPLIED.ToString());
                    }
                    else
                    {
                        applicant.ApplicantStatus = ApplicantStatus.Applied;
                        await context.SaveChangesAsync();
                        await EmailDelivery.SendJobSeekerAppliedJob(job.Employer.User.Email, jobSeeker.FullName, job.JobName, user.Id);
                    }
                }
                else
                {
                    Applicant newApplicant = new Applicant
                    {
                        Id = Guid.NewGuid(),
                        JobSeekerId = user.Id,
                        JobId = jobID,
                        ApplicantStatus = ApplicantStatus.Applied,
                        CreatedDateUtc = DateTime.UtcNow,
                        UpdatedDateUtc = DateTime.UtcNow
                    };
                    context.Applicants.Add(newApplicant);
                    await context.SaveChangesAsync();
                    await EmailDelivery.SendJobSeekerAppliedJob(job.Employer.User.Email, jobSeeker.FullName, job.JobName, user.Id);
                }
            }
            else
            {
                throw new UserException(ErrorCode.NO_PERMISSION.ToString());
            }
        }
    }