Ejemplo n.º 1
0
        public JsonResult LoadVillage(int districtID)
        {
            var xmlDoc = XDocument.Load(Server.MapPath(@"~/Assets/client/data/Provinces_VietNam.xml"));

            var xElement = xmlDoc.Element("Root").Elements("Item").Elements("Item").
                           Where(x => x.Attribute("type").Value == "district" && int.Parse(x.Attribute("id").Value) == districtID);

            //var xElement = xmlDoc.Element("Root").Elements("Item").Elements("Item").Elements("Item").
            //    Where(x => x.Attribute("type").Value == "precinct" && int.Parse(x.Attribute("id").Value) == districtID);

            var          list     = new List <VillageModel>();
            VillageModel district = null;

            foreach (var item in xElement.Elements("Item").Where(x => x.Attribute("type").Value == "precinct"))
            {
                district            = new VillageModel();
                district.Id         = int.Parse(item.Attribute("id").Value);
                district.Name       = item.Attribute("value").Value;
                district.DistrictID = districtID;
                list.Add(district);
            }

            return(Json(new
            {
                data = list,
                status = true
            }));
        }
Ejemplo n.º 2
0
        private void UpdateButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(VillageNameTextBox.Text))
            {
                NotificationForm notificationForm = new NotificationForm("Điền tên xã", "Cảnh báo", MessageBoxIcon.Warning);
                notificationForm.ShowDialog();
                return;
            }

            if (string.IsNullOrEmpty(AddressTextBox.Text))
            {
                NotificationForm notificationForm = new NotificationForm("Điền địa chỉ huyện", "Cảnh báo", MessageBoxIcon.Warning);
                notificationForm.ShowDialog();
                return;
            }

            if (TownComboBox.SelectedValue == null)
            {
                NotificationForm notificationForm = new NotificationForm("Chọn huyện", "Cảnh báo", MessageBoxIcon.Warning);
                notificationForm.ShowDialog();
                return;
            }

            VillageModel villageModel = new VillageModel();

            villageModel.Id          = _villageId;
            villageModel.VillageName = VillageNameTextBox.Text;
            villageModel.Address     = AddressTextBox.Text;
            villageModel.TownId      = int.Parse(TownComboBox.SelectedValue.ToString());
            villageModel.PhoneNumber = string.IsNullOrEmpty(PhoneNumberTextBox.Text) ? "" : PhoneNumberTextBox.Text;
            villageModel.Fax         = string.IsNullOrEmpty(FaxTextBox.Text) ? "" : FaxTextBox.Text;
            villageModel.Note        = string.IsNullOrEmpty(NoteRichTextBox.Text) ? "" : NoteRichTextBox.Text;
            villageModel.IsDeleted   = false;
            try
            {
                int result = managingAdministrativeBoundariesService.UpdateVillage(villageModel);
                if (result > 0)
                {
                    OnVillageUpdated();
                    NotificationForm notificationForm = new NotificationForm("Cập nhật xã thành công", "Thông báo", MessageBoxIcon.Information);
                    notificationForm.ShowDialog();
                    this.Close();
                }
                else
                {
                    NotificationForm notificationForm = new NotificationForm("Cập nhật xã không thành công", "Cảnh báo", MessageBoxIcon.Warning);
                    notificationForm.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                NotificationForm notificationForm = new NotificationForm(Common.Common.COMMON_ERORR, "Lỗi", MessageBoxIcon.Error);
                notificationForm.ShowDialog();
            }
        }
 private void UpdateVillageFromModel(Village target, VillageModel source)
 {
     target.VillageId       = source.VillageId;
     target.VillageGuid     = source.VillageGuid;
     target.TalukId         = Convert.ToInt32(source.TalukId);
     target.HobliId         = Convert.ToInt32(source.HobliId);
     target.VillageName     = source.VillageName;
     target.VillageGMapLink = source.VillageGMapLink;
     target.VillageIsActive = source.VillageIsActive;
     target.TalukName       = source.TalukName;
     target.HobliName       = source.HobliName;
 }
        public async Task <VillageModel> UpdateVillageAsync(VillageModel model)
        {
            long id = model.VillageId;

            using (var dataService = DataServiceFactory.CreateDataService())
            {
                var village = new Village();
                if (village != null)
                {
                    UpdateVillageFromModel(village, model);
                    await dataService.UpdateVillageAsync(village);

                    model.Merge(await GetVillageAsync(dataService, village.VillageId));
                }
                return(model);
            }
        }
        public static VillageModel CreateVillageModelAsync(Village source, bool includeAllFields)
        {
            var model = new VillageModel()
            {
                VillageId       = source.VillageId,
                VillageGuid     = source.VillageGuid,
                TalukId         = source.TalukId.ToString(),
                HobliId         = source.HobliId.ToString(),
                VillageName     = source.VillageName,
                VillageGMapLink = source.VillageGMapLink,
                VillageIsActive = source.VillageIsActive,
                TalukName       = source.TalukName,
                HobliName       = source.HobliName
            };

            return(model);
        }
