public ActionResult ChangeStudentGrade() { if ((Request.Form["gridRadios1"] != null) && (Request.Form["Student_id"] != null)) { string student_id = Request.Form["Student_id"]; int course_id = Convert.ToInt32(Request.Form["Course_id"]); int grade = Convert.ToInt32(Request.Form["Grade"]); PDAL DBconnection = new PDAL(); UsersCourses Student = DBconnection.UsersCoursess.Find(student_id, course_id); string option = Request.Form["gridRadios1"].ToString(); if (Student != null) { if (option.Equals("option1")) { Student.moed1 = grade; Student.final = grade; } else if (option.Equals("option2")) { Student.moed2 = grade; Student.final = grade; } else { Student.final = grade; } } DBconnection.SaveChanges(); } return(Redirect("~/Administration/AdminMain")); }
public ActionResult ChangeStudentGrade() { if ((Request.Form["gridRadios1"] != null) && (Request.Form["Student_id"] != null)) { string student_id = Request.Form["Student_id"]; int course_id = Convert.ToInt32(Request.Form["Course_id"]); int grade = Convert.ToInt32(Request.Form["Grade"]); string Lecturer = (string)Session["id"]; PDAL DBconnection = new PDAL(); UsersCourses Student = DBconnection.UsersCoursess.Find(student_id, course_id); string option = Request.Form["gridRadios1"].ToString(); string Course_Lecturer = "-1"; try { Course_Lecturer = (DBconnection.Courses.Find(course_id).lecturer_id).ToString(); } catch (Exception a) { if (a != null) { Course_Lecturer = "-1"; } } if (Regex.Replace(Course_Lecturer, " ", "") != Lecturer) { Session["Alert"] = "You dont have permission to change that course."; return(Redirect("~/Lecturers/LecturerMain")); } if (Student == null) { Session["Alert"] = "No such student."; return(Redirect("~/Lecturers/LecturerMain")); } if (option.Equals("option1")) { Student.moed1 = grade; Student.final = grade; } else if (option.Equals("option2")) { Student.moed2 = grade; Student.final = grade; } else { Student.final = grade; } DBconnection.SaveChanges(); } return(Redirect("~/Lecturers/LecturerMain")); }
public void Subscribe(int userId, int coursId, DateTime startDate) { var user = context.Users.FirstOrDefault(x => x.Id == userId); var course = context.Course.FirstOrDefault(x => x.Id == coursId); var subcription = new UsersCourses { User = user, Course = course, StartDate = startDate }; context.UsersCourses.Update(subcription); context.SaveChanges(); notificationEmailSender.ScheduleJobs(user.Email, course.Name, subcription.StartDate); }
public ActionResult AddStudentToCource() { int course_id; try { course_id = Convert.ToInt32(Request.Form["Course_id"]); }catch (Exception a) { a.GetType(); Session["Alert"] = "No such course."; return(Redirect("~/Administration/AdminMain")); } string Student_id = (string)Request.Form["Student_id"]; PDAL DBconnection = new PDAL(); UsersCourses Student = DBconnection.UsersCoursess.Find(Student_id, course_id); if (Student == null) { Session["Alert"] = "Student is alredy tacking the course or no such student."; return(Redirect("~/Administration/AdminMain")); } string role = (DBconnection.Users.Find(Student_id)).role.ToString(); if (Regex.Replace(role, " ", "") != "1") { Session["Alert"] = "The user is not student."; return(Redirect("~/Administration/AdminMain")); } if (CheckIfCourseOverlaps(Student_id, course_id)) { Session["Alert"] = "Course overlap with another course."; return(Redirect("~/Administration/AdminMain")); } Student = new UsersCourses(); Student.id = Student_id; Student.course = course_id; Student.moed1 = Student.moed2 = Student.final = 0; DBconnection.UsersCoursess.Add(Student); DBconnection.SaveChanges(); return(Redirect("~/Administration/AdminMain")); }
public async Task <Response> RegisterToCourse(int userId, int courseId, DateTime startDate) { var res = new Response(); var user = await _userRepo.GetByIdAsync(userId); var course = await _repo.GetByIdAsync(courseId); var userInCourse = await _usersCoursesRepo.GetSingleAsync(u => u.UserId == userId && u.CourseId == courseId && u.StartDate == startDate); if (userInCourse == null) { var userCourse = new UsersCourses { UserId = userId, CourseId = courseId, StartDate = startDate }; try { _usersCoursesRepo.Add(userCourse); res.Successful = true; res.Information = "You have successfully registered to course"; _backgroundEmailSender.SendNotificationEmails(user.Email, course.CourseName, userCourse.StartDate); return(res); } catch (Exception e) { res.Successful = false; res.Information = e.Message; return(res); } } else { res.Successful = false; res.Information = "Choose another date"; return(res); } }