Example #1
0
        public override async Task <int> HandleCommand(AddCommand request, CancellationToken cancellationToken)
        {
            if (request.District == null || string.IsNullOrEmpty(request.District.Code))
            {
                throw new BusinessException("AddWrongInformation");
            }


            var checkingDistrict = (await districtQueries.Gets($"d.code = '{request.District.Code}' and d.is_deleted = 0")).FirstOrDefault();

            if (checkingDistrict != null)
            {
                throw new BusinessException("District.ExistedCode");
            }

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

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

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

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

            request.District = CreateBuild(request.District, request.LoginSession);
            var rs = await districtRepository.Add(request.District);

            return(rs == 0 ? -1 : 0);
        }
Example #2
0
 public async Task <APIResult> GetDistricts()
 {
     return(new APIResult()
     {
         Result = 0,
         Data = await districtQueries.Gets()
     });
 }
        public override async Task <int> HandleCommand(UpdateCommand request, CancellationToken cancellationToken)
        {
            if (request.District == null || request.District.Id == 0)
            {
                throw new BusinessException("District.NotExisted");
            }

            var district = await districtQueries.Get(request.District.Id);

            if (district == null)
            {
                throw new BusinessException("District.NotExisted");
            }

            var checkingDistrict = (await districtQueries.Gets($"d.code = '{request.District.Code}' and d.id <> {district.Id} and d.is_deleted = 0")).FirstOrDefault();

            if (checkingDistrict != null)
            {
                throw new BusinessException("District.ExistedCode");
            }

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

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

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

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

            district            = UpdateBuild(district, request.LoginSession);
            district.Code       = request.District.Code;
            district.Name       = request.District.Name;
            district.CountryId  = request.District.CountryId;
            district.ProvinceId = request.District.ProvinceId;
            district.IsUsed     = request.District.IsUsed;
            var rs = await districtRepository.Update(district);

            return(rs);
        }