Пример #1
0
        public ActionResult Create(RegionModel model)
        {
            var cityId = Request.Form["CityId"];
            if (!string.IsNullOrEmpty(cityId))
            {
                model = new RegionModel();
                model.Region.CityId = Convert.ToInt32(cityId);
                model.Districts = m_merkezDC.Districts.Where(x => x.CityId == cityId &&
                                                                x.DistrictStatus==true).ToList();
            }

            if (model.SelectedDistricts.Count > 0)
            {
                var region = model.Region;
                m_merkezDC.Regions.InsertOnSubmit(region);
                m_merkezDC.SubmitChanges();

                foreach (var district_id in model.SelectedDistricts)
                {
                    var region_detail = new RegionDetail();
                    region_detail.DistrictId = district_id;
                    region_detail.RegionId = region.RegionId;
                    region_detail.RegionStatus = true;
                    m_merkezDC.RegionDetails.InsertOnSubmit(region_detail);

                    var old_district = m_merkezDC.Districts.First(f => f.DistrictId == district_id);
                    old_district.DistrictStatus = false;
                    m_merkezDC.SubmitChanges();
                }
                ViewData["Message"] = "Seçim Bölgesi Başarıyla Oluşturuldu.";
                return RedirectToAction("List");
            }

            return View(model);
        }
Пример #2
0
 partial void DeleteRegionDetail(RegionDetail instance);
Пример #3
0
 partial void UpdateRegionDetail(RegionDetail instance);
Пример #4
0
 partial void InsertRegionDetail(RegionDetail instance);
Пример #5
0
        public ActionResult Edit(RegionModel model)
        {
            var region = m_merkezDC.Regions.First(f => f.RegionId == model.Region.RegionId);
            region.Region1 = model.Region.Region1;
            region.CandidateCount = model.Region.CandidateCount;

            var regionDetails = m_merkezDC.RegionDetails.Where(r => r.RegionId == model.Region.RegionId).ToList();
            m_merkezDC.RegionDetails.DeleteAllOnSubmit(regionDetails);
            foreach (var districtId in model.SelectedDistricts)
            {
                var regionDetail = new RegionDetail();
                regionDetail.RegionId = model.Region.RegionId;
                regionDetail.DistrictId = districtId;
                regionDetail.RegionStatus = true;
                m_merkezDC.RegionDetails.InsertOnSubmit(regionDetail);
            }
            m_merkezDC.SubmitChanges();
            return RedirectToAction("List");
        }