public ActionResult Delete(ZoneModel m) { try { DataRepository.DeleteZone((int)m.id); return RedirectToAction("Index"); } catch { ViewBag.active_menu_item_id = "menu-btn-zones"; return View(m); } }
public ActionResult Create(ZoneModel m) { try { if (!ModelState.IsValid) { throw new Exception(); } DataRepository.InsertZone(m); return RedirectToAction("Index"); } catch { ViewBag.active_menu_item_id = "menu-btn-zones"; return View(); } }
/// <summary> /// Updates a dangerous zone /// </summary> /// <param name="m"></param> public static void UpdateZone(ZoneModel m) { var db = new BicikliDataClassesDataContext(); var zoneToUpdate = db.DangerousZones.Single(z => z.id == m.id); if (zoneToUpdate.description != m.description) { zoneToUpdate.description = m.description; } if (zoneToUpdate.latitude != m.latitude) { zoneToUpdate.latitude = m.latitude; } if (zoneToUpdate.longitude != m.longitude) { zoneToUpdate.longitude = m.longitude; } if (zoneToUpdate.name != m.name) { zoneToUpdate.name = m.name; } if (zoneToUpdate.radius != m.radius) { zoneToUpdate.radius = m.radius; } db.SubmitChanges(); }
/// <summary> /// Inserts a new Zone into the database /// </summary> /// <param name="m"></param> /// <returns></returns> public static int InsertZone(ZoneModel m) { var db = new BicikliDataClassesDataContext(); var zoneToInsert = new DangerousZone() { description = m.description, latitude = m.latitude, longitude = m.longitude, name = m.name, radius = m.radius }; db.DangerousZones.InsertOnSubmit(zoneToInsert); db.SubmitChanges(); return zoneToInsert.id; }
public ActionResult Edit(ZoneModel m) { try { if (!ModelState.IsValid) { throw new Exception(); } DataRepository.UpdateZone(m); return RedirectToAction("Index"); } catch { ViewBag.active_menu_item_id = "menu-btn-zones"; ViewBag.Sessions = DataRepository.GetSessions().Where(s => (s.endTime == null) && (s.dangerousZoneId == m.id)).ToList(); return View(m); } }