// GET: Events/Create
 public ActionResult Create(List<int> roomNum, List<int> options, string name, int? attendeeCountDGS, int? attendeeCountNonDGS, DateTime? startTime, DateTime? endTime)
 {
     TempData["ReturnPath"] = Request.UrlReferrer;
     EventViewModel model = new EventViewModel();
     Event e = new Event {
         attendeeCount = attendeeCountDGS + attendeeCountNonDGS,
         attendeeCountDGS = attendeeCountDGS,
         attendeeCountNonDGS = attendeeCountNonDGS,
         name = name ?? string.Empty,
         startTime = startTime ?? DateTime.Now,
         endTime = endTime ?? DateTime.Now,
         created = DateTime.Now,
         createdBy = Helpers.Helpers.GetUser(User.Identity).loginName,
         modified = DateTime.Now,
         modifiedBy = Helpers.Helpers.GetUser(User.Identity).loginName
     };
     model.Event = e;
     roomNum = roomNum ?? new List<int>();
     options = options ?? new List<int>();
     model.LocationList = Helpers.Helpers.GetLocationList(roomNum);
     model.OptionList = Helpers.Helpers.GetOptionList(options);
     //ViewBag.LocationList = new SelectList(db.Locations.OrderBy(l => l.name), "locationId", "name");
     //ViewBag.LocationList = Helpers.Helpers.GetLocationList(roomNum);
     //ViewBag.EventEventOptions = new SelectList(db.Options.OrderBy(o => o.name), "optionId", "name");
     List<SelectListItem> users = Helpers.Helpers.GetUserSelectList();
     model.UserList = users;
     //ViewBag.owner = users;
     //ViewBag.organizer = users; 
     return View(model);
 }
 // GET: Events/Details/5
 public async Task<ActionResult> Details(int? id)
 {
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Event @event = await db.Events.FindAsync(id);
     if (@event == null)
     {
         return HttpNotFound();
     }
     EventViewModel model = new EventViewModel
     {
         Event = @event,
         LocationList = Helpers.Helpers.GetLocationList(@event.Locations.Select(l => l.locationId).ToList()),
         OptionList = Helpers.Helpers.GetOptionList(@event.Locations.Select(l => l.locationId).ToList())
     };
     return View(model);
 }
        public String AsyncCreate(EventViewModel ev, List<ReservationRequest> reservations, List<int> EventLocations, List<int> EventOption)
        {
            var returnPath = TempData["ReturnPath"] ?? Request.UrlReferrer;
            var user = Helpers.Helpers.GetUser(User.Identity).loginName;
            EventLocations = EventLocations ?? new List<int>();
            EventOption = EventOption ?? new List<int>();
            try
            {
                foreach (var r in reservations)
                {
                    foreach (var reservation in r.GetReservations(db))
                    {
                        var thisReservation = reservation.Reservation;
                        thisReservation.ReservationNotes.Add(new ReservationNote { 
                            created = DateTime.Now,
                            createdBy = user,
                            note = ev.Event.notes
                        });
                        thisReservation.created = DateTime.Now;
                        thisReservation.createdBy = user;
                        thisReservation.modified = DateTime.Now;
                        thisReservation.modifiedBy = user;
                        ev.Event.Reservations.Add(thisReservation);
                    }
                    //r.GetReservations().ForEach(rr => ev.Reservations.Add(rr.Reservation));
                }
                foreach (var location in EventLocations)
                {
                    ev.Event.Locations.Add(db.Locations.Find(location));
                }
                foreach (var option in EventOption)
                {
                    ev.Event.Options.Add(db.Options.Find(option));
                }
                db.Events.Add(ev.Event);
                db.SaveChanges();
                if (returnPath != null)
                {
                    return returnPath.ToString();
                }
                return "Success";

            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbex)
            {
                return "Oops. Looks like you're missing some information";
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }
        public async Task<ActionResult> Edit(EventViewModel model)
        {
            var returnPath = TempData["ReturnPath"] ?? Request.UrlReferrer;

            if (ModelState.IsValid)
            {
                db.Entry(model.Event).State = EntityState.Modified;
                await db.SaveChangesAsync();     
                return Redirect(returnPath.ToString());
            }
            return View(model);
        }
 // GET: Events/Edit/5
 public async Task<ActionResult> Edit(int? id)
 {
     TempData["ReturnPath"] = Request.UrlReferrer;
     EventViewModel model = new EventViewModel();
     if (id == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     Event @event = await db.Events.FindAsync(id);
     if (@event == null)
     {
         return HttpNotFound();
     }
     model.Event = @event;
     model.UserList = Helpers.Helpers.GetUserSelectList(); ;
     return View(model);
 }