public ActionResult SchedTutor(ProposedSchedule schedule)
        {
            schedule.UserName  = TempData["SearchedTutor"] as string;
            schedule.UserEmail = TempData["SearchedTutorEmail"] as string;


            var notification = new Notification()
            {
                Notificationtype = Notificationtype.ScheduleProposiotion,
                NotificationData = schedule.ScheduleAsString,
                Message          = "You have been hired",
                ActionLink       = "/Home/Index",
                Key = schedule.UserEmail
            };

            if (new NotificationService().Add(notification))
            {
            }

            //send a notification to tutor
            var t       = new ServiceProvider().Create <Tutor>().GetByEmail(schedule.UserEmail);
            var student = new ServiceProvider().Create <Student>().GetByEmail(Session["Key"] as string);


            if (!t.Students.Contains(student))
            {
                t.Students.Add(student);
            }

            t.Schedules.Add(schedule);
            if (new ServiceProvider().Create <Tutor>().Update(t))
            {
            }

            student = new ServiceProvider().Create <Student>().GetByEmail(Session["Key"] as string);
            student.Schedules.Add(schedule);
            if (!student.Tutors.Contains(t))
            {
                student.Tutors.Add(t);

                new ServiceProvider().Create <Student>().Update(student);
            }


            return(RedirectToAction("HireTutor", "Student"));
        }
Exemple #2
0
 public ActionResult ScheduleProp(ProposedSchedule schedule)
 {
     return(View());
 }
        /// <summary>
        /// Create a proposed Schedule and save it to the database based on elements already in the database
        /// </summary>
        /// <param name="eventDate">Date of the event that the schedule will be created for</param>
        public static bool CreateProposedSchedule(DateTime eventDate)
        {
            try
            {
                // Ensure the Event Date does not have an unnecessary time added
                eventDate = eventDate.Date;

                // Get the talkIDs and order them by decreasing count
                var cachedTalks = DATABASE.Talks.Where(talk => talk.DateGiven == eventDate).Select(talk => talk.ID).ToList();
                var talks       = (from talkID in cachedTalks
                                   let count = DATABASE.TalkInterest.Count(interest => interest.TalkID == talkID)
                                               orderby count descending
                                               select talkID).ToList();

                // Get the existing ProposedSchedule entries
                var schedulesForDate = (from sched in DATABASE.ProposedSchedules
                                        join session in DATABASE.Sessions on sched.SessionID equals session.ID
                                        where session.SessionDate == eventDate
                                        select sched).ToList();

                // If there are any existing schedules for this date, warn the user that creating a new one will overwrite the existing one
                if (schedulesForDate.Any())
                {
                    var result = MessageBox.Show("A proposed schedule already exists. Generating a new one will overwrite the old. Continue?",
                                                 "Existing Proposed Schedule", MessageBoxButton.OKCancel);

                    if (result == MessageBoxResult.Cancel)
                    {
                        return(false);
                    }

                    // Delete the existing schedule for the eventDate to overwrite them
                    DATABASE.ProposedSchedules.DeleteAllOnSubmit(schedulesForDate);
                }

                // Combine the Rooms and Sessions to create each unique combination
                var roomSessions = (from room in DATABASE.Rooms
                                    from session in DATABASE.Sessions.Where(session => session.SessionDate == eventDate)
                                    select new { room, session })
                                   .OrderByDescending(rs => rs.room.Capacity) // Largest rooms first
                                   .ToList();

                // We need at least as many roomSessions as there are talks to create a schedule
                if (roomSessions.Count < talks.Count)
                {
                    MessageBox.Show(
                        "There aren't enough rooms and/or sessions to create a full schedule for all the talks available.",
                        "Not Enough Rooms", MessageBoxButton.OK);
                    return(false);
                }

                // Add the talks by decreasing interest into the rooms/sessions by decreasing capacity to create the Proposed Schedule
                for (var i = 0; i < roomSessions.Count && i < talks.Count; i++)
                {
                    var roomSession = roomSessions[i];
                    var newSchedule = new ProposedSchedule
                    {
                        RoomID                = roomSession.room.ID,
                        SessionID             = roomSession.session.ID,
                        TalkID                = talks[i],
                        UpdateTime            = DateTime.Now,
                        DiagnosticInformation = $"Adding Proposed Schedule for event on {eventDate}"
                    };
                    DATABASE.ProposedSchedules.InsertOnSubmit(newSchedule);
                }

                DATABASE.SubmitChanges();
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButton.OK);
                return(false);
            }
        }
Exemple #4
0
        public ActionResult ScheduleProp(string scheduleString)
        {
            ProposedSchedule proposedSchedule = JsonConvert.DeserializeObject <ProposedSchedule>(scheduleString);

            return(View(proposedSchedule));
        }