Ejemplo n.º 1
0
        public async Task CancelFixedTestingPersonnelForDateAsync(CancelFixedTestingPersonnelForDateSpecDto specDto)
        {
            if (specDto == null)
            {
                throw new ArgumentNullException(nameof(specDto));
            }

            Guid testingPersonnelId = await _testingPersonnelsRepository.GetTestingPersonnelIdByEmailAndTypeAsync(specDto.Email, TestingPersonnelType.Fixed)
                                      .ConfigureAwait(false);

            if (testingPersonnelId == Guid.Empty)
            {
                ValidationDictionary
                .AddModelError("Fixed testing personnel with email was not found", $"{specDto.Email}");
                return;
            }

            var cancelationForDateExists = await _repository.DoesCancelationForTestingPersonnelAndDateExistAsync(testingPersonnelId, specDto.Date)
                                           .ConfigureAwait(false);

            if (cancelationForDateExists)
            {
                ValidationDictionary
                .AddModelError("Cancelation for testing personnel for date already exists", $"{specDto.Date.ToString(dateFormat, CultureInfo.InvariantCulture)}");
                return;
            }

            await _repository.CancelFixedTestingPersonnelForDateAsync(testingPersonnelId, specDto.CanceledByUserId, specDto.Date.Date)
            .ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> CancelFixedTestingPersonnelForDateAsync([FromBody] CancelFixedTestingPersonnelForDateSpecDto specDto)
        {
            if (specDto == null)
            {
                return(BadRequest());
            }

            var loggedUserId = HttpContext.User.Claims.First(x => x.Type == JwtRegisteredClaimNames.Jti).Value;

            specDto.CanceledByUserId = Guid.Parse(loggedUserId);

            await _fixedTestingPersonnelCancelationService
            .CancelFixedTestingPersonnelForDateAsync(specDto)
            .ConfigureAwait(false);

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

            return(Ok());
        }