Preference Class
Inheritance: BaseClass
        public void CanAddPreference()
        {
            Professor p = new ProfessorProvider(session).GetProfessorByID(19);
            Course c = new CourseProvider(session).GetCourseByID(6);
            var prefID = new PreferencesId(p, c);

            var pref = new Preference(prefID) { Weight = 3 };
            provider.AddPreference(pref);
            Preference testPref = provider.GetPreferenceByProfIdAndCourseId(19, 6);
            Assert.AreEqual(c, testPref.Id.Course);
            Assert.AreEqual(p, testPref.Id.Professor);
            //Assert.IsNotNull(testPref);
            //provider.AddPreference(pref);
        }
Exemplo n.º 2
0
        public object Create(string Id)
        {
            ViewData["Title"] = "Create Preference";
            ViewData["Message"] = "Create a Preference";
            if (string.IsNullOrEmpty(Id)) {
                return RedirectToAction("Index", "Professor");

            }
            int profId;
            try {
                profId = Convert.ToInt32(Id);
            } catch (Exception)   //not an integer
            {
                return RedirectToAction("Index", "Professor");
            }
            Professor professor = new ProfessorProvider().GetProfessorByID(profId);
            if (professor == null) {
                return RedirectToAction("Index", "Professor");
            }
            var ProfPrefs = (new PreferencesProvider().GetAllPreferencesByProfId(profId));
            var settings = new Settings();
            int lookFor = settings.NumberOfPreferencesPerProfessor;
            while (true)
            {
                int lookFor1 = lookFor;
                if (ProfPrefs.Where(s => s.Weight == lookFor1).Count() == 0)
                {
                    break;
                }
                lookFor--;
                if (lookFor == 0)
                {
                    break;
                }
            }
            int weight = lookFor;
            var preference = new Preference
                             	{
                             		Id = { Professor = professor },
                             		Weight = weight
                             	};
            PrepareCoursesList(preference);
            ViewData["ProfId"] = preference.Id.Professor.ProfId;
            return View(preference);
        }
Exemplo n.º 3
0
 private void PrepareCoursesList(Preference preference)
 {
     IList<Course> pl = (new CourseProvider()).GetAllCourses();
     //ViewData["CourseList"] = preference.Id.Course.CourseId != 0
     //                             ? new SelectList(pl, "CourseId", "CourseName", preference.Id.Course.CourseId)
     //                             : new SelectList(pl, "CourseId", "CourseName", "0");
     if (preference.Id != null)
     {
         ViewData["CourseList"] = preference.Id.Course.CourseId != 0
                                  	? new SelectList(pl, "CourseId", "CourseName",
                                  	                 preference.Id.Course.CourseId)
                                  	: new SelectList(pl, "CourseId", "CourseName", "0");
     }
     else
     {
         ViewData["CourseList"] = new SelectList(pl, "CourseId", "CourseName", "0");
     }
 }