public ActionResult Events() { if (User.IsInRole("Admin")) { return(RedirectToAction("Index", "Admin")); } var records = _repo.Retrieve(); var eventList = new List <EventViewModel>(); foreach (var item in records) { var newEvent = new EventViewModel() { EventId = item.EventId, Description = item.Description, EventDate = item.EventDate, Name = item.Name, LocationName = db.Locations.Where(l => l.LocationId == item.LocationId).FirstOrDefault().Name, WallpaperContent = db.Photos.Where(p => p.EventId == item.EventId).FirstOrDefault().Content }; eventList.Add(newEvent); } return(View(eventList)); }
// GET: Events public ActionResult Index() { try { if (User.IsInRole("Admin")) { var records = _repo.Retrieve(); if (records == null) { return(RedirectToAction("Error404", "Home")); } return(View(records)); } return(RedirectToAction("Login", "Account")); } catch (Exception ex) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString())); } }