public ActionResult Details(string id) { if (String.IsNullOrEmpty(id)) { return RedirectToAction("Index","Home"); } ApplicationDbContext db = new ApplicationDbContext(); var u = db.AppUsers.Find(User.Identity.GetUserId()); var s = db.Sessions.Where(q => q.CustomURL == id).FirstOrDefault(); if (s == null) { int i = 0; if (int.TryParse(id,out i)){ s = db.Sessions.Where(q => q.IID == i).FirstOrDefault(); if (s == null) return HttpNotFound(); } } var sm = new SessionModalView() { Session = s, AppUser = u }; if (u != null) { db.Entry(u).Collection(c => c.Sessions).Load(); List<int> ls = new List<int>(); foreach (var ses in u.Sessions) { ls.Add(ses.IID); } sm.alreadyAdded = ls.Contains(s.IID); } return View(sm); }
public ActionResult DetailsModal(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ApplicationDbContext db = new ApplicationDbContext(); var s = db.Sessions.Where(q => q.IID == id).FirstOrDefault(); var u = db.AppUsers.Find(User.Identity.GetUserId()); if (s == null) { return HttpNotFound(); } var sm = new SessionModalView() { Session = s, AppUser = u }; if (u != null) { db.Entry(u).Collection(c => c.Sessions).Load(); List<int> ls = new List<int>(); foreach (var ses in u.Sessions) { ls.Add(ses.IID); } sm.alreadyAdded = ls.Contains(s.IID); } return View(sm); }