|
|
|
@@ -1,4 +1,6 @@ |
|
|
|
namespace Diligent.WebAPI.Business.Services |
|
|
|
using static Diligent.WebAPI.Data.Entities.Applicant; |
|
|
|
|
|
|
|
namespace Diligent.WebAPI.Business.Services |
|
|
|
{ |
|
|
|
public class ApplicantService : IApplicantService |
|
|
|
{ |
|
|
|
@@ -111,6 +113,61 @@ |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task ApplyForAAd(ApplyForAdRequestDto request) |
|
|
|
{ |
|
|
|
_logger.LogInformation("Start applying for ad"); |
|
|
|
_logger.LogInformation("Find ad by id"); |
|
|
|
var ad = await _context.Ads.Where(x => x.Id == request.AdId).FirstOrDefaultAsync(); |
|
|
|
|
|
|
|
if (ad == null) |
|
|
|
{ |
|
|
|
_logger.LogError($"Ad with {request.AdId} not found"); |
|
|
|
throw new EntityNotFoundException("Ad not found in database"); |
|
|
|
} |
|
|
|
|
|
|
|
_logger.LogInformation($"Find sent technologies from FE in database"); |
|
|
|
var technologies = await _context.Technologies.Where(x => request.TechnologiesIds.Contains(x.TechnologyId)).ToListAsync(); |
|
|
|
|
|
|
|
_logger.LogInformation($"Create applicant instance with sent data"); |
|
|
|
Applicant applicant = new Applicant |
|
|
|
{ |
|
|
|
FirstName = request.FirstName, |
|
|
|
LastName = request.LastName, |
|
|
|
Position = ad.Title, |
|
|
|
DateOfApplication = DateTime.UtcNow, |
|
|
|
CV = request.PdfFile, |
|
|
|
Email = request.Email, |
|
|
|
PhoneNumber = request.PhoneNumber, |
|
|
|
GithubLink = request.GithubLink, |
|
|
|
LinkedlnLink = request.LinkedinLink, |
|
|
|
BitBucketLink = request.BitBucketLink, |
|
|
|
Experience = request.Experience, |
|
|
|
//TypeOfEmployment = (EmploymentTypes)Enum.Parse(typeof(EmploymentTypes), ad.EmploymentType, true), |
|
|
|
TypeOfEmployment = ad.EmploymentType == EmploymentTypes.Intership ? TypesOfEmployment.Intership : TypesOfEmployment.Posao, |
|
|
|
Comments = new(), |
|
|
|
Ads = new List<Ad> { ad }, |
|
|
|
SelectionProcesses = new(), |
|
|
|
TechnologyApplicants = new(), |
|
|
|
ApplicationChannel = "Putem sajta" |
|
|
|
}; |
|
|
|
|
|
|
|
_logger.LogInformation($"Saving applicant in database"); |
|
|
|
await _context.AddAsync(applicant); |
|
|
|
|
|
|
|
await _context.SaveChangesAsync(); |
|
|
|
_logger.LogInformation($"Applicant saved in database"); |
|
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"Saving TechnologyApplicants in database"); |
|
|
|
for (int i = 0; i < technologies.Count; i++) |
|
|
|
{ |
|
|
|
await _context.ApplicantTechnologies.AddAsync(new TechnologyApplicant { Applicant = applicant, ApplicantId = applicant.ApplicantId, Technology = technologies[i], TechnologyId = technologies[i].TechnologyId }); |
|
|
|
} |
|
|
|
|
|
|
|
await _context.SaveChangesAsync(); |
|
|
|
_logger.LogInformation($"TechnologyApplicants saved in database"); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<List<ApplicantOptionsDTO>> GetOptions() |
|
|
|
{ |
|
|
|
var res = await _context.Applicants.ToListAsync(); |