public ActionResult Edit(string id) { if (!IsUserLoggedIn()) { TempData["RedirectMessage"] = "Access denied. Please login."; return(RedirectToAction("Index", "Home")); } Beacon beacon = new Beacon(); if (!String.IsNullOrWhiteSpace(id)) { using (BeaconDBContext db = new BeaconDBContext()) { try { beacon = db.GetBeaconById(id); } catch (Exception e) { return(RedirectToAction("Error", "Home", new { id = 0 })); } } } return(View(beacon)); }
public ActionResult Save(Beacon beacon) { if (!IsUserLoggedIn()) { TempData["RedirectMessage"] = "Access denied. Please login."; return(RedirectToAction("Index", "Home")); } if (String.IsNullOrWhiteSpace(beacon.uuid)) { ModelState.AddModelError("uuid", "Please fill this field."); return(View("Edit", beacon)); } try { new Guid(beacon.uuid); } catch (Exception e) { ModelState.AddModelError("uuid", "UUID must have 32 characters, separated by 4 dashes."); beacon.uuid = null; return(View("Edit", beacon)); } if (String.IsNullOrWhiteSpace(beacon.Name)) { ModelState.AddModelError("Name", "Please fill this field."); return(View("Edit", beacon)); } if (String.IsNullOrWhiteSpace(beacon.Location)) { ModelState.AddModelError("Localization", "Please fill this field."); return(View("Edit", beacon)); } using (BeaconDBContext db = new BeaconDBContext()) { bool success; if (Request.Params["typeofedit"].ToString().Equals("new")) // hiddenfield can be 2 values: new, exists { success = db.AddNewBeacon(beacon); return(RedirectToAction("Index", new { result = success ? 1 : 0, add = 1 })); } success = db.EditBeacon(beacon); return(RedirectToAction("Index", new { result = success ? 1 : 0, add = 0 })); } }
// GET: Beacon public ActionResult Index() { if (!IsUserLoggedIn()) { TempData["RedirectMessage"] = "Access denied. Please login."; return(RedirectToAction("Index", "Home")); } IList <Beacon> list; using (BeaconDBContext db = new BeaconDBContext()) { list = db.GetAllBeacons(); } return(View(list)); }
public ActionResult Delete(string id) { if (!IsUserLoggedIn()) { TempData["RedirectMessage"] = "Access denied. Please login."; return(RedirectToAction("Index", "Home")); } using (BeaconDBContext db = new BeaconDBContext()) { bool success; if (String.IsNullOrWhiteSpace(id)) { return(RedirectToAction("Index", new { result = 0, delete = 1 })); } success = db.DeleteBeacon(id); return(RedirectToAction("Index", new { result = success ? 1 : 0, delete = 1 })); } }
public ActionResult Associate(int id) { ContentBeacon cb = new ContentBeacon(); List <string> availableBeacons = new List <string>(); using (BeaconDBContext db = new BeaconDBContext()) { availableBeacons = db.GetAllBeaconsIds(); } if (id < 0) { return(RedirectToAction("Error", "Home", new { id = 0 })); } if (id > 0) { using (ContentDBContext db = new ContentDBContext()) { if (db.GetContentById(id).id == 0) { return(RedirectToAction("Error", "Home", new { id = 0 })); } } using (ContentBeaconDBContext db = new ContentBeaconDBContext()) { cb = db.GetContentBeaconsById(id); availableBeacons = availableBeacons.Except(cb.BeaconIds).ToList(); } } ViewData["availableBeacons"] = availableBeacons; return(View(cb)); }