Пример #1
0
        public async Task <TestingPersonnelDto> CreateTestingPersonnelAsync(TestingPersonnelSpecDto specDto)
        {
            if (specDto == null)
            {
                throw new ArgumentNullException(nameof(specDto));
            }

            var existingTestingPersonnelId = await _testingPersonnelsRepository.GetTestingPersonnelIdByEmailAsync(specDto.Email)
                                             .ConfigureAwait(false);

            if (existingTestingPersonnelId != Guid.Empty)
            {
                ValidationDictionary
                .AddModelError("Testing personnel with this email already exists", $"{specDto.Email}");
                return(null);
            }

            var testingPersonnel = await AddAsync(specDto)
                                   .ConfigureAwait(false);

            return(testingPersonnel);
        }
Пример #2
0
        public async Task <ActionResult <PagedResults <TestingPersonnelDto> > > CreateTestingPersonnelAsync([FromBody] TestingPersonnelSpecDto specDto)
        {
            if (specDto == null)
            {
                return(BadRequest());
            }

            var testingPersonnel = await _testingPersonnelsService
                                   .CreateTestingPersonnelAsync(specDto)
                                   .ConfigureAwait(false);

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

            return(Ok(testingPersonnel.Id));
        }