コード例 #1
0
        /// <summary>
        /// An action returning a page used to create a meeting list
        /// </summary>
        /// <param name="id">The event to create the list for</param>
        /// <returns>if the user owns the event: Returns a page where the user can create a meeting list</returns>
        public ActionResult CreateList(int id)
        {
            MeetupModel model = new MeetupModel();

            //Checks if the user owns the event or not
            int?  infoID   = this.UserId();
            Event theEvent = model.Events.SingleOrDefault(e => e.Id == id && e.HostUserId == infoID);

            if (theEvent is null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            EventListCreationModel viewModel = new EventListCreationModel();

            viewModel.EventInformation = theEvent;
            viewModel.EventId          = theEvent.Id;

            if (viewModel.EventInformation.Invites.Count < 2)
            {
                return(View("NotEnoughPeople", viewModel));
            }

            return(View(viewModel));
        }
コード例 #2
0
        public ActionResult CreateList(EventListCreationModel viewModel)
        {
            MeetupModel model = new MeetupModel();

            //Makes sure the user owns the event
            int?infoID = this.UserId();

            viewModel.EventInformation = model.Events.SingleOrDefault(e => e.Id == viewModel.EventId && e.HostUserId == infoID);
            if (viewModel.EventInformation is null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            //Make sure there are enough people
            if (viewModel.EventInformation.Invites.Count < 2)
            {
                return(View("NotEnoughPeople", viewModel));
            }

            //Creates a list of all users in the event
            List <User> UsersInEvent = viewModel.EventInformation.GetUsers().ToList();

            //Clear old meeting list
            foreach (Seance meetingRow in viewModel.EventInformation.Seances)
            {
                model.Meetings.RemoveRange(meetingRow.Meetings);
                model.UserPauses.RemoveRange(meetingRow.UserPauses);
            }
            model.Seances.RemoveRange(viewModel.EventInformation.Seances);

            //Get list of all possible meetings
            List <MeetingScore> possibleMeetings = MeetingScore.GetPossibleMeetings(UsersInEvent, viewModel.EventId);

            //Generate Seances/meetings list
            int meetingsPerSeance = UsersInEvent.Count / 2;

            for (int i = 0; i < viewModel.AmountOfMeetings && possibleMeetings.Count != 0; i++)
            {
                //Create a meeting row (seance)
                List <MeetingScore> possibleMeetingsThisRow = possibleMeetings.Where(m => true).ToList();
                List <User>         usersNotInMeeting       = UsersInEvent.Where(u => true).ToList();
                DateTime            beginningTime           = viewModel.EventInformation.BeginningTime.AddMinutes(viewModel.MinuteInterval * i);
                Seance eventMeetingsRow = new Seance(viewModel.EventInformation, i, beginningTime, beginningTime.AddMinutes(viewModel.MinuteInterval));

                for (int j = 0; j < meetingsPerSeance; j++)
                {
                    if (possibleMeetingsThisRow.Count == 0)
                    {
                        //fill with already used meetings if turned on
                        if (viewModel.ForceFillMeetings && usersNotInMeeting.Count >= 2)
                        {
                            possibleMeetingsThisRow = MeetingScore.GetPossibleMeetings(usersNotInMeeting, viewModel.EventId);
                        }
                        else
                        {
                            //Create list of users not in meetings in this seance
                            foreach (User userNotInMeeting in usersNotInMeeting)
                            {
                                eventMeetingsRow.UserPauses.Add(new UserPause(userNotInMeeting, eventMeetingsRow));
                            }
                            break;
                        }
                    }

                    //add highest scored meeting to the event
                    MeetingScore meetingToAdd = possibleMeetingsThisRow[0];

                    //remove impossible meetings (meetings containing the users who just have been added to the meeting list)
                    eventMeetingsRow.Meetings.Add(new Meeting(meetingToAdd.Person1, meetingToAdd.Person2, eventMeetingsRow));
                    possibleMeetingsThisRow = possibleMeetingsThisRow.Where(m => m.Person1.Id != meetingToAdd.Person1.Id && m.Person2.Id != meetingToAdd.Person2.Id && m.Person1.Id != meetingToAdd.Person2.Id && m.Person2.Id != meetingToAdd.Person1.Id).ToList();
                    usersNotInMeeting       = usersNotInMeeting.Where(u => u.Id != meetingToAdd.Person1.Id && u.Id != meetingToAdd.Person2.Id).ToList();
                    possibleMeetings.Remove(meetingToAdd);
                }

                viewModel.EventInformation.Seances.Add(eventMeetingsRow);
            }

            model.SaveChanges();

            return(RedirectToAction("Page", new { Id = viewModel.EventId }));
        }