Просмотр исходного кода

added endpoints for scheduler update

pull/124/head
meris.ahmatovic 3 лет назад
Родитель
Сommit
aa783de6fd

+ 1
- 0
Diligent.WebAPI.Business/Services/Interfaces/ISelectionProcessService.cs Просмотреть файл

@@ -11,5 +11,6 @@ namespace Diligent.WebAPI.Business.Services.Interfaces
Task<List<SelectionLevelInfoDto>> GetCountByLevels(List<string> statuses);
Task UpdateSelectionProcessStatusAsync(int id, SelectionProcessUpdateStatusDto selectionProcessUpdateStatusDto);
Task StatusUpdate(StatusChangeDTO model);
Task InterviewerUpdate(InterviewerUpdateDTO model);
}
}

+ 29
- 0
Diligent.WebAPI.Business/Services/SelectionProcessService.cs Просмотреть файл

@@ -111,24 +111,53 @@ namespace Diligent.WebAPI.Business.Services
}
public async Task StatusUpdate(StatusChangeDTO model)
{
_logger.LogInformation($"Start searching process with id = {model.ProcessId}");
var process = await _context.SelectionProcesses.FindAsync(model.ProcessId);

if (process is null)
{
_logger.LogError($"Process with id = {model.ProcessId} not found");
throw new EntityNotFoundException("Process does not exist.");
}

_logger.LogInformation($"Check which status is going to be set.");
if (model.NewStatus == "Zakazan" && model.SchedulerId is not null)
{
_logger.LogInformation($"Start searching user with id = {model.SchedulerId}");
var user = await _userManager.FindByIdAsync(model.SchedulerId.ToString());

if (user is null)
throw new EntityNotFoundException("Scheduler does not exist.");

_logger.LogInformation($"Setting user {user.FirstName} {user.LastName} as scheduler for process with id = {model.ProcessId}");
process.SchedulerId = user.Id;
}

process.Status = model.NewStatus;
process.Date = model.Appointment;

_logger.LogInformation($"Processing changes.");
await _context.SaveChangesAsync();
}

public async Task InterviewerUpdate(InterviewerUpdateDTO model)
{
_logger.LogInformation($"Start searching process with id = {model.ProcessId}");
var process = await _context.SelectionProcesses.FindAsync(model.ProcessId);

if (process is null)
throw new EntityNotFoundException("Process does not exist.");

_logger.LogInformation($"Start searching user with id = {model.SchedulerId}");
var user = await _userManager.FindByIdAsync(model.SchedulerId.ToString());

if (user is null)
throw new EntityNotFoundException("Scheduler does not exist.");

_logger.LogInformation($"Setting user {user.FirstName} {user.LastName} as scheduler for process with id = {model.ProcessId}");
process.SchedulerId = user.Id;

_logger.LogInformation("Processing changes...");
await _context.SaveChangesAsync();
}
}

+ 9
- 0
Diligent.WebAPI.Contracts/DTOs/SelectionProcess/InterviewerUpdateDTO.cs Просмотреть файл

@@ -0,0 +1,9 @@
namespace Diligent.WebAPI.Contracts.DTOs.SelectionProcess
{
public class InterviewerUpdateDTO {
[Required]
public int ProcessId { get; set; }
[Required]
public int SchedulerId { get; set; }
}
}

+ 7
- 0
Diligent.WebAPI.Host/Controllers/V1/SelectionProcessesController.cs Просмотреть файл

@@ -31,6 +31,13 @@ namespace Diligent.WebAPI.Host.Controllers.V1
await _selectionProcessesService.StatusUpdate(model);
return Ok("Status updated.");
}

[HttpPost("interviewer-update")]
public async Task<IActionResult> UpdateInterviewer([FromBody] InterviewerUpdateDTO model)
{
await _selectionProcessesService.InterviewerUpdate(model);
return Ok("Interviewer changed.");
}
//[HttpPost]
//public async Task<IActionResult> Create([FromBody] SelectionProcessCreateDto request)
//{

Загрузка…
Отмена
Сохранить