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);
        }
Exemple #2
0
        public async Task <ActionResult <Guid> > CreateConfirmationWithoutInvitationAsync(
            [FromBody] TestingPersonnelConfirmationsWithoutInvitationSpecDto specDto)
        {
            if (specDto == null)
            {
                return(BadRequest());
            }

            await _testingPersonnelConfirmationsWithoutInvitationService
            .CreateConfirmationWithoutInvitationAsync(specDto)
            .ConfigureAwait(false);

            if (!_testingPersonnelConfirmationsWithoutInvitationService.ValidationDictionary.IsValid())
            {
                return(BadRequest(new
                {
                    errors = _testingPersonnelConfirmationsWithoutInvitationService.ValidationDictionary.GetErrorMessages()
                }));
            }

            return(Ok());
        }