public ActionResult GetCoursesSchedule() { if (Session["Permission"] == null || Session["Permission"].ToString() != "Lecturer") { return(View("~/Views/Error.cshtml")); } var lecturerDal = new LecturerDal(); var courseDal = new CourseDal(); var courses = new List <Course>(); var id = Session["UserID"].ToString(); var lecturers = (from x in lecturerDal.Lecturers where x.LecturerId.Equals(id) select x).ToList(); for (int i = 0; i < lecturers.Count(); i++) { var t = lecturers[i].CourseName; courses.Add((from x in courseDal.Courses where x.CourseName.Equals(t) select x).SingleOrDefault()); } return(View("ShowCoursesSchedule", new CourseViewModel { Courses = courses })); }
public ActionResult update() { CourseDal c = new CourseDal(); StudentDal st = new StudentDal(); Grade g = new Grade(); g.cid = Request.Form["cid"]; g.username = Request.Form["username"]; g.grade1 = Request.Form["grade"]; string a1 = Request.Form["update"]; Gradedal dal = new Gradedal(); List <Grade> s = dal.grade.ToList <Grade>(); if (st.Dalstudents.Find(g.username) == null) { ModelState.AddModelError(string.Empty, "Student Name not exists."); return(View("editgrade")); } if (c.courses.Find(g.cid) == null) { ModelState.AddModelError(string.Empty, "Student Name not exists."); return(View("editgrade")); } if (a1.Equals("u")) { Grade a = dal.grade.Find(g.username, g.cid); if (a == null) { ModelState.AddModelError(string.Empty, " this Student didnt have grade to update."); return(View("editgrade")); } a.grade1 = g.grade1; dal.SaveChanges(); } if (a1.Equals("i")) { dal.grade.Add(g); dal.SaveChanges(); } return(View("editgrade")); }
public ActionResult Menu() { if (Session["Permission"] == null || Session["Permission"].ToString() != "FaAdmin") { return(View("~/Views/Error.cshtml")); } var courseDal = new CourseDal(); var examDal = new ExamDal(); var courses = (from x in courseDal.Courses select x).ToList(); var exams = (from x in examDal.Exams select x).ToList(); var coursesName = (from x in courseDal.Courses select x.CourseName).ToList(); if (Request.Form["AddNewCourse"] != null) { var userDal = new UserDal(); var lecturers = (from x in userDal.Users where x.PermissionType.Equals("Lecturer") select x.ID).ToList(); Session["ListLecturers"] = lecturers; return(View("AddNewCourse")); } if (Request.Form["CourseList"] != null) { Session["ListCoursesName"] = coursesName; return(View("ChangeStudentGrade")); } if (Request.Form["AssignStudents"] != null) { var userDal = new UserDal(); var students = (from x in userDal.Users where x.PermissionType.Equals("Student") select x).ToList(); Session["ListCourses"] = coursesName; return(View("AssignStudents", new UserViewModel { Users = students })); } if (Request.Form["ChangeSchedule"] != null) { Session["ListCourses"] = coursesName; return(View("ChangeSchedule", new CoursesExamsViewModel { Courses = courses, Exams = exams })); } return(View("FaAdminMenu", new CourseViewModel { Courses = courses })); }
// GET: Lecturer public ActionResult ShowSchedule() { // Session["username"] = "******"; ScheduleDal sheduleDal = new ScheduleDal(); LearnDal learnDal = new LearnDal(); CourseDal courseDal = new CourseDal(); ScheduleViewModel scheduleViewModel = new ScheduleViewModel(); scheduleViewModel.learns = new List <Learn>(); scheduleViewModel.courses = new List <Course>(); List <string> shids = new List <string>(); List <string> cids = new List <string>(); foreach (Course course in courseDal.courses.ToList <Course>()) { if (course.Lecturer.Equals(Session["username"].ToString())) { cids.Add(course.cid); scheduleViewModel.courses.Add(course); } } foreach (Learn learn in learnDal.learns.ToList <Learn>()) { if (cids.Contains(learn.cid)) { shids.Add(learn.shid); scheduleViewModel.learns.Add(learn); } } scheduleViewModel.schedules = new List <Shedule>(); foreach (Shedule shedule in sheduleDal.schedules.ToList <Shedule>()) { if (shids.Contains(shedule.shid)) { scheduleViewModel.schedules.Add(shedule); } } List <ScheduleViewModel> models = new List <ScheduleViewModel>(); ScheduleViewModel model; for (int i = 0; i < scheduleViewModel.courses.Count && i < scheduleViewModel.learns.Count && i < scheduleViewModel.schedules.Count; i++) { model = new ScheduleViewModel(); model.schedule = scheduleViewModel.schedules.ElementAt(i); model.Learn = scheduleViewModel.learns.ElementAt(i); model.course = scheduleViewModel.courses.ElementAt(i); models.Add(model); } return(View(models)); }
public SelectList GetAsCourseIDList() { CourseDal courseDal = new CourseDal(); List <Course> courses = (from x in courseDal.Courses select x).ToList <Course>(); var CourseName = from x in courses select new { course1 = x.CourseId, course2 = x.CourseName + " - " + x.CourseId }; return(new SelectList(CourseName, "course1", "course2")); }
public ActionResult Submit(Course course) { ScheduleDal dal = new ScheduleDal(); LecturerDal lecturerDal = new LecturerDal(); CourseDal courseDal = new CourseDal(); if (!lecturerDal.IsFound(course.Lecturer)) { ViewBag.error = " the lecturer is not found"; return(View("AddCourse")); } if (ModelState.IsValid) { try { Session["shid"] = (dal.schedules.Count() + 1).ToString(); course.shid = Session["shid"].ToString(); courseDal.courses.Add(course); courseDal.SaveChanges(); return(RedirectToAction("addschule")); } catch (Exception) { ViewBag.error1 = "Enter another course number"; return(View("AddCourse")); } //throw; } else { // ViewData["error1"] = "Enter another course number"; ViewBag.error1 = "Enter another course number"; } return(View("AddCourse")); //if(ModelState.IsValid) // return View(Content("HI EVERY THING IS OK BYBY")); //else //{ // return RedirectToAction("AddCourse"); //} //return View("ShowUsers"); // } }
public ActionResult add() { string username = Request.Form["username"]; string cid = Request.Form["cid"]; if (ModelState.IsValid) { CourseDal c = new CourseDal(); Course course = c.courses.Find(cid); StudentDal s = new StudentDal(); Student student = s.Dalstudents.Find(username); if (student == null) { ModelState.AddModelError(string.Empty, "Student Name not exists."); return(View("addStudent")); } if (course == null) { ModelState.AddModelError(string.Empty, "Course cid not exists."); return(View("addStudent")); } LearnDal learn = new LearnDal(); Learn l = new Learn(); l.cid = course.cid; l.Susername = student.username; l.shid = course.shid; learn.learns.Add(l); try { learn.SaveChanges(); } catch (Exception) { ModelState.AddModelError(string.Empty, "this student already not exists."); } } return(View("Homepage")); }
public ActionResult ShowExams() { LearnDal learnDal = new LearnDal(); CourseDal courseDal = new CourseDal(); Session["username"] = "******"; ScheduleViewModel scheduleViewModel = new ScheduleViewModel(); scheduleViewModel.learns = new List <Learn>(); foreach (Learn learn in learnDal.learns.ToList <Learn>()) { if (learn.Susername.Equals(Session["username"])) { scheduleViewModel.learns.Add(learn); } } List <string> cids = new List <string>(); foreach (Learn learn in scheduleViewModel.learns) { if (!cids.Contains(learn.cid)) { cids.Add(learn.cid); } } //scheduleViewModel.schedules = sheduleDal.schedules.ToList<Shedule>(); scheduleViewModel.courses = new List <Course>(); foreach (Course course in courseDal.courses.ToList <Course>()) { if (cids.Contains(course.cid)) { scheduleViewModel.courses.Add(course); } } return(View(scheduleViewModel.courses)); }
public bool insertCourseResponse(CourseEntity course) { CourseDal coursedal = new CourseDal(); return(coursedal.insertCourseResponse(course)); }
public bool VerificaPago(UserEntity user, CourseEntity course) { CourseDal courseDal = new CourseDal(); return(courseDal.VerificaPago(user, course)); }
public bool RealizarPago(UserEntity user, CourseEntity course) { CourseDal courseDal = new CourseDal(); return(courseDal.RealizarPago(user, course)); }
public CourseEntity GetCourse(string curso, string area) { CourseDal courseDal = new CourseDal(); return(courseDal.GetCourse(curso, area)); }
public List <CourseEntity> GetAllCoursesWithinNameAndArea(string curso) { CourseDal courseDal = new CourseDal(); return(courseDal.GetAllCoursesWithinNameAndArea(curso)); }
public List <CourseEntity> GetAllCourses() { CourseDal courseDal = new CourseDal(); return(courseDal.GetAllCourses()); }
public CoursesController(IOptions <ApplicationSettings> appSetting, IOptions <ConnectionSetting> con) { this.udal = new CourseDal(appSetting.Value, con.Value); }
public ActionResult AddCourse() { if (Session["Permission"] == null || Session["Permission"].ToString() != "FaAdmin") { return(View("~/Views/Error.cshtml")); } //Add course var cname = Request.Form["CourseName"]; var lid = Request.Form["SelectedLecturer"]; var day = Request.Form["Day"]; int shour = Convert.ToInt32(Request.Form["StartHour"]), fhour = Convert.ToInt32(Request.Form["FinishHour"]); if (fhour <= shour) { return(RedirectToAction("Menu")); } var classroom = Request.Form["Classroom"]; var courseDal = new CourseDal(); var course = (from x in courseDal.Courses where x.CourseName.Equals(cname) select x.CourseName).SingleOrDefault(); if (course != null) { TempData["Error"] = "Course " + course + " already exists in the system"; return(RedirectToAction("Menu")); //course already exist } var schedule = (from x in courseDal.Courses where x.Day.Equals(day) && x.Classroom.Equals(classroom) select x).ToList(); if (IsClashingCourse(shour, fhour, schedule)) { return(RedirectToAction("Menu")); //schedule is occupied for classroom } var scheduleLecturer = (from x in courseDal.Courses where x.Day.Equals(day) && x.LecturerID.Equals(lid) select x).ToList(); if (IsClashingCourse(shour, fhour, scheduleLecturer)) { return(RedirectToAction("Menu")); //lecturer is occupied for lecturer } SqlConnection conn = new SqlConnection("Data Source=DESKTOP-GH6DGFT\\AVIEL;Initial Catalog=sce_website;Integrated Security=True"); conn.Open(); var query = "INSERT INTO tblCourses " + "(CourseName, Day, Classroom, LecturerID, StartHour, FinishHour) " + "VALUES (@cname, @day, @classroom, @lid, @shour, @fhour)"; SqlCommand command = new SqlCommand(query, conn); command.Parameters.Add("@cname", SqlDbType.NVarChar, 50).Value = cname; command.Parameters.Add("@day", SqlDbType.NVarChar, 50).Value = day; command.Parameters.Add("@shour", SqlDbType.Int).Value = shour; command.Parameters.Add("@fhour", SqlDbType.Int).Value = fhour; command.Parameters.Add("@classroom", SqlDbType.NVarChar, 50).Value = classroom; command.Parameters.Add("@lid", SqlDbType.NVarChar, 50).Value = lid; //Add exam schedule to course string ashour = Request.Form["ExamAStartHour"], afhour = Request.Form["ExamAFinishHour"], bshour = Request.Form["ExamBStartHour"], bfhour = Request.Form["ExamBFinishHour"]; int astarthour = Convert.ToInt32(ashour), afinishhour = Convert.ToInt32(afhour); int bstarthour = Convert.ToInt32(bshour), bfinishhour = Convert.ToInt32(bfhour); var examDal = new ExamDal(); if (astarthour >= afinishhour) { TempData["Error"] = "Start hour cannot be after finish hour."; return(RedirectToAction("Menu")); } if (bstarthour >= bfinishhour) { TempData["Error"] = "Start hour cannot be after finish hour."; return(RedirectToAction("Menu")); } var examADate = Convert.ToDateTime(Request.Form["ADate"]); var examBDate = Convert.ToDateTime(Request.Form["BDate"]); if (DateTime.Compare(examADate, DateTime.Now) <= 0 || DateTime.Compare(examBDate, DateTime.Now) <= 0 || DateTime.Compare(examADate, examBDate) >= 0) { TempData["Error"] = "No time-machines invented yet."; return(RedirectToAction("Menu")); } var exams = (from x in examDal.Exams where x.Classroom.Equals(classroom) && !x.CourseName.Equals(cname) select x).ToList(); if (IsClashingExam(astarthour, afinishhour, examADate, exams) || IsClashingExam(bstarthour, bfinishhour, examBDate, exams)) { TempData["Error"] = "Hours clashing with other exam."; return(RedirectToAction("Menu")); } var addExamQ = "INSERT INTO tblExams " + "(CourseName, Classroom, ExamADate, ExamBDate, ExamAStart, ExamAFinish, ExamBStart, ExamBFinish) " + "VALUES (@cname, @classroom, @adate, @bdate, @astart, @afinish, @bstart, @bfinish)"; SqlCommand examCommand = new SqlCommand(addExamQ, conn); examCommand.Parameters.Add("@cname", SqlDbType.NVarChar, 50).Value = cname; examCommand.Parameters.Add("@adate", SqlDbType.Date).Value = examADate; examCommand.Parameters.Add("@bdate", SqlDbType.Date).Value = examBDate; examCommand.Parameters.Add("@astart", SqlDbType.Int).Value = astarthour; examCommand.Parameters.Add("@afinish", SqlDbType.Int).Value = afinishhour; examCommand.Parameters.Add("@bstart", SqlDbType.Int).Value = bstarthour; examCommand.Parameters.Add("@bfinish", SqlDbType.Int).Value = bfinishhour; examCommand.Parameters.Add("@classroom", SqlDbType.NVarChar, 50).Value = classroom; //assign course to lecturer var addCourseToLecturer = "INSERT INTO tblLecturers " + "(LecturerID, CourseName) " + "VALUES (@lid, @cname)"; SqlCommand lecturerCommand = new SqlCommand(addCourseToLecturer, conn); lecturerCommand.Parameters.Add("@lid", SqlDbType.NVarChar, 50).Value = lid; lecturerCommand.Parameters.Add("@cname", SqlDbType.NVarChar, 50).Value = cname; command.ExecuteNonQuery(); examCommand.ExecuteNonQuery(); lecturerCommand.ExecuteNonQuery(); conn.Close(); TempData["Success"] = "Course " + cname + " added successfully"; return(RedirectToAction("Menu")); }
public ActionResult ChangeCourseSchedule() { if (Session["Permission"] == null || Session["Permission"].ToString() != "FaAdmin") { return(View("~/Views/Error.cshtml")); } string cname = Request.Form["SelectedCourse"], classroom = Request.Form["Classroom"], day = Request.Form["Day"], shour = Request.Form["StartHour"], fhour = Request.Form["FinishHour"]; if (classroom == null && day == null && shour == null && fhour == null) { return(RedirectToAction("Menu")); } int starthour, endhour; var courseDal = new CourseDal(); var currentCourse = (from x in courseDal.Courses where x.CourseName.Equals(cname) select x).SingleOrDefault(); if (classroom == null) { classroom = currentCourse.Classroom; } if (day == null) { day = currentCourse.Day; } if (shour == null) { starthour = currentCourse.StartHour; } else { starthour = Convert.ToInt32(shour); } if (fhour == null) { endhour = currentCourse.FinishHour; } else { endhour = Convert.ToInt32(fhour); } if (starthour >= endhour) { return(RedirectToAction("Menu")); } var courses = (from x in courseDal.Courses where x.Classroom.Equals(classroom) && x.Day.Equals(day) && !x.CourseName.Equals(cname) select x).ToList(); if (IsClashingCourse(starthour, endhour, courses)) //is clashing with other course { TempData["Error"] = "The time window is already occupied by other event."; return(RedirectToAction("Menu")); } SqlConnection conn = new SqlConnection("Data Source=DESKTOP-GH6DGFT\\AVIEL;Initial Catalog=sce_website;Integrated Security=True"); conn.Open(); string query; query = "UPDATE tblCourses " + "SET Day = @day, " + "Classroom = @classroom, " + "StartHour = @shour, " + "FinishHour = @fhour " + "WHERE CourseName = @cname"; SqlCommand command = new SqlCommand(query, conn); command.Parameters.Add("@cname", SqlDbType.NVarChar, 50).Value = cname; command.Parameters.Add("@day", SqlDbType.NVarChar, 50).Value = day; command.Parameters.Add("@shour", SqlDbType.Int).Value = shour; command.Parameters.Add("@fhour", SqlDbType.Int).Value = fhour; command.Parameters.Add("@classroom", SqlDbType.NVarChar, 50).Value = classroom; command.ExecuteNonQuery(); conn.Close(); TempData["Success"] = "Course schedule changed successfully."; return(RedirectToAction("Menu")); }