Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ApplicantService.cs 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using Diligent.WebAPI.Contracts.DTOs.Applicant;
  2. namespace Diligent.WebAPI.Business.Services
  3. {
  4. public class ApplicantService : IApplicantService
  5. {
  6. private readonly DatabaseContext _context;
  7. private readonly IMapper _mapper;
  8. public ApplicantService(DatabaseContext context,IMapper mapper)
  9. {
  10. _context = context;
  11. _mapper = mapper;
  12. }
  13. public async Task<List<ApplicantViewDto>> GetAll()
  14. {
  15. var applicants = await _context.Applicants.Include(c => c.Ads).ToListAsync();
  16. return _mapper.Map<List<ApplicantViewDto>>(applicants);
  17. }
  18. public async Task<ApplicantViewDto> GetById(int id)
  19. {
  20. var applicant = await _context.Applicants
  21. .Include(x => x.Ads)
  22. .ThenInclude(x => x.Technologies)
  23. .Include(x => x.TechnologyApplicants)
  24. .ThenInclude(x => x.Technology)
  25. .Include(x => x.Comments)
  26. .ThenInclude(t => t.User)
  27. .FirstOrDefaultAsync(x => x.ApplicantId == id);
  28. if (applicant is null)
  29. throw new EntityNotFoundException("Applicant not found");
  30. return _mapper.Map<ApplicantViewDto>(applicant);
  31. }
  32. public async Task<ApplicantViewDto> GetApplicantWithSelectionProcessesById(int id)
  33. {
  34. var applicant = await _context.Applicants
  35. .Include(a => a.SelectionProcesses).ThenInclude(sp => sp.SelectionLevel)
  36. .Include(a => a.SelectionProcesses).ThenInclude(sp => sp.Scheduler)
  37. .FirstOrDefaultAsync(a => a.ApplicantId == id);
  38. if (applicant is null)
  39. throw new EntityNotFoundException("Applicant not found");
  40. return _mapper.Map<ApplicantViewDto>(applicant);
  41. }
  42. public async Task CreateApplicant(ApplicantCreateDto applicantCreateDto)
  43. {
  44. var applicant = _mapper.Map<Applicant>(applicantCreateDto);
  45. await _context.Applicants.AddAsync(applicant);
  46. await _context.SaveChangesAsync();
  47. }
  48. public async Task DeleteApplicant(int id)
  49. {
  50. var applicant = await _context.Applicants.FindAsync(id);
  51. if(applicant is null)
  52. throw new EntityNotFoundException("Applicant not found");
  53. _context.Applicants.Remove(applicant);
  54. await _context.SaveChangesAsync();
  55. }
  56. public async Task UpdateApplicant(int id, ApplicantUpdateDto applicantUpdateDto)
  57. {
  58. var applicant = await _context.Applicants.FindAsync(id);
  59. if (applicant is null)
  60. throw new EntityNotFoundException("Applicant not found");
  61. _mapper.Map(applicantUpdateDto, applicant);
  62. _context.Entry(applicant).State = EntityState.Modified;
  63. await _context.SaveChangesAsync();
  64. }
  65. }
  66. }