public ActionResult AssignAvoidedSession(int index)
 {
     InterviewAssignMultipleViewModel ViewModel = new InterviewAssignMultipleViewModel();
     ViewBag.index = index;
     ViewBag.academicOrganizationList = new SelectList(db.StudentProfiles.Select(s => new { value = s.academic_organization, text = s.academic_organization }).Distinct(), "value", "text");
     ViewBag.academicPlanList = new SelectList(db.StudentProfiles.Select(s => new { value = s.academic_plan_primary, text = s.academic_plan_description }).Distinct(), "value", "text");
     ViewBag.academicLevelList = new SelectList(db.StudentProfiles.Select(s => new { value = s.academic_level, text = s.academic_level }).Distinct(), "value", "text");
     return PartialView(ViewModel);
 }
        public ActionResult AssignMultiple(InterviewAssignMultipleViewModel ViewModel)
        {
            int auto_assigned_count = 0;

            Program program = db.Programs.Find(ViewModel.program_id);
            if (program == null)
            {
                Session["FlashMessage"] = "Program not found.";
            }
            try
            {
                foreach (var interview in program.Interviews.Where(i => i.Applications.Count() < i.no_of_interviewee))
                {
                    string department = null;
                    var applications = program.Applications.Where(a => a.Interviews.Count() == 0 && a.ApplicationStatus.name == "Processed");
                    //sort applications by department is sort_by_dept is true, ,or continuous_assign is false
                    if (ViewModel.sort_by_dept || !ViewModel.continuous_assign)
                    {
                        applications = applications.OrderBy(a => a.StudentProfile.academic_organization);
                    }
                    foreach (var application in applications)
                    {
                        //check if student academic organization is set in avoided session and collide with interview session
                        bool avoided = CheckAvoidedSessions(interview, ViewModel.avoided_sessions, application.StudentProfile);
                        if (!avoided && interview.Applications.Count() < interview.no_of_interviewee)
                        {
                            //check if same department in a single interview if continuous_assign is false
                            if (ViewModel.continuous_assign || department == null || department == application.StudentProfile.academic_organization)
                            {
                                interview.Applications.Add(application);
                                application.Interviews.Add(interview);
                                auto_assigned_count++;
                                department = application.StudentProfile.academic_organization;
                            }
                        }
                    }
                }
                db.Entry(program).State = EntityState.Modified;
                db.SaveChanges();

                var available_interview_seat_count = program.Interviews.Sum(i => i.no_of_interviewee - i.Applications.Count());
                int unassigned_application_count = program.Applications.Where(a => a.ApplicationStatus.name == "Processed" && a.Interviews.Count() == 0).Count();

                Session["FlashMessage"] = "<b>Auto assign summary:</b><br/>"
                    + "Auto-assigned Applications : " + auto_assigned_count + "<br/>"
                    + "Available seats: " + available_interview_seat_count + "<br/>"
                    + "Unassigned Applications : " + unassigned_application_count;
                return RedirectToAction("Index");
            }
            catch (Exception e)
            {
                Session["FlashMessage"] = "Failed to assign applications to interview timeslots." + (e.Message);
                return RedirectToAction("AssignMultiple");
            }
        }
 public ActionResult AssignMultiple()
 {
     InterviewAssignMultipleViewModel ViewModel = new InterviewAssignMultipleViewModel();
     ViewModel.sort_by_dept = true;
     ViewModel.continuous_assign = true;
     ViewBag.programList = new SelectList(db.Programs.Where(p => p.require_interview && p.Applications.Count(a => a.ApplicationStatus.name == "Processed") > 0), "id", "name");
     ViewBag.academicOrganizationList = new SelectList(db.StudentProfiles.Select(s => new { value = s.academic_organization, text = s.academic_organization }).Distinct(), "value", "text");
     ViewBag.academicPlanList = new SelectList(db.StudentProfiles.Select(s => new { value = s.academic_plan_primary, text = s.academic_plan_description }).Distinct(), "value", "text");
     ViewBag.academicLevelList = new SelectList(db.StudentProfiles.Select(s => new { value = s.academic_level, text = s.academic_level }).Distinct(), "value", "text");
     return View(ViewModel);
 }