Esempio n. 1
0
        public async Task <CantonDto> CreateCantonWithSamplesCountAsync(CantonSpecDto cantonSpecDto)
        {
            if (cantonSpecDto == null)
            {
                throw new ArgumentNullException(nameof(cantonSpecDto));
            }

            var doesCantonExist = await AnyAsync(c => c.Name == cantonSpecDto.Name || c.ShortName == cantonSpecDto.ShortName)
                                  .ConfigureAwait(false);

            if (doesCantonExist)
            {
                ValidationDictionary
                .AddModelError("Canton with this name or abbreviation already exists", $"{cantonSpecDto.Name}, {cantonSpecDto.ShortName}");

                return(null);
            }

            Guid countryId = await _countriesRepository.GetCountryIdByNameAsync(CountryName)
                             .ConfigureAwait(false);

            cantonSpecDto.CountryId = countryId;

            return(await AddAsync(cantonSpecDto)
                   .ConfigureAwait(false));
        }
Esempio n. 2
0
        public async Task <ActionResult <Guid> > CreateCantonWithSamplesCountAsync([FromBody] CantonSpecDto cantonSpecDto)
        {
            if (cantonSpecDto == null)
            {
                return(BadRequest());
            }

            var cantonDto = await _cantonService
                            .CreateCantonWithSamplesCountAsync(cantonSpecDto)
                            .ConfigureAwait(false);

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

            return(Ok(cantonDto.Id));
        }