public async Task <TestingPersonnelInvitationConfirmedShiftsDto> CreateConfirmationAsync(TestingPersonnelManuallyAddedConfirmationDto confirmDto) { if (confirmDto == null) { throw new ArgumentNullException(nameof(confirmDto)); } var invitationId = await _testingPersonnelInvitationsRepository.GetInvitationIdByDateAsync(confirmDto.Date.Date) .ConfigureAwait(false); if (invitationId == Guid.Empty) { ValidationDictionary .AddModelError("Invitation for date was not found", $"{confirmDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}"); return(null); } var doesUserExist = await _testingPersonnelsRepository .AnyAsync(tp => tp.Id == confirmDto.TestingPersonnelId) .ConfigureAwait(false); if (!doesUserExist) { ValidationDictionary .AddModelError("Testing personnel was not found", $"Testing personnel was not found"); return(null); } var doesConfirmationExist = await _testingPersonnelConfirmationsRepository .CheckIfConfirmationExistsForSelectedShiftsAsync(invitationId, confirmDto.TestingPersonnelId, confirmDto.Shifts) .ConfigureAwait(false); if (doesConfirmationExist) { ValidationDictionary .AddModelError("Confirmation already exists for selected testing personnel", $"Confirmation already exists for selected testing personnel"); return(null); } var testingPersonnelConfirmSpecDto = new TestingPersonnelConfirmationSpecDto { InvitationId = invitationId, PersonnelId = confirmDto.TestingPersonnelId, ShiftNumbers = confirmDto.Shifts }; var confirmedShifts = await _testingPersonnelConfirmationsRepository .AddConfirmationOfInvitationAsync(testingPersonnelConfirmSpecDto) .ConfigureAwait(false); if (!confirmedShifts.ShiftsBooked.Any()) { ValidationDictionary .AddModelError("Shift capacity is already full", $"Shift capacity is already full"); return(null); } return(confirmedShifts); }
public async Task CreateConfirmationWithoutInvitationAsync(TestingPersonnelConfirmationsWithoutInvitationSpecDto specDto) { if (specDto == null) { throw new ArgumentNullException(nameof(specDto)); } var invitationExists = await _testingPersonnelInvitationsRepository.AnyAsync(i => i.InvitationForDate.Date == specDto.Date.Date) .ConfigureAwait(false); if (invitationExists) { ValidationDictionary .AddModelError("Invitation for selected date already exists", $"{specDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}"); return; } var testingPersonnelExists = await _testingPersonnelsRepository .AnyAsync(tp => tp.Id == specDto.TestingPersonnelId && tp.Type == TestingPersonnelType.Temporary) .ConfigureAwait(false); if (!testingPersonnelExists) { ValidationDictionary .AddModelError("Testing personnel does not exist or is not of Temporary type", $"Testing personnel does not exist or is not of Temporary type"); return; } bool confirmationForDateExists = await _repository.DoesConfirmationExistAsync(specDto.TestingPersonnelId, specDto.Date, specDto.ShiftNumber) .ConfigureAwait(false); if (confirmationForDateExists) { ValidationDictionary .AddModelError("Confirmation for testing personnel for date and shift already exists", $"Confirmation for testing personnel for date and shift already exists"); return; } await _repository.AddConfirmationAsync(specDto.TestingPersonnelId, specDto.Date, specDto.ShiftNumber) .ConfigureAwait(false); }