Ejemplo n.º 6
0
        public ActionResult CreateVillage(string Id)
        {
            int villageId = DecryptQueryString(Id);

            VillageDto villageDto = new VillageDto();

            if (villageId > 0)
            {
                villageDto = _villageService.GetByID(villageId);
            }

            VillageModel objVillage = Mapper.Map <VillageDto, VillageModel>(villageDto);

            LoadDropDowns(objVillage.StateID, objVillage.DistrictID, objVillage.MandalID, objVillage.ClusterID);

            return(View(objVillage));
        }
Ejemplo n.º 7
0
        public ActionResult CreateVillage(FormCollection Form)
        {
            var resultDto = new ResultDto();

            int villageId = default(int);
            int clusterId = default(int);

            int.TryParse(Request.Form["VillageID"], out villageId);
            int.TryParse(Request.Form["ClusterID"], out clusterId);

            VillageModel objVillage = new VillageModel();

            objVillage.VillageID     = villageId;
            objVillage.ClusterID     = clusterId;
            objVillage.Village       = Convert.ToString(Request.Form["txtVillage"]);
            objVillage.TEVillageName = Convert.ToString(Request.Form["TEVillageName"]);
            objVillage.VillageCode   = Convert.ToString(Request.Form["VillageCode"]);

            if (ModelState.IsValid)
            {
                var villageDto = Mapper.Map <VillageModel, VillageDto>(objVillage);
                villageDto.UserID = UserInfo.UserID;
                if (villageDto.VillageID > 0)
                {
                    resultDto = _villageService.Update(villageDto);
                }
                else
                {
                    resultDto = _villageService.Insert(villageDto);
                }
                if (resultDto.ObjectId > 0)
                {
                    villageDto           = _villageService.GetByID(resultDto.ObjectId);
                    objVillage           = AutoMapperEntityConfiguration.Cast <VillageModel>(villageDto);
                    resultDto.ObjectCode = villageDto.VillageCode;
                }
            }

            LoadDropDowns(objVillage.StateID, objVillage.DistrictID, objVillage.MandalID, objVillage.ClusterID);
            ViewBag.Result = resultDto;
            return(View(objVillage));
        }
Ejemplo n.º 8
0
        private void EditVillageForm_Load(object sender, EventArgs e)
        {
            // load towncombobox
            List <TownModel> townModels = managingAdministrativeBoundariesService.GetAllTown();

            TownComboBox.DataSource    = townModels.ToList();
            TownComboBox.DisplayMember = "TownName";
            TownComboBox.ValueMember   = "Id";
            TownComboBox.SelectedIndex = 0;

            // load village

            VillageModel villageModel = managingAdministrativeBoundariesService.GetSingleVillageById(_villageId);

            VillageNameTextBox.Text    = villageModel.VillageName;
            AddressTextBox.Text        = villageModel.Address;
            PhoneNumberTextBox.Text    = villageModel.PhoneNumber;
            FaxTextBox.Text            = villageModel.Fax;
            NoteRichTextBox.Text       = villageModel.Note;
            TownComboBox.SelectedValue = villageModel.TownId;
        }
        public async Task <Result> DeleteVillageAsync(VillageModel model)
        {
            var village = new Village {
                VillageId = model.VillageId
            };

            using (var dataService = DataServiceFactory.CreateDataService())
            {
                try
                {
                    await dataService.DeleteVillageAsync(village);
                }
                catch (DbUpdateException ex) when(ex.InnerException is SqlException sqlException && (sqlException.Number == 547))
                {
                    return(Result.Error("Village is already in use"));
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                return(Result.Ok());
            }
        }