|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using Bytescout.Spreadsheet;
- using System.Globalization;
-
- namespace Diligent.WebAPI.Business.Services
- {
- public class SaveImportedDataService : ISaveImportedDataService
- {
- private readonly ILogger<SaveImportedDataService> _logger;
- private readonly IApplicantService _applicantService;
- private readonly IAdService _adService;
-
- public SaveImportedDataService(IApplicantService applicantService, ILogger<SaveImportedDataService> logger, IAdService adService)
- {
- _applicantService = applicantService;
- _logger = logger;
- _adService = adService;
- }
- public async Task<List<ApplicantImportDto>> Save()
- {
- List<ApplicantImportDto> applicants = new List<ApplicantImportDto>();
- try
- {
- var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", "s.xlsx");
- Spreadsheet document = new Spreadsheet();
- document.LoadFromFile(path);
- var worksheetsNumber = document.Workbook.Worksheets.Count;
- for (int k = 0; k < worksheetsNumber; k++)
- {
- var worksheets = document.Workbook.Worksheets[k];
- var position = worksheets.Name;
- var ad = await _adService.ImportAsync(new AdCreateDto
- {
- Title = position,
- TechnologiesIds = new(),
- MinimumExperience = 0,
- WorkHour = "FullTime",
- Requirements = "",
- Offer = "",
- KeyResponsibilities = "",
- EmploymentType = position.Contains("praksa") ? "Intership" : "Work",
- CreatedAt = DateTime.Now,
- ExpiredAt = DateTime.Now
- });
-
- int i = 2;
- while (true)
- {
- if (String.IsNullOrEmpty(worksheets.Cell(i, 0).ToString()))
- break;
- var name = worksheets.Cell(i, 0).ToString().Split(' ');
- var a = new ApplicantImportDto
- {
- FirstName = name[0],
- LastName = name[1],
- Email = worksheets.Cell(i, 1).ToString(),
- CV = worksheets.Cell(i, 2).ToString(),
- ApplicationChannel = worksheets.Cell(i, 6).ToString(),
- Comment = worksheets.Cell(i, 7).ToString(),
- Position = position,
- Ad = ad,
- TypeOfEmployment = position.Contains("praksa") ? "Praksa" : "Posao"
- };
- try
- {
- string str = worksheets.Cell(i, 3).ToString();
- if(!string.IsNullOrEmpty(str))
- a.DateOfApplication = DateTime.ParseExact(str, "dd.MM.yyyy.", CultureInfo.InvariantCulture);
-
- }
- catch (Exception ex)
- {
-
- }
- applicants.Add(a);
- i++;
- }
- }
- }
- catch (Exception e)
- {
-
- }
- return applicants;
- }
- }
- }
|