Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SaveImportedDataService.cs 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Bytescout.Spreadsheet;
  2. using System.Globalization;
  3. namespace Diligent.WebAPI.Business.Services
  4. {
  5. public class SaveImportedDataService : ISaveImportedDataService
  6. {
  7. private readonly ILogger<SaveImportedDataService> _logger;
  8. private readonly IApplicantService _applicantService;
  9. private readonly IAdService _adService;
  10. public SaveImportedDataService(IApplicantService applicantService, ILogger<SaveImportedDataService> logger, IAdService adService)
  11. {
  12. _applicantService = applicantService;
  13. _logger = logger;
  14. _adService = adService;
  15. }
  16. public async Task<List<ApplicantImportDto>> Save()
  17. {
  18. List<ApplicantImportDto> applicants = new List<ApplicantImportDto>();
  19. try
  20. {
  21. var path = Path.Combine(Directory.GetCurrentDirectory(), "Files", "s.xlsx");
  22. Spreadsheet document = new Spreadsheet();
  23. document.LoadFromFile(path);
  24. var worksheetsNumber = document.Workbook.Worksheets.Count;
  25. for (int k = 0; k < worksheetsNumber; k++)
  26. {
  27. var worksheets = document.Workbook.Worksheets[k];
  28. var position = worksheets.Name;
  29. var ad = await _adService.ImportAsync(new AdCreateDto
  30. {
  31. Title = position,
  32. TechnologiesIds = new(),
  33. MinimumExperience = 0,
  34. WorkHour = "FullTime",
  35. Requirements = "",
  36. Offer = "",
  37. KeyResponsibilities = "",
  38. EmploymentType = position.Contains("praksa") ? "Intership" : "Work",
  39. CreatedAt = DateTime.Now,
  40. ExpiredAt = DateTime.Now
  41. });
  42. int i = 2;
  43. while (true)
  44. {
  45. if (String.IsNullOrEmpty(worksheets.Cell(i, 0).ToString()))
  46. break;
  47. var name = worksheets.Cell(i, 0).ToString().Split(' ');
  48. var a = new ApplicantImportDto
  49. {
  50. FirstName = name[0],
  51. LastName = name[1],
  52. Email = worksheets.Cell(i, 1).ToString(),
  53. CV = worksheets.Cell(i, 2).ToString(),
  54. ApplicationChannel = worksheets.Cell(i, 6).ToString(),
  55. Comment = worksheets.Cell(i, 7).ToString(),
  56. Position = position,
  57. Ad = ad,
  58. TypeOfEmployment = position.Contains("praksa") ? "Praksa" : "Posao"
  59. };
  60. try
  61. {
  62. string str = worksheets.Cell(i, 3).ToString();
  63. if(!string.IsNullOrEmpty(str))
  64. a.DateOfApplication = DateTime.ParseExact(str, "dd.MM.yyyy.", CultureInfo.InvariantCulture);
  65. }
  66. catch (Exception ex)
  67. {
  68. }
  69. applicants.Add(a);
  70. i++;
  71. }
  72. }
  73. }
  74. catch (Exception e)
  75. {
  76. }
  77. return applicants;
  78. }
  79. }
  80. }