public ActionResult StaffSubjectView(string arm) { //List<Level> theLevels = work.LevelRepository.Get().ToList(); //List<SelectListItem> theItem = new List<SelectListItem>(); //theItem.Add(new SelectListItem() { Text = "None", Value = "" }); //foreach (var level in theLevels) //{ // theItem.Add(new SelectListItem() { Text = level.LevelName + ":" + level.Type, Value = level.LevelName + ":" + level.Type }); //} //ViewData["arm"] = theItem; int userId = Convert.ToInt32(User.Identity.Name); List <PrimarySchoolStaff> theStaff = work.PrimarySchoolStaffRepository.Get(a => a.UserID == userId).ToList(); PrimarySchoolStaff theRealStaff = theStaff[0]; List <List <TimeTable> > theTimeTable = TimeTableCollisionAviodance.DisplayTimeTableCustomisedForStaff(theRealStaff.PersonID); ViewBag.TimeTable = theTimeTable; ViewBag.Name = theRealStaff.LastName + " " + theRealStaff.FirstName; return(View("StaffSubjectView")); }
public ActionResult Create(TimeTable model) { List <Level> theLevels = work.LevelRepository.Get().ToList(); List <SelectListItem> theItem = new List <SelectListItem>(); theItem.Add(new SelectListItem() { Text = "None", Value = "" }); foreach (var level in theLevels) { theItem.Add(new SelectListItem() { Text = level.LevelName + ":" + level.Type, Value = level.LevelName + ":" + level.Type }); } ViewData["Level"] = theItem; List <Subject> theSubject = work.SubjectRepository.Get().ToList(); List <SelectListItem> theSubjectsItem = new List <SelectListItem>(); theSubjectsItem.Add(new SelectListItem() { Text = "None", Value = "" }); foreach (var sub in theSubject) { theSubjectsItem.Add(new SelectListItem() { Text = sub.Name, Value = sub.Name }); } ViewData["Subject"] = theSubjectsItem; List <PrimarySchoolStaff> staff = work.PrimarySchoolStaffRepository.Get().OrderBy(a => a.LastName).ToList(); List <SelectListItem> theStaffItem = new List <SelectListItem>(); theStaffItem.Add(new SelectListItem() { Text = "None", Value = "" }); foreach (var s in staff) { theStaffItem.Add(new SelectListItem() { Text = s.LastName + " " + s.Middle + " " + s.FirstName, Value = s.LastName + " " + s.Middle + " " + s.FirstName }); } ViewData["Staff"] = theStaffItem; try { string v = model.Subject + ";" + model.Class + ";" + model.StratTimeHour + ";" + model.StratTimeMinute + ";" + model.Teacher + ";" + model.Day; string theReturnedValue = TimeTableCollisionAviodance.CheckDaySlotAvialability(v); string theReturnedValueSubject = TimeTableCollisionAviodance.CheckSubjectSlotAvialability(v); string theReturnedValueStaff = TimeTableCollisionAviodance.CheckStaffSlotAvialability(v); if (!(string.IsNullOrEmpty(theReturnedValue))) { // ModelState.AddModelError("", "Create a Class Subjects First for Class " + theStudent.PresentLevel); // return View(theReg); ModelState.AddModelError("", theReturnedValue); return(View(model)); } int start = Convert.ToInt32(model.StratTimeHour); int finish = Convert.ToInt32(model.EndTimeHour); if (finish < start) { ModelState.AddModelError("", "Start Time of a Subject must be greater than its finish time!"); return(View(model)); } if (!(string.IsNullOrEmpty(theReturnedValueSubject))) { ModelState.AddModelError("", theReturnedValueSubject); return(View(model)); } if (!(string.IsNullOrEmpty(theReturnedValueStaff))) { ModelState.AddModelError("", theReturnedValueStaff); return(View(model)); } //var theValue = $('#Subject').val() + ";" + $('#Class').val() + ";" + $('#StratTimeHour').val() + ";" + $('#StratTimeMinute').val() + ";" + $('#Teacher').val() + ";" + $('#Day').val(); TeachingSubject ts = new TeachingSubject(); ts.SubjectName = model.Subject; TeachingDay td = new TeachingDay(); td.StratTimeHour = model.StratTimeHour; td.StratTimeMinute = model.StratTimeMinute; td.EndTimeHour = model.EndTimeHour; td.EndTimeMinute = model.EndTimeMinute; if (model.Day == "SUNDAY") { td.theDay = Day.SUNDAY; } if (model.Day == "MONDAY") { td.theDay = Day.MONDAY; } if (model.Day == "TUESDAY") { td.theDay = Day.TUESDAY; } if (model.Day == "WEDNESDAY") { td.theDay = Day.WEDNESDAY; } if (model.Day == "THURSDAY") { td.theDay = Day.THURSDAY; } if (model.Day == "FRIDAY") { td.theDay = Day.FRIDAY; } if (model.Day == "SATURDAY") { td.theDay = Day.SATURDAY; } TeachingClass tc = new TeachingClass(); tc.ClassName = model.Class; List <TeachingSubject> tss = new List <TeachingSubject>(); tss.Add(ts); td.TeachingSubject = tss; List <TeachingDay> tdd = new List <TeachingDay>(); tdd.Add(td); tc.TheTeachingDay = tdd;; List <TeachingClass> tt = new List <TeachingClass>(); tt.Add(tc); Teacher t = new Teacher(); // work.PrimarySchoolStaffRepository.ge t.TeacherName = model.Teacher; string[] theTeacher = model.Teacher.Split(' '); string firstName = theTeacher[2]; string lastName = theTeacher[0]; List <PrimarySchoolStaff> priStaff = work.PrimarySchoolStaffRepository.Get(a => a.LastName.Equals(lastName) && a.FirstName.Equals(firstName)).ToList(); t.ThePersonID = priStaff[0].PersonID; t.TheTeachingClass = tt; work.TeacherRepository.Insert(t); work.Save(); // td.theDay = model.Day; // TODO: Add insert logic here return(RedirectToAction("Create")); // return RedirectToAction("Index"); } catch { return(View()); } }
public ActionResult Index(string arm, string studentID) { if (User.IsInRole("Parent")) { Int32 theUser = Convert.ToInt32(User.Identity.Name); List <PrimarySchoolStudent> thSchoolStudents; // string userid = User.Identity.Name; List <Parent> theP = work.ParentRepository.Get(a => a.UserID == theUser).ToList(); Parent theRealParent = theP[0]; int idParent = theRealParent.ParentID; thSchoolStudents = work.PrimarySchoolStudentRepository.Get(a => a.ParentID == idParent).ToList(); List <SelectListItem> theItem1 = new List <SelectListItem>(); foreach (var s in thSchoolStudents) { theItem1.Add(new SelectListItem() { Text = s.LastName + " " + s.FirstName, Value = s.PersonID.ToString() }); ViewData["Students"] = theItem1; } } List <Level> theLevels = work.LevelRepository.Get().ToList(); List <SelectListItem> theItem = new List <SelectListItem>(); theItem.Add(new SelectListItem() { Text = "None", Value = "" }); foreach (var level in theLevels) { theItem.Add(new SelectListItem() { Text = level.LevelName + ":" + level.Type, Value = level.LevelName + ":" + level.Type }); } ViewData["arm"] = theItem; List <List <TimeTable> > theTimeTable1 = TimeTableCollisionAviodance.DisplayTimeTable(arm); ViewBag.TimeTable = theTimeTable1; int userId = 0;// Convert.ToInt32(User.Identity.Name); if (User.IsInRole("Parent")) { Int32 theUser = Convert.ToInt32(User.Identity.Name); Parent theP = work.ParentRepository.Get(a => a.UserID == theUser).First(); if (studentID != null) { int id = Convert.ToInt32(studentID); // userId = Convert.ToInt32(User.Identity.Name); List <PrimarySchoolStudent> theStaff = work.PrimarySchoolStudentRepository.Get(a => a.PersonID == id).ToList(); if (theStaff.Count() > 0) { PrimarySchoolStudent theRealStudent = theStaff[0]; string theArm = theRealStudent.LevelType; List <List <TimeTable> > theTimeTable = TimeTableCollisionAviodance.DisplayTimeTable(theArm); ViewBag.TimeTable = theTimeTable; return(View()); } } } if (string.IsNullOrEmpty(arm) && User.IsInRole("Student")) { userId = Convert.ToInt32(User.Identity.Name); List <PrimarySchoolStudent> theStaff = work.PrimarySchoolStudentRepository.Get(a => a.UserID == userId).ToList(); if (theStaff.Count() > 0) { PrimarySchoolStudent theRealStudent = theStaff[0]; string theArm = theRealStudent.LevelType; List <List <TimeTable> > theTimeTable = TimeTableCollisionAviodance.DisplayTimeTable(theArm); ViewBag.TimeTable = theTimeTable; return(View()); } } return(View()); }
public ActionResult StudentTimeTableView(string studentID) { if (User.IsInRole("Parent")) { Int32 theUser = Convert.ToInt32(User.Identity.Name); List <PrimarySchoolStudent> thSchoolStudents; // string userid = User.Identity.Name; List <Parent> theP = work.ParentRepository.Get(a => a.UserID == theUser).ToList(); Parent theRealParent = theP[0]; int idParent = theRealParent.ParentID; thSchoolStudents = work.PrimarySchoolStudentRepository.Get(a => a.ParentID == idParent).ToList(); List <SelectListItem> theItem = new List <SelectListItem>(); foreach (var s in thSchoolStudents) { theItem.Add(new SelectListItem() { Text = s.LastName + " " + s.FirstName, Value = s.PersonID.ToString() }); ViewData["Students"] = theItem; } } int userId = 0;//Convert.ToInt32(User.Identity.Name); // int userID = 0; //=// Convert.ToInt32(User.Identity.Name); if (User.IsInRole("Parent")) { // int userID = Convert.ToInt32(User.Identity.Name); Int32 theUser = Convert.ToInt32(User.Identity.Name); Parent theP = work.ParentRepository.Get(a => a.UserID == theUser).First(); if (studentID != null) { int id = Convert.ToInt32(studentID); PrimarySchoolStudent theStudents = work.PrimarySchoolStudentRepository.GetByID(id); if (theStudents != null) { userId = theStudents.UserID; // work.PrimarySchoolStudentRepository.Get(a=>a.UserID == ids).First(); } else { userId = -1; } } else { userId = -1; } } else { // userID = Convert.ToInt32(User.Identity.Name); userId = Convert.ToInt32(User.Identity.Name); } //int userId = Convert.ToInt32(User.Identity.Name); List <PrimarySchoolStudent> theStaff = work.PrimarySchoolStudentRepository.Get(a => a.UserID == userId).ToList(); List <List <TimeTable> > theTimeTable = new List <List <TimeTable> >(); if (theStaff.Count() > 0) { PrimarySchoolStudent theRealStudent = theStaff[0]; string theArm = theRealStudent.LevelType; theTimeTable = TimeTableCollisionAviodance.DisplayTimeTable(theArm); } // ViewBag.TimeTable = theTimeTable; // ViewBag.Name = theRealStaff.LastName + " " + theRealStaff.FirstName; return(View("Index", theTimeTable)); }