Exemplo n.º 1
0
 public async Task <APIResult> GetDistrict(int districtId)
 {
     return(new APIResult()
     {
         Result = 0,
         Data = await districtQueries.Get(districtId)
     });
 }
Exemplo n.º 2
0
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.Ward == null || request.Ward.Id == 0)
            {
                throw new BusinessException("Ward.NotExisted");
            }

            var ward = await wardQueries.Get(request.Ward.Id);

            if (ward == null)
            {
                throw new BusinessException("Ward.NotExisted");
            }

            var checkingWard = (await wardQueries.Gets($"w.code = '{request.Ward.Code}' and w.id <> {ward.Id} and w.is_deleted = 0")).FirstOrDefault();

            if (checkingWard != null)
            {
                throw new BusinessException("Ward.ExistedCode");
            }

            var country = await countryQueries.Get(request.Ward.CountryId);

            if (country == null)
            {
                throw new BusinessException("Country.NotExisted");
            }

            var province = await provinceQueries.Get(request.Ward.ProvinceId);

            if (province == null || province.CountryId != request.Ward.CountryId)
            {
                throw new BusinessException("Province.NotExisted");
            }

            var district = await districtQueries.Get(request.Ward.DistrictId);

            if (district == null || district.ProvinceId != request.Ward.ProvinceId)
            {
                throw new BusinessException("District.NotExisted");
            }

            ward            = UpdateBuild(ward, request.LoginSession);
            ward.Code       = request.Ward.Code;
            ward.Name       = request.Ward.Name;
            ward.CountryId  = request.Ward.CountryId;
            ward.ProvinceId = request.Ward.ProvinceId;
            ward.DistrictId = request.Ward.DistrictId;
            ward.IsUsed     = request.Ward.IsUsed;
            var rs = await wardRepository.Update(ward);

            return(rs);
        }
Exemplo n.º 3
0
        public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken)
        {
            if (request.Ward == null || string.IsNullOrEmpty(request.Ward.Code))
            {
                throw new BusinessException("AddWrongInformation");
            }


            var checkingWard = (await wardQueries.Gets($"w.code = '{request.Ward.Code}' and w.is_deleted = 0")).FirstOrDefault();

            if (checkingWard != null)
            {
                throw new BusinessException("Ward.ExistedCode");
            }

            var country = await countryQueries.Get(request.Ward.CountryId);

            if (country == null)
            {
                throw new BusinessException("Country.NotExisted");
            }

            var province = await provinceQueries.Get(request.Ward.ProvinceId);

            if (province == null || province.CountryId != request.Ward.CountryId)
            {
                throw new BusinessException("Province.NotExisted");
            }

            var district = await districtQueries.Get(request.Ward.DistrictId);

            if (district == null || district.ProvinceId != request.Ward.ProvinceId)
            {
                throw new BusinessException("District.NotExisted");
            }

            request.Ward = CreateBuild(request.Ward, request.LoginSession);
            var rs = await wardRepository.Add(request.Ward);

            return(rs == 0 ? -1 : 0);
        }