| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using Diligent.WebAPI.Contracts.DTOs.SelectionProcess;
-
- namespace Diligent.WebAPI.Business.Services
- {
- public class SelectionProcessService : ISelectionProcessService
- {
- private readonly DatabaseContext _context;
- private readonly IMapper _mapper;
-
- public SelectionProcessService(DatabaseContext context, IMapper mapper)
- {
- _context = context;
- _mapper = mapper;
- }
-
- public async Task<List<SelectionProcessResposneDto>> GetAllAsync() =>
- _mapper.Map<List<SelectionProcessResposneDto>>(await _context.SelectionProcesses.ToListAsync());
-
- public async Task<SelectionProcessResposneDto> GetByIdAsync(int id)
- {
- var sp = await _context.SelectionProcesses.FindAsync(id);
-
- if (sp is null)
- throw new EntityNotFoundException("Selection process not found");
-
- return _mapper.Map<SelectionProcessResposneDto>(sp);
-
- }
-
- public async Task CreateAsync(SelectionProcessCreateDto model)
- {
- await _context.SelectionProcesses.AddAsync(_mapper.Map<SelectionProcess>(model));
-
- await _context.SaveChangesAsync();
- }
-
- public async Task UpdateAsync(int id, SelectionProcessCreateDto model)
- {
- var sp = await _context.SelectionProcesses.FindAsync(id);
-
- if (sp is null)
- throw new EntityNotFoundException("Selection process not found");
-
- _mapper.Map(model, sp);
-
- _context.Entry(sp).State = EntityState.Modified;
- await _context.SaveChangesAsync();
- }
-
- public async Task DeleteAsync(int id)
- {
- var sp = await _context.SelectionProcesses.FindAsync(id);
-
- if (sp is null)
- throw new EntityNotFoundException("Ad not found");
-
- _context.SelectionProcesses.Remove(sp);
- await _context.SaveChangesAsync();
- }
- }
- }
|