| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Bytescout.Spreadsheet;
- using System.Globalization;
-
- namespace Diligent.WebAPI.Business.Services
- {
- public class SaveImportedDataService : ISaveImportedDataService
- {
- private readonly ILogger<SaveImportedDataService> _logger;
- private readonly IAdService _adService;
-
- public SaveImportedDataService(ILogger<SaveImportedDataService> logger, IAdService adService)
- {
- _logger = logger;
- _adService = adService;
- }
- public async Task<List<ApplicantImportDto>> Save()
- {
- List<ApplicantImportDto> applicants = new List<ApplicantImportDto>();
- try
- {
- _logger.LogInformation("Unoirtubg data from file...");
- var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", "s.xlsx");
- Spreadsheet document = new Spreadsheet();
- document.LoadFromFile(path);
- _logger.LogInformation("File is opened successfully");
- var worksheetsNumber = document.Workbook.Worksheets.Count;
- _logger.LogInformation($"File contains {worksheetsNumber} sheets");
- for (int k = 0; k < worksheetsNumber; k++)
- {
- var worksheets = document.Workbook.Worksheets[k];
- var position = worksheets.Name;
- _logger.LogInformation($"Import data for Ad {position}");
- 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"
- };
- _logger.LogInformation($"Loaded user {a.FirstName} {a.LastName}");
- 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)
- {
- _logger.LogError("Incorect date time for this candidate");
- }
- applicants.Add(a);
- _logger.LogInformation("Candidate added successfully in the list");
- i++;
- }
- }
- }
- catch (Exception e)
- {
- _logger.LogError(e.Message);
- throw new FileNotFoundException("File is not uploaded!");
- }
- return applicants;
- }
- }
- }
|