public ActionResult Create()
        {
            var meetRSVP = new MeetingUserRSVP();

            PopulateAssignedMeetings(meetRSVP);
            PopulateAssignedUsers(meetRSVP);
            return(View());
        }
 public ActionResult Edit([Bind(Include = "ID,ComingYorN,RSVPNotes")] MeetingUserRSVP meetingUserRSVP)
 {
     if (ModelState.IsValid)
     {
         db.Entry(meetingUserRSVP).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(meetingUserRSVP));
 }
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MeetingUserRSVP meetingUserRSVP = db.MeetingUserRSVPs.Find(id);

            if (meetingUserRSVP == null)
            {
                return(HttpNotFound());
            }
            return(View(meetingUserRSVP));
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            MeetingUserRSVP MuRSVP = db.MeetingUserRSVPs.Include(m => m.MeetingRSVP).Include(u => u.AppUser).Where(i => i.ID == id).Single();

            if (MuRSVP == null)
            {
                return(HttpNotFound());
            }
            return(View(MuRSVP));
        }
        //// GET: MeetingUserRSVPs/Delete/5
        //public ActionResult Delete(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    MeetingUserRSVP meetingUserRSVP = db.MeetingUserRSVPs.Find(id);
        //    if (meetingUserRSVP == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(meetingUserRSVP);
        //}

        //// POST: MeetingUserRSVPs/Delete/5
        //[HttpPost, ActionName("Delete")]
        //[ValidateAntiForgeryToken]
        //public ActionResult DeleteConfirmed(int id)
        //{
        //    MeetingUserRSVP meetingUserRSVP = db.MeetingUserRSVPs.Find(id);
        //    db.MeetingUserRSVPs.Remove(meetingUserRSVP);
        //    db.SaveChanges();
        //    return RedirectToAction("Index");
        //}

        public void PopulateAssignedMeetings(MeetingUserRSVP meetings)
        {
            var allMeetings = db.Meetings;
            var veiwModel   = new List <MettingVM>();

            foreach (var m in allMeetings)
            {
                veiwModel.Add(new MettingVM
                {
                    MeetingId   = m.ID,
                    MeetingName = m.EventTitle,
                    MeetingDesc = m.DescriptionTrimmed
                });
            }

            ViewBag.Meeting = veiwModel;
        }
        public void PopulateAssignedUsers(MeetingUserRSVP meetings)
        {
            var allUsers  = db.Users;
            var viewModel = new List <UserVM>();

            foreach (var m in allUsers)
            {
                viewModel.Add(new UserVM
                {
                    UserID       = m.Id,
                    UserFName    = m.UserFName,
                    UserLName    = m.UserLName,
                    UserFullName = m.UserFName + " " + m.UserLName + ", " + m.UserName
                });
            }

            ViewBag.User = viewModel;
        }
        public ActionResult Create([Bind(Include = "ID,ComingYorN,RSVPNotes")] MeetingUserRSVP meetingUserRSVP, string[] selectedMeetings, string[] selectedUsers)
        {
            if (selectedMeetings != null)
            {
                foreach (var m in selectedMeetings)
                {
                    var meetingToAdd = db.Meetings.Find(int.Parse(m));
                    //meetingUserRSVP.MeetingRSVP = meetingToAdd;

                    if (selectedUsers != null)
                    {
                        foreach (var u in selectedUsers)
                        {
                            var userToAdd = db.Users.Find(u);
                            if (!db.MeetingUserRSVPs.Any(us => us.AppUser.Id == u && us.MeetingRSVP.ID == meetingToAdd.ID))
                            {
                                meetingUserRSVP.MeetingRSVP = meetingToAdd;
                                meetingUserRSVP.AppUser     = userToAdd;
                                db.MeetingUserRSVPs.Add(meetingUserRSVP);
                                db.SaveChanges();
                            }
                            else
                            {
                                ModelState.AddModelError("", "User " + userToAdd.UserFName + " " + userToAdd.UserLName + " has already been sent RSVP for this event");
                            }
                        }
                    }
                }
            }



            if (ModelState.IsValid)
            {
                //PopulateAssignedMeetings(meetingUserRSVP);
                //PopulateAssignedUsers(meetingUserRSVP);
                return(RedirectToAction("AdminList"));
            }
            PopulateAssignedMeetings(meetingUserRSVP);
            PopulateAssignedUsers(meetingUserRSVP);
            return(View(meetingUserRSVP));
        }