Ejemplo n.º 1
0
        public void UpdateWard(WardDTO ward)
        {
            var wardEF = wardRepository.GetBy(ward.IdWard);

            ward.MappingWard(wardEF);
            wardRepository.Update(wardEF);
        }
        public void UpdateProvince(ProvinceViewModel provoinceVm)
        {
            var province = Mapper.Map <ProvinceViewModel, Province>(provoinceVm);

            //District
            var newdistricts = province.Districts;

            //new districts added
            var addedDistricts = newdistricts.Where(x => x.Id == 0).ToList();

            //get updated districts
            var updatedDistricts = newdistricts.Where(x => x.Id != 0).ToList();

            //Existed districts
            var existedDistricts = _disctrictRepository.FindAll(x => x.ProvinceId == provoinceVm.Id);

            province.Districts.Clear();

            //Ward
            var newwards = province.Wards;

            //new wards added
            var addedWards = newwards.Where(x => x.Id == 0).ToList();

            //get updated wards
            var updatedWards = newwards.Where(x => x.Id != 0).ToList();

            //Existed wards
            var existedWards = _wardRepository.FindAll(x => x.ProvinceId == provoinceVm.Id);

            province.Wards.Clear();

            var newtreets = province.Streets;

            //new districts added
            var addedTreets = newtreets.Where(x => x.Id == 0).ToList();

            //get updated districts
            var updatedTreets = newtreets.Where(x => x.Id != 0).ToList();

            //Existed details
            var existedTreets = _streetRepository.FindAll(x => x.ProvinceId == provoinceVm.Id);

            //Clear db
            province.Streets.Clear();

            foreach (var district in updatedDistricts)
            {
                _disctrictRepository.Update(district);
            }
            foreach (var ward in updatedWards)
            {
                _wardRepository.Update(ward);
            }
            foreach (var street in updatedTreets)
            {
                _streetRepository.Update(street);
            }
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
 public void Update(Ward item)
 {
     item.UpdatedDate = DateTime.Now;
     _wardRepository.Update(item);
 }
Ejemplo n.º 5
0
        public void Update(WardViewModel wardVm)
        {
            var ward = Mapper.Map <WardViewModel, Ward>(wardVm);

            _wardRepository.Update(ward);
        }