Esempio n. 1
0
        public async Task <CityDistrictOutputQuery> HandleAsync(GetCityDistrictInputQuery inputQuery, CancellationToken cancellationToken = default)
        {
            var getCityDistrictResult = await _cityDistrictGetterService.GetByIdAsync(inputQuery.CityDistrictId);

            if (!getCityDistrictResult.Success)
            {
                throw new ResourceNotFoundException(getCityDistrictResult.Errors);
            }
            return(_mapper.Map <CityDistrict, CityDistrictOutputQuery>(getCityDistrictResult.Value));
        }
Esempio n. 2
0
        public async Task GetByIdAsync_Should_Return_GetResult_With_CityDistrict()
        {
            var cityDistrict = CityDistrict.Builder()
                               .SetId(Guid.NewGuid())
                               .SetRowVersion(Array.Empty <byte>())
                               .SetName("Name")
                               .SetPolishName("PolishName")
                               .SetCityId(Guid.NewGuid())
                               .SetParentId(Guid.NewGuid())
                               .SetNameVariants(new List <string> {
                "NameVariant"
            })
                               .Build();
            var expectedResult = GetResult <CityDistrict> .Ok(cityDistrict);

            _cityDistrictRepositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(cityDistrict);

            var result = await _service.GetByIdAsync(cityDistrict.Id);

            result.Should().BeEquivalentTo(expectedResult);
        }
Esempio n. 3
0
        public async Task <VerificationResult> VerifyParentExistsAsync(Guid parentId)
        {
            var getCityDistrictResult = await _cityDistrictGetterService.GetByIdAsync(parentId);

            if (getCityDistrictResult.Success)
            {
                return(VerificationResult.Ok());
            }

            var errors = new Collection <IError>
            {
                new Error(CityDistrictErrorCodeEnumeration.ParentNotFound, CityDistrictErrorMessage.ParentNotFound)
            };

            return(VerificationResult.Fail(errors));
        }
Esempio n. 4
0
        public async Task HandleAsync(DeleteCityDistrictCommand command, CancellationToken cancellationToken = default)
        {
            var getCityDistrictResult = await _cityDistrictGetterService.GetByIdAsync(command.CityDistrictId);

            if (!getCityDistrictResult.Success)
            {
                throw new ResourceNotFoundException(getCityDistrictResult.Errors);
            }

            if (getCityDistrictResult.Value.RowVersion.Except(command.RowVersion).Any())
            {
                throw new PreconditionFailedException();
            }

            await _cityDistrictRepository.DeleteAsync(getCityDistrictResult.Value);
        }
Esempio n. 5
0
        public async Task HandleAsync(UpdateCityDistrictCommand command, CancellationToken cancellationToken = default)
        {
            var getCityDistrictResult = await _cityDistrictGetterService.GetByIdAsync(command.CityDistrictId);

            if (!getCityDistrictResult.Success)
            {
                throw new ResourceNotFoundException(getCityDistrictResult.Errors);
            }

            if (getCityDistrictResult.Value.RowVersion.Except(command.RowVersion).Any())
            {
                throw new PreconditionFailedException();
            }

            await UpdateCityIdAsync(getCityDistrictResult.Value, command.CityId);
            await UpdateParentIdAsync(getCityDistrictResult.Value, command.ParentId);
            await UpdateNamesAsync(getCityDistrictResult.Value, command.Name, command.PolishName, command.CityId);

            UpdateNameVariants(getCityDistrictResult.Value, command.NameVariants.ToList());

            await _cityDistrictRepository.UpdateAsync(getCityDistrictResult.Value);
        }