選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

SelectionProcessService.cs 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
  2. namespace Diligent.WebAPI.Business.Services
  3. {
  4. public class SelectionProcessService : ISelectionProcessService
  5. {
  6. private readonly DatabaseContext _context;
  7. private readonly IMapper _mapper;
  8. public SelectionProcessService(DatabaseContext context, IMapper mapper)
  9. {
  10. _context = context;
  11. _mapper = mapper;
  12. }
  13. public async Task<List<SelectionProcessResposneDto>> GetAllAsync() =>
  14. _mapper.Map<List<SelectionProcessResposneDto>>(await _context.SelectionProcesses.ToListAsync());
  15. public async Task<SelectionProcessResposneDto> GetByIdAsync(int id)
  16. {
  17. var sp = await _context.SelectionProcesses.FindAsync(id);
  18. if (sp is null)
  19. throw new EntityNotFoundException("Selection process not found");
  20. return _mapper.Map<SelectionProcessResposneDto>(sp);
  21. }
  22. public async Task CreateAsync(SelectionProcessCreateDto model)
  23. {
  24. await _context.SelectionProcesses.AddAsync(_mapper.Map<SelectionProcess>(model));
  25. await _context.SaveChangesAsync();
  26. }
  27. public async Task UpdateAsync(int id, SelectionProcessCreateDto model)
  28. {
  29. var sp = await _context.SelectionProcesses.FindAsync(id);
  30. if (sp is null)
  31. throw new EntityNotFoundException("Selection process not found");
  32. _mapper.Map(model, sp);
  33. _context.Entry(sp).State = EntityState.Modified;
  34. await _context.SaveChangesAsync();
  35. }
  36. public async Task DeleteAsync(int id)
  37. {
  38. var sp = await _context.SelectionProcesses.FindAsync(id);
  39. if (sp is null)
  40. throw new EntityNotFoundException("Ad not found");
  41. _context.SelectionProcesses.Remove(sp);
  42. await _context.SaveChangesAsync();
  43. }
  44. }
  45. }