Ejemplo n.º 1
0
 public ActionResult Create(Street obj)
 {
     if (ModelState.IsValid)
     {
         if (!dataManager.Streets.GetAll()
             .Where(m => m.DistrictId == obj.DistrictId)
             .Any(o => o.Name == obj.Name))
         {
             dataManager.Streets.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.HasValue ? obj.DistrictId.Value == d.Id : false
                         };
     if (obj.LocalityId.HasValue)
     {
         var locality = dataManager.Localities.Get(obj.LocalityId.Value);
         ViewBag.Locality = locality;
     }
     return View(obj);
 }
Ejemplo n.º 2
0
 public void Save(Street 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();
 }
Ejemplo n.º 3
0
 public ActionResult Create(int? districtId, int? localityId)
 {
     var model = new Street();
     if (localityId.HasValue)
     {
         var locality = dataManager.Localities.Get(localityId.Value);
         model.LocalityId = locality.Id;
         districtId = locality.DistrictId;
         ViewBag.Locality = locality;
     }
     ViewBag.Districts = from d in dataManager.Districts.GetAll()
                         select new SelectListItem
                         {
                             Text = d.Name,
                             Value = d.Id.ToString(),
                             Selected = districtId.HasValue ? districtId.Value == d.Id : false
                         };
     return View(model);
 }
Ejemplo n.º 4
0
 int GetStreetId(int districtId, string streetName)
 {
     var streets = dataManager.Streets.GetAll().Where(s => s.DistrictId == districtId).ToList();
     foreach (var street in streets)
     {
         if (street.Name.StartsWith(streetName)) return street.Id;
     }
     var newStreet = new Street
     {
         DistrictId = districtId,
         Name = streetName
     };
     dataManager.Streets.Save(newStreet);
     return newStreet.Id;
 }
Ejemplo n.º 5
0
 public ActionResult Edit(Street obj)
 {
     if (ModelState.IsValid)
     {
         if (!dataManager.Streets.GetAll()
             .Where(m => m.DistrictId == obj.DistrictId)
             .Any(o => o.Name == obj.Name))
         {
             var objFromDb = dataManager.Streets.Get(obj.Id);
             objFromDb.Name = obj.Name;
             objFromDb.DistrictId = obj.DistrictId;
             objFromDb.LocalityId = obj.LocalityId;
             dataManager.Streets.Save(objFromDb);
             return RedirectToAction("Show", new { Id = obj.Id });
         }
         else
         {
             ModelState.AddModelError("Name",
                 "Улица с названием \"" + obj.Name + "\" уже существует!");
             return View(obj);
         }
     }
     return View(obj);
 }
Ejemplo n.º 6
0
        public ActionResult CreatePartial(Street obj)
        {
            if (Request.IsAjaxRequest())
            {
                dataManager.Streets.Save(obj);

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