예제 #1
0
 public void Save(Precinct obj)
 {
     if (obj.Id == 0)
         context.Entry(obj).State = System.Data.Entity.EntityState.Added;
     else
         context.Entry(obj).State = System.Data.Entity.EntityState.Modified;
     context.SaveChanges();
 }
예제 #2
0
 public ActionResult Create(Precinct obj, FormCollection collection)
 {
     //if (ModelState.IsValid)
     //{
     //    if (!dataManager.Precincts.GetAll()
     //        .Where(m => m.DistrictId == obj.DistrictId)
     //        .Any(o => o.Name == obj.Name))
     //    {
     //        dataManager.Precincts.Save(obj);
     //        return RedirectToAction("Show", new { Id = obj.Id });
     //    }
     //    else
     //        ModelState.AddModelError("Name",
     //            "УИК с названием \"" + obj.Name + "\" уже существует!");
     //}
     //ViewBag.Districts = from d in dataManager.Districts.GetAll()
     //                    select new SelectListItem
     //                    {
     //                        Text = d.Name,
     //                        Value = d.Id.ToString(),
     //                        Selected = obj.DistrictId == d.Id
     //                    };
     //var workers = new List<SelectListItem>
     //{
     //    new SelectListItem()
     //};
     //workers.AddRange(from w in dataManager.Workers.GetAll()
     //                 select new SelectListItem
     //                 {
     //                     Text = dataManager.Persons.Get(w.PersonId ?? 0).FullName,
     //                     Value = w.Id.ToString(),
     //                     Selected = w.Id == obj.WorkerId
     //                 });
     //ViewBag.Workers = workers;
     //return View(obj);
     string latitude = collection["Latitude"];
     string longitude = collection["Longitude"];
     if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude))
     {
         obj.Latitude = double.Parse(latitude.Replace('.', ','));
         obj.Longitude = double.Parse(longitude.Replace('.', ','));
     }
     dataManager.Precincts.Save(obj);
     return RedirectToAction("Show", new { Id = obj.Id });
 }
예제 #3
0
 public ActionResult Edit(Precinct obj, FormCollection collection)
 {
     string latitude = collection["Latitude"];
     string longitude = collection["Longitude"];
     if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude))
     {
         obj.Latitude = double.Parse(latitude.Replace('.', ','));
         obj.Longitude = double.Parse(longitude.Replace('.', ','));
     }
     dataManager.Precincts.Save(obj);
     return RedirectToAction("Show", new { Id = obj.Id });
 }
예제 #4
0
 public ActionResult SetMapPosition(Precinct obj/*FormCollection collection*/)
 {
     /*string latitude = collection["Latitude"];
     string longitude = collection["Longitude"];
     string zoom = collection["Zoom"];
     string iconPath = collection["IconPath"];
     int id = int.Parse(collection["Id"]);
     if (!string.IsNullOrEmpty(latitude) && !string.IsNullOrEmpty(longitude))
     {
         var objFromDb = dataManager.Precincts.Get(id);
         objFromDb.Latitude = double.Parse(latitude.Replace('.', ','));
         objFromDb.Longitude = double.Parse(longitude.Replace('.', ','));
         objFromDb.Zoom = int.Parse(zoom);
         objFromDb.IconPath = iconPath;
         dataManager.Precincts.Save(objFromDb);
     }*/
     return View("Error");
 }
예제 #5
0
        public ActionResult CreatePartial(Precinct obj)
        {
            if (Request.IsAjaxRequest())
            {
                dataManager.Precincts.Save(obj);

                return Json(new { Name = obj.Name, Id = obj.Id, Key = "PrecinctId2" }, JsonRequestBehavior.AllowGet);
            }
            return Json("", JsonRequestBehavior.AllowGet);
        }