Esempio n. 1
0
        public PartialViewResult Update(int id = 0, int cityId = -1, int districtId = -1, int wardId = -1, int regionId = -1)
        {
            PlaceService  placeService  = new PlaceService();
            RegionService regionService = new RegionService();

            Models.Road_VillageModel m = new Models.Road_VillageModel();
            if (id > 0)
            {
                var road = roadService.GetById(id);
                m.MapFrom(road, ref m);
                m.DistrictId = placeService.GetParentItem(m.WardId).Id;
                m.CityId     = placeService.GetParentItem(m.DistrictId).Id;
                cityId       = m.CityId;
                districtId   = m.DistrictId;
                wardId       = m.WardId;
            }

            m.ListCity     = placeService.ListPlaceItemByParent(0);
            m.ListDistrict = placeService.ListPlaceItemByParent(cityId);
            m.ListWard     = placeService.ListPlaceItemByParent(districtId);
            m.ListRegion   = regionService.List();

            LoadData();

            ViewBag.ListRoad   = roadService.ListItem(wardId, regionId);
            ViewBag.ActionForm = "Update";
            return(PartialView("index", m));
        }
Esempio n. 2
0
 public void MapFrom(Entities.Road_Village e, ref Models.Road_VillageModel m)
 {
     m.Id          = e.Id;
     m.Text        = e.Text;
     m.Description = e.Description;
     m.Type        = e.Type;
     m.WardId      = e.WardId;
     m.RegionId    = e.RegionId;
 }
Esempio n. 3
0
 public void MapFrom(Models.Road_VillageModel m, ref Entities.Road_Village e)
 {
     e.Id          = m.Id;
     e.Text        = m.Text;
     e.Description = m.Description;
     e.Type        = m.Type;
     e.WardId      = m.WardId;
     e.RegionId    = m.RegionId;
 }
Esempio n. 4
0
        public ActionResult Update(int id, Models.Road_VillageModel m)
        {
            if (ModelState.IsValid)
            {
                Entities.Road_Village e = new Entities.Road_Village();
                m.MapFrom(m, ref e);
                int result = 0;
                if (id > 0)
                {
                    result = roadService.Update(e);
                }
                else
                {
                    result = roadService.Insert(e);
                }
                if (result <= 0)
                {
                    ViewBag.Message    = AdminConfigs.MESSAGE_UPDATE_ERROR;
                    ViewBag.AlertClass = AdminConfigs.CLASS_ALERT_DANGER;
                    return(PartialView("index", m));
                }
                else
                {
                    ViewBag.AlertClass = AdminConfigs.CLASS_ALERT_SUCCESS;
                    ViewBag.Message    = AdminConfigs.MESSAGE_UPDATE_SUCCESS;
                    ModelState.Clear();

                    //
                    // Xóa đi những thông tin vừa được cập nhật tránh trường hợp click 2 lần.
                    m.Text        = "";
                    m.Description = "";
                }
            }
            else
            {
            }

            PlaceService  placeService  = new PlaceService();
            RegionService regionService = new RegionService();

            m.ListCity     = placeService.ListPlaceItemByParent(0);
            m.ListDistrict = placeService.ListPlaceItemByParent(m.CityId);
            m.ListWard     = placeService.ListPlaceItemByParent(m.DistrictId);
            m.ListRegion   = regionService.List();
            LoadData();
            ViewBag.ListRoad   = roadService.ListItem(m.WardId, m.RegionId);
            ViewBag.ActionForm = "Update";
            return(PartialView("index", m));
        }