|
|
|
@@ -1,4 +1,8 @@ |
|
|
|
using static Diligent.WebAPI.Data.Entities.Applicant; |
|
|
|
using Azure.Storage.Blobs; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.WindowsAzure.Storage; |
|
|
|
using Microsoft.WindowsAzure.Storage.Blob; |
|
|
|
using static Diligent.WebAPI.Data.Entities.Applicant; |
|
|
|
|
|
|
|
namespace Diligent.WebAPI.Business.Services |
|
|
|
{ |
|
|
|
@@ -8,13 +12,16 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
private readonly IMapper _mapper; |
|
|
|
private readonly ILogger<ApplicantService> _logger; |
|
|
|
private readonly IUserService _userService; |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
|
|
|
|
public ApplicantService(DatabaseContext context, IMapper mapper, ILogger<ApplicantService> logger, IUserService userService) |
|
|
|
public ApplicantService(DatabaseContext context, IMapper mapper, ILogger<ApplicantService> logger, |
|
|
|
IUserService userService,IConfiguration configuration) |
|
|
|
{ |
|
|
|
_context = context; |
|
|
|
_mapper = mapper; |
|
|
|
_logger = logger; |
|
|
|
_userService = userService; |
|
|
|
_configuration = configuration; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<QueryResultDto<ApplicantViewDto>> GetFilteredApplicants(ApplicantFilterDto applicantFilterDto) |
|
|
|
@@ -115,8 +122,22 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task ApplyForAAd(ApplyForAdRequestDto request) |
|
|
|
public async Task ApplyForAd(ApplyForAdRequestDto request) |
|
|
|
{ |
|
|
|
string fileName = string.Format(@"{0}.pdf", DateTime.Now.Ticks); |
|
|
|
|
|
|
|
string blobstorageconnection = _configuration.GetValue<string>("BlobConnectionString"); |
|
|
|
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection); |
|
|
|
CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient(); |
|
|
|
CloudBlobContainer container = blobClient.GetContainerReference( |
|
|
|
_configuration.GetValue<string>("BlobContainerName")); |
|
|
|
CloudBlockBlob blockBlob = container.GetBlockBlobReference(fileName); |
|
|
|
|
|
|
|
await using (var data = request.PdfFile.OpenReadStream()) |
|
|
|
{ |
|
|
|
await blockBlob.UploadFromStreamAsync(data); |
|
|
|
} |
|
|
|
|
|
|
|
_logger.LogInformation("Start applying for ad"); |
|
|
|
_logger.LogInformation("Find ad by id"); |
|
|
|
var ad = await _context.Ads.Where(x => x.Id == request.AdId).FirstOrDefaultAsync(); |
|
|
|
@@ -131,13 +152,13 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
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 |
|
|
|
Applicant applicant = new() |
|
|
|
{ |
|
|
|
FirstName = request.FirstName, |
|
|
|
LastName = request.LastName, |
|
|
|
Position = ad.Title, |
|
|
|
DateOfApplication = DateTime.UtcNow, |
|
|
|
CV = request.PdfFile, |
|
|
|
CV = fileName, |
|
|
|
Email = request.Email, |
|
|
|
PhoneNumber = request.PhoneNumber, |
|
|
|
GithubLink = request.GithubLink, |
|
|
|
@@ -154,9 +175,9 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
}; |
|
|
|
|
|
|
|
_logger.LogInformation($"Saving applicant in database"); |
|
|
|
await _context.AddAsync(applicant); |
|
|
|
await _context.Applicants.AddAsync(applicant); |
|
|
|
|
|
|
|
await _context.SaveChangesAsync(); |
|
|
|
var res = await _context.SaveChangesAsync(); |
|
|
|
_logger.LogInformation($"Applicant saved in database"); |
|
|
|
|
|
|
|
|
|
|
|
@@ -248,6 +269,35 @@ namespace Diligent.WebAPI.Business.Services |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<string> GetCV(string fileName) |
|
|
|
{ |
|
|
|
CloudBlockBlob blockBlob; |
|
|
|
await using (MemoryStream memoryStream = new()) |
|
|
|
{ |
|
|
|
string blobstorageconnection = _configuration.GetValue<string>("BlobConnectionString"); |
|
|
|
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(blobstorageconnection); |
|
|
|
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient(); |
|
|
|
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference(_configuration.GetValue<string>("BlobContainerName")); |
|
|
|
blockBlob = cloudBlobContainer.GetBlockBlobReference(fileName); |
|
|
|
await blockBlob.DownloadToStreamAsync(memoryStream); |
|
|
|
Stream blobStream = blockBlob.OpenReadAsync().Result; |
|
|
|
return ConvertToBase64(blobStream); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static string ConvertToBase64(Stream stream) |
|
|
|
{ |
|
|
|
byte[] bytes; |
|
|
|
using (var memoryStream = new MemoryStream()) |
|
|
|
{ |
|
|
|
stream.CopyTo(memoryStream); |
|
|
|
bytes = memoryStream.ToArray(); |
|
|
|
} |
|
|
|
|
|
|
|
string base64 = Convert.ToBase64String(bytes); |
|
|
|
return base64; |
|
|
|
} |
|
|
|
|
|
|
|
//public async Task CreateApplicant(ApplicantCreateDto applicantCreateDto) |
|
|
|
//{ |
|
|
|
// var applicant = _mapper.Map<Applicant>(applicantCreateDto); |