private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckInputs(txtTitle))
                {
                    throw new Exception("Please enter Title");
                }
                //if (!CheckInputs(txtRoomSize))
                //{
                //    throw new Exception("Please enter Room Size");
                //}
                if (!CheckInputs(txtDuration))
                {
                    throw new Exception("Please enter Duration");
                }
                Seminar seminar;
                List <AudiencePerSeminar>   audiencePerSeminars   = new List <AudiencePerSeminar>();
                List <PresentersPerSeminar> presentersPerSeminars = new List <PresentersPerSeminar>();
                if (seminarId > 0)
                {
                    seminar               = db.Seminars.Find(seminarId);
                    audiencePerSeminars   = seminar.AudiencePerSeminars;
                    presentersPerSeminars = seminar.PresentersPerSeminars;
                }
                else
                {
                    seminar = new Seminar();
                    //audiencePerSeminars = new List<AudiencePerSeminar>();
                    //presentersPerSeminars = new List<PresentersPerSeminar>();
                    if (CheckSeminarExists(GetSeminarStartDateTime(), GetSeminarEndDateTime()))
                    {
                        throw new Exception("There is already a seminar in this time");
                    }
                }
                seminar.Title               = txtTitle.Text;
                seminar.SeminarDateTime     = GetSeminarStartDateTime();
                seminar.RoomStallLocationId = Convert.ToInt32(cbRoom.SelectedValue);
                //seminar.RoomStallLocation = db.RoomStallLocations.Find(Convert.ToInt32(cbRoom.SelectedValue));
                seminar.Duration = Convert.ToInt32(txtDuration.Text);


                foreach (int id in attendeeIds)
                {
                    AudiencePerSeminar audiencePerSeminar = new AudiencePerSeminar();
                    audiencePerSeminar.Attendee = db.Attendees.Find(id);
                    audiencePerSeminar.Seminar  = seminar;
                    var attendee = audiencePerSeminars.Where(aps => aps.AttendeeId == id).FirstOrDefault();

                    if (attendee == null)
                    {
                        audiencePerSeminars.Add(audiencePerSeminar);
                    }
                }

                foreach (int id in presenterIds)
                {
                    PresentersPerSeminar presentersPerSeminar = new PresentersPerSeminar();
                    presentersPerSeminar.Presenter = db.Attendees.Find(id);
                    presentersPerSeminar.Seminar   = seminar;
                    var presenter = presentersPerSeminars.Where(aps => aps.AttendeeId == id).FirstOrDefault();
                    if (presenter == null)
                    {
                        presentersPerSeminars.Add(presentersPerSeminar);
                    }
                }

                //if (audiencePerSeminars.Count < 1)
                //{
                //    throw new Exception("Please add Audience");
                //}
                //if (presentersPerSeminars.Count < 1)
                //{
                //    throw new Exception("Please add Presenter");
                //}

                seminar.AudiencePerSeminars = audiencePerSeminars;
                if (seminar.AudiencePerSeminars.Count > db.RoomStallLocations.Find(cbRoom.SelectedValue).Capacity)
                {
                    throw new Exception("Room Capacity is Full");
                }
                seminar.PresentersPerSeminars = presentersPerSeminars;

                if (seminarId > 0)
                {
                    db.Seminars.Attach(seminar);
                }
                else
                {
                    db.Seminars.Add(seminar);
                }
                db.SaveChanges();
                MessageBox.Show("Seminar successfully added");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnAddSeminar_Click(object sender, EventArgs e)
        {
            try
            {
                if (!CheckInput(txt_Title))
                {
                    throw new Exception("Please enter Title");
                }
                if (!CheckInput(txt_Duration))
                {
                    throw new Exception("Please enter Duration");
                }
                Seminar seminar;
                List <AudiencePerSeminar>  audienceSeminars  = new List <AudiencePerSeminar>();
                List <PresenterPerSeminar> presenterSeminars = new List <PresenterPerSeminar>();
                if (seminarId > 0)
                {
                    seminar           = db.Seminars.Find(seminarId);
                    audienceSeminars  = seminar.AudienceSeminars;
                    presenterSeminars = seminar.PresenterSeminars;
                }
                else
                {
                    seminar = new Seminar();
                    if (CheckSeminar(getSeminarStartDateTime(), getSeminarEndDateTime()))
                    {
                        throw new Exception("Time is already booked for another seminar");
                    }
                }
                seminar.SeminarTitle     = txt_Title.Text;
                seminar.SeminarStartTime = getSeminarStartDateTime();
                seminar.RoomId           = Convert.ToInt32(cmb_Room.SelectedValue);
                seminar.Duration         = Convert.ToInt32(txt_Duration.Text);


                foreach (int id in attendeeIds)
                {
                    AudiencePerSeminar audienceSeminar = new AudiencePerSeminar();
                    audienceSeminar.Attendee = db.Attendees.Find(id);
                    audienceSeminar.Seminar  = seminar;
                    var attendeeCheck = audienceSeminars.Where(au => au.AttendeeId == id).FirstOrDefault();

                    if (attendeeCheck == null)
                    {
                        audienceSeminars.Add(audienceSeminar);
                    }
                }

                foreach (int id in presenterIds)
                {
                    PresenterPerSeminar presenterSeminar = new PresenterPerSeminar();
                    presenterSeminar.Presenter = db.Attendees.Find(id);
                    presenterSeminar.Seminar   = seminar;
                    var presenter = presenterSeminars.Where(pa => pa.AttendeeId == id).FirstOrDefault();
                    if (presenter == null)
                    {
                        presenterSeminars.Add(presenterSeminar);
                    }
                }
                if (audienceSeminars.Count < 1)
                {
                    throw new Exception("Please add Audience");
                }
                if (presenterSeminars.Count < 1)
                {
                    throw new Exception("Please add Presenter");
                }
                seminar.AudienceSeminars = audienceSeminars;
                if (seminar.AudienceSeminars.Count > db.Rooms.Find(cmb_Room.SelectedValue).Capacity)
                {
                    throw new Exception("Max room capacity");
                }
                seminar.PresenterSeminars = presenterSeminars;

                if (seminarId > 0)
                {
                    db.Seminars.Attach(seminar);
                }
                else
                {
                    db.Seminars.Add(seminar);
                }
                db.SaveChanges();
                MessageBox.Show("Seminar successfully added");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }