public ActionResult Search(string searchString) { ViewBag.SearchKey = searchString; var list = CourseHelper.SearchCoursesFor(searchString); return(View(list)); }
// GET: Courses/Delete/courseId // returns delete view with confirmation of the course being deleted public ActionResult Delete(int?courseId) { if (courseId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var id = (int)courseId; Course course = CourseHelper.GetById(id); if (course == null) { return(HttpNotFound()); } var isSupervisor = SupervisorHelper.IsUserSupervisor(CurrentWebContext.CurrentUser.UserID, id); if (!isSupervisor) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } ViewBag.Title = course.CourseName; var success = course.Delete(); ViewBag.Success = success; return(View()); }
public ActionResult loadCourseTimings(string courseName) { var Jcon = new JsonContainer(); var objCourseHelper = new CourseHelper(); var courseDetails = new Course { userId = 0, courseName = string.Empty, startTime = string.Empty, endTime = string.Empty }; var dtCourse = objCourseHelper.SearchCourse(courseDetails); List <Course> courseList = new List <Course>(); foreach (DataRow dr in dtCourse.Rows) { var course = new Course { startTime = dr["startTime"].ToString(), endTime = dr["startTime"].ToString() + " - " + dr["endTime"].ToString() }; courseList.Add(course); } Jcon.Result = courseList.Distinct().OrderBy(x => x.startTime).ToList(); return(Json(Jcon)); }
public void GetAllStudents() { CourseHelper ch = new CourseHelper(new ApplicationDbContext()); var students = ch.GetAllStudents(); Assert.IsNotNull(students); }
public async Task OnGetAsync() { var userId = HttpContext.Session.GetInt32(SD.UserSessionId); if (userId == null) { userId = 0; } var isInstructor = await _context.User.Where(x => x.ID == userId).Where(x => x.UserType == 'I').AnyAsync(); courseHelper = new CourseHelper(); if (isInstructor) { Course = await _context.Course.Where(x => x.InstructorID == userId).ToListAsync(); foreach (var course in Course) { course.StartTime = courseHelper.ConvertMilitaryToStandardTime(course.StartTime); course.EndTime = courseHelper.ConvertMilitaryToStandardTime(course.EndTime); } } else { userId = 0; Course = await _context.Course.Where(x => x.InstructorID == userId).ToListAsync(); } }
public void GetAllCourses() { CourseHelper ch = new CourseHelper(new ApplicationDbContext()); var courses = ch.allCourses(); Assert.IsNotNull(courses); }
public async Task <IActionResult> OnGetAsync(int?id) { int userId = (int)HttpContext.Session.GetInt32(SD.UserSessionId); if (id == null) { return(NotFound()); } Course = await _context.Course.FirstOrDefaultAsync(m => m.ID == id); courseHelper = new CourseHelper(); if (Course == null) { return(NotFound()); } else { string startEndTime = courseHelper.ConcatenateStartAndEndTime(Course); string fullSchedule = courseHelper.ConcatenateDaysAndTimes(Course, startEndTime); Course.StartTime = fullSchedule; } if (id > 0) { User = _context.User.Where(x => x.ID == userId).FirstOrDefault(); } return(Page()); }
// GET: Courses/Enroll/userId&courseId // returns enroll confirmation view public ActionResult Enroll(int userId, int?courseId) { if (courseId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int id = (int)courseId; Course course = CourseHelper.GetById(id); if (course == null) { return(HttpNotFound()); } if (CurrentWebContext.CurrentUser.Type == "teacher") { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } var participant = new Participant(userId, id, Participant.STATUS_PENDING); var success = participant.Insert(); if (success) { ViewBag.Message = "Successfully applied for the course, a course supervisor must approve you!"; } else { ViewBag.Message = "Something went wrong! Please try again."; } return(View()); }
// GET: Courses/Edit/courseId // returns edit view where a teacher can modify the course's data public ActionResult Edit(int?courseId) { if (courseId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } int id = (int)courseId; Course course = CourseHelper.GetById(id); if (course == null) { return(HttpNotFound()); } // check if the user trying to access the course is a supervisor var supervisors = SupervisorHelper.GetSupervisorsForCourse(id); // if he isn't, then return him => denied if (!supervisors.Any(x => x.UserID == CurrentWebContext.CurrentUser.UserID)) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } // create the viewmodel var viewModel = DetailedCourseVM.CreateDetailedCourseVMW(course, supervisors); ViewBag.CountOfPendingStudents = ParticipantHelper.GetCountOfPendingParticipants(id); return(View(viewModel)); }
public EnrollmentsController(PruebaContext context, StudentHelper Helper, CourseHelper CourseHelper, QualificationHelper QualificationHelper) { _context = context; _studentHelper = Helper; _courseHelper = CourseHelper; _QualificationHelper = QualificationHelper; }
public ActionResult searchResults(string courseName, string courseTiming) { string startTime = string.Empty, endTime = string.Empty; courseName = string.IsNullOrEmpty(courseName) ? "-SELECT-" : courseName; courseTiming = string.IsNullOrEmpty(courseTiming) ? "-SELECT-" : courseTiming; if (courseName.ToUpper() == "-SELECT-") { courseName = string.Empty; } if (courseTiming.ToUpper() == "-SELECT-") { courseTiming = string.Empty; } else { var substrings = courseTiming.Split('-'); startTime = substrings[0].Trim(' '); endTime = substrings[1].Trim(' '); } var Jcon = new JsonContainer(); var objCourseHelper = new CourseHelper(); var courseDetails = new Course { userId = 0, courseName = courseName, startTime = startTime, endTime = endTime }; var dtCourse = objCourseHelper.SearchCourse(courseDetails); List <Course> courseList = new List <Course>(); foreach (DataRow dr in dtCourse.Rows) { var course = new Course { courseName = dr["courseName"].ToString(), courseDescription = dr["courseDescription"].ToString(), courseCategory = dr["courseCategory"].ToString(), startTime = dr["startTime"].ToString(), endTime = dr["endTime"].ToString(), numberOfStudent = long.Parse(dr["numberOfStudent"].ToString()), instructorName = dr["instructorName"].ToString() }; courseList.Add(course); } Jcon.Result = courseList.Distinct().OrderBy(x => x.courseName).ToList(); return(Json(Jcon)); }
public IActionResult OnGet(int?id) { int userId = 0; if (HttpContext.Session.GetInt32(SD.UserSessionId) != null) { if (HttpContext.Session.GetInt32(SD.UserSessionId).HasValue) { userId = HttpContext.Session.GetInt32(SD.UserSessionId).Value; } } UserObj = _unitOfWork.User.GetFirstorDefault(u => u.ID == userId); if (id == null) { return(NotFound()); } Assignment = _unitOfWork.Assignment.GetFirstorDefault(m => m.ID == id); var Avglist = new List <int>(); foreach (var item in _unitOfWork.Submission.GetAll(m => m.AssignmentId == Assignment.ID)) { Avglist.Add(item.Points); } if (_unitOfWork.Submission.GetFirstorDefault(m => m.AssignmentId == Assignment.ID && m.UserId == userId) != null) { SubmissionObj = _unitOfWork.Submission.GetAll(m => m.AssignmentId == Assignment.ID && m.UserId == userId).ToList(); } else { SubmissionObj = new List <Submission>(); SubmissionObj.Add(new Submission()); } Assignment.SubmissionId = SubmissionObj.LastOrDefault().ID; Assignment.Grade = SubmissionObj.LastOrDefault().Points; Assignment.Avg = "0"; if (Avglist.Count() > 0) { Assignment.Avg = Avglist.Average().ToString(); } courseHelper = new CourseHelper(); if (Assignment == null) { return(NotFound()); } return(Page()); }
public IHttpActionResult GetForCourse(int id) { var course = CourseHelper.GetById(id); using (var dc = new ArmsContext()) { dc.Configuration.LazyLoadingEnabled = false; var lectures = dc.Lectures.Include(x => x.Course).Where(x => x.CourseID == course.CourseID); return(Ok(lectures.ToList())); } }
// GET: Courses/userId // returns view containing all courses related to the logged in user public ActionResult Index(int userId) { List <Course> courses = null; if (CurrentWebContext.CurrentUser.Type == "student") { courses = CourseHelper.GetCoursesForParticipant(userId); } if (CurrentWebContext.CurrentUser.Type == "teacher") { courses = CourseHelper.GetCoursesForSupervisor(userId); } return(View(courses.ToList())); }
public void AddAttendee(int lectureId, string email) { var user = UserHelper.GetByEmail(email); if (user == null) { return; } var lecture = LectureHelper.GetById(lectureId); var studentStatus = CourseHelper.GetStudentStatusForCourse(user.UserID, lecture.CourseID); if (studentStatus == Participant.STATUS_ACTIVE) { var attendee = new Attendee(user.UserID, lectureId, ""); attendee.Insert(); } }
private static async Task <bool> doCourse(Operations operations) { if (token == null) { Authorizer authorizer = new Authorizer(); Console.WriteLine("calling authorize()"); token = await authorizer.Authorize(); Console.WriteLine("doCourse(): Token=" + token.ToString()); } CourseService courseService = new CourseService(token); if (operations.HasFlag(Operations.C)) { Course newCourse = CourseHelper.GenerateObject(); Course course = await courseService.CreateObject(newCourse); Console.WriteLine("Course Create: " + course.ToString()); } if (operations.HasFlag(Operations.R)) { Course course = await courseService.ReadObject(); Console.WriteLine("Course Read: " + course.ToString()); } if (operations.HasFlag(Operations.U)) { Course newCourse = CourseHelper.GenerateObject(); Course course = await courseService.UpdateObject(newCourse); Console.WriteLine("Course Update: " + course.ToString()); } if (operations.HasFlag(Operations.D)) { Course course = await courseService.DeleteObject(); Console.WriteLine("Course Delete: " + course.ToString()); } return(true); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } int userId = (int)HttpContext.Session.GetInt32(SD.UserSessionId); var isInstructor = await _context.User.Where(x => x.ID == userId).Where(x => x.UserType == 'I').AnyAsync(); if (!isInstructor) { return(NotFound()); } courseHelper = new CourseHelper(); courseValidationResponse = new CourseValidationResponse(); Course.InstructorID = userId; courseValidationResponse = courseHelper.ValidateCourse(Course); if (userId == null) { userId = 0; } //If user is not logged in or is not an instructor or the instructorId for the course is not the ID of the user, return unauthorized if (userId == 0 || !isInstructor || Course.InstructorID != userId) { return(Unauthorized()); } //Make sure that start time is before the end time if (courseValidationResponse.isValidated) { _context.Course.Add(Course); await _context.SaveChangesAsync(); } //TODO: Make error page return(RedirectToPage("./Index")); }
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.Item.ItemType == ListItemType.Item) { if (e.CommandName == "delete") { oucITEntities db = new oucITEntities(); if (CourseHelper.Delete(Convert.ToInt32(e.CommandArgument), db)) { JSHelper.Redirect("CourseList.aspx", true);//window.location.href='NewsList.aspx' } else { Response.Write("<script>alert('删除失败!');</script>"); } } } }
public async Task OnGetAsync() { var userId = HttpContext.Session.GetInt32(SD.UserSessionId); if (userId == null) { userId = 0; } User = _context.User.Where(x => x.ID == userId).FirstOrDefault(); var isInstructor = await _context.User.Where(x => x.ID == userId).Where(x => x.UserType == 'I').AnyAsync(); courseHelper = new CourseHelper(); if (isInstructor) { Course = await _context.Course.Where(x => x.InstructorID == userId).ToListAsync(); } else { var courseIds = await _context.Registration.Where(x => x.StudentID == userId).Select(x => x.CourseID).ToListAsync(); Course = new List <Models.Course>(); foreach (int id in courseIds) { Course.Add(await _context.Course.Where(x => x.ID == id).FirstOrDefaultAsync()); } } Assignment = new List <Models.Assignment>(); foreach (Models.Course course in Course) { var assignmentIds = await _context.Assignment.Where(x => x.CourseID == course.ID).Where(x => x.DueDate >= DateTime.Today).Select(x => x.ID).ToListAsync(); foreach (int id in assignmentIds) { Assignment.Add(await _context.Assignment.Where(x => x.ID == id).FirstOrDefaultAsync()); } } }
public ActionResult Create([Bind(Include = "CourseID,CourseName,CourseDescription,CreatorID")] Course course) { if (ModelState.IsValid) { if (CourseHelper.Exists(course.CourseName)) { ViewBag.Error = "Such a course name exists, please try with another!"; return(View()); } course.CreatorID = CurrentWebContext.CurrentUser.UserID; course.Insert(); var model = new Supervisor(CurrentWebContext.CurrentUser.UserID, course.CourseID); model.Insert(); return(RedirectToAction("Index", new { userId = CurrentWebContext.CurrentUser.UserID })); } return(View(course)); }
private void Btn_ok_Click(object sender, EventArgs e) { var inputCourseName = txt_courseName.Text; var inputCourseLength = txt_courseLength.Text; var inputCheckPoints = txt_checkPoints.Text.Replace(" ", ""); var inputErrorString = string.Empty; var inputError = false; // check inputs if (inputCourseName.Length <= 0) { inputErrorString = "Check course name." + Environment.NewLine; inputError = true; } if (!Int32.TryParse(inputCourseLength, out int courseLength_m)) { inputErrorString += $"Could not parse '{txt_courseLength.Text}' to a number." + Environment.NewLine; inputError = true; } if (!inputCheckPoints.Contains(',')) { inputErrorString += "Check checkpoints" + Environment.NewLine; inputError = true; } if (!IsDigitsOrDotsOnly(inputCheckPoints)) { inputErrorString += "Checkpoints contains unaccepted chars" + Environment.NewLine; inputError = true; } if (inputError) { return; } var checkPoints = inputCheckPoints.Split(',').Select(Int32.Parse).ToList(); var newCourse = CourseHelper.CreateACourseFromControlPointNumbers(checkPoints, courseLength_m, inputCourseName); //Create XML file WriteCoursesToXML(newCourse); }
public static bool CanChangeCourse(int courseId, ClaimsPrincipal principal) { var userEmail = APIUtils.GetCurrentUserEmail(principal); if (userEmail == null) { throw new Exception("Was unable to find the user name."); } var targetCourse = CourseHelper.GetById(courseId); var possible_creator = UserHelper.GetByEmail(userEmail); if (targetCourse != null) { return(targetCourse.CreatorID == possible_creator.UserID); } return(false); }
public IActionResult Details(long?Id) { using (StudentHelper helper = new StudentHelper()) { StudentCourseModel model = new StudentCourseModel(); model.SelectedCourses = new List <CourseModel>(); if (Id.HasValue) { model = helper.GetData(Id.Value); } using (CourseHelper chelper = new CourseHelper()) { model.Courses = chelper.GetList(); } if (!Id.HasValue || Id.Value == 0) { model.DateOfBirth = System.DateTime.Now; model.BirthDate = System.DateTime.Now.ToString("dd-MMM-yyyy"); } return(View(model)); } }
// GET: Courses/SeeDetailedOverview/courseId&studentId // returns detailed overviev view for the specified student and targeted course public ActionResult SeeDetailedOverview(int courseId, int studentId) { Course course = CourseHelper.GetById(courseId); User student = UserHelper.GetById(studentId); if (course == null || student == null) { return(HttpNotFound()); } var isSupervisor = SupervisorHelper.IsUserSupervisor(CurrentWebContext.CurrentUser.UserID, courseId); if (!isSupervisor) { return(new HttpStatusCodeResult(HttpStatusCode.Forbidden)); } ViewBag.AttendancePerformance = ParticipantHelper.GetParticipantAttendance(student.UserID, course.CourseID); var vm = DetailedOverviewForStudentVM.CreateDetailedOverviewForStudentVM(student, course); return(View(vm)); }
// GET: Courses/Details/courseId // returns details view with all related data depending on the logged in user public ActionResult Details(int?courseId) { if (courseId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // cast nullable int int id = (int)courseId; Course course = CourseHelper.GetById(id); if (course == null) { return(HttpNotFound()); } DetailedCourseVM viewModel = null; // check if the current user is a student and setup accordingly the view model if (CurrentWebContext.CurrentUser.Type == "student") { ViewBag.IsParticipant = false; viewModel = new DetailedCourseVM(course); viewModel.Lectures = LectureHelper.GetLecturesForCourse(course.CourseID); // get the type of student for this course ViewBag.StatusOfStudent = CourseHelper.GetStudentStatusForCourse(CurrentWebContext.CurrentUser.UserID, course.CourseID); } // check if the current user is a teacher and create the view model for him if (CurrentWebContext.CurrentUser.Type == "teacher") { viewModel = DetailedCourseVM.CreateDetailedCourseVMW(course); ViewBag.CountOfPendingStudents = ParticipantHelper.GetCountOfPendingParticipants(id); } return(View(viewModel)); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { oucITEntities db = new oucITEntities(); string temTitle = "物理系"; if (Request.QueryString["type"] != "本科生教育") { Response.Redirect("index.aspx"); } if (Request.QueryString["item"] != null) { temTitle = Request.QueryString["item"]; } // 绑定院系名称 lbdepartment.Text = temTitle.Replace('<', ' ').Replace('>', ' ').Replace('"', ' '); lbenglishDepart.Text = ArticleHelper.GetEnglishItems(temTitle); // 绑定课程repeater switch (temTitle) { case "电子工程系": lbtnMajor1.Text = "电子信息科学与技术"; lbtnMajor1.Visible = true; lbtnMajor2.Text = "电子信息工程"; lbtnMajor2.Visible = true; lbtnMajor3.Text = "通信工程"; lbtnMajor3.Visible = true; Repeater1.DataSource = CourseHelper.GetCoursesOfTheMajor("电子信息科学与技术", db); Repeater1.DataBind(); Repeater2.DataSource = CourseHelper.GetCoursesOfTheMajor("电子信息工程", db); Repeater2.DataBind(); Repeater3.DataSource = CourseHelper.GetCoursesOfTheMajor("通信工程", db); Repeater3.DataBind(); break; case "物理系": lbtnMajor1.Text = "物理学"; lbtnMajor1.Visible = true; lbtnMajor2.Text = "光信息科学与技术"; lbtnMajor2.Visible = true; Repeater1.DataSource = CourseHelper.GetCoursesOfTheMajor("物理学", db); Repeater1.DataBind(); Repeater2.DataSource = CourseHelper.GetCoursesOfTheMajor("光信息科学与技术", db); Repeater2.DataBind(); break; case "计算机科学与技术系": lbtnMajor1.Text = "计算机科学与技术"; lbtnMajor1.Visible = true; Repeater1.DataSource = CourseHelper.GetCoursesOfTheMajor("计算机科学与技术", db); Repeater1.DataBind(); break; case "海洋技术系": lbtnMajor1.Text = "海洋技术"; lbtnMajor1.Visible = true; Repeater1.DataSource = CourseHelper.GetCoursesOfTheMajor("海洋技术", db); Repeater1.DataBind(); break; default: Response.Redirect("index.aspx"); break; } } }
public AccountController() { _db = new ApplicationDbContext(); courseHelper = new CourseHelper(_db); }
public CoursesController() { rolesManger = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>()); userManager = new UserManager <IdentityUser>(new UserStore <IdentityUser>()); ch = new CourseHelper(db); }
public ActionResult addCourse(string courseName, string courseDesc, string courseCategory, string startTime, string endTime, long noOfStudents) { int valid = 1; var Jcon = new JsonContainer(); var objCourseHelper = new CourseHelper(); var courseDetails = new Course { userId = long.Parse(Session["userId"].ToString()), courseName = string.Empty, startTime = string.Empty, endTime = string.Empty }; try { var dtCourse = objCourseHelper.SearchCourse(courseDetails); courseDetails.courseName = courseName; courseDetails.courseDescription = courseDesc; courseDetails.courseCategory = courseCategory; courseDetails.startTime = startTime; courseDetails.endTime = endTime; courseDetails.numberOfStudent = noOfStudents; if (dtCourse.Rows.Count <= 0) { objCourseHelper.InsertCourse(courseDetails); } else { var isValid = true; var dummyStartTime = DateTime.Parse(startTime); var dummyEndTime = DateTime.Parse(endTime); //check condition for valid timing foreach (DataRow row in dtCourse.Rows) { var rowStartTime = DateTime.Parse(row["startTime"].ToString()); var rowEndTime = DateTime.Parse(row["endTime"].ToString()); if (dummyStartTime < rowStartTime && dummyEndTime > rowEndTime) { isValid = false; } else if (dummyStartTime > rowStartTime && dummyStartTime < rowEndTime) { isValid = false; } else if (dummyEndTime > rowStartTime && dummyEndTime < rowEndTime) { isValid = false; } if (!isValid) { Jcon.Result = -1; return(Json(Jcon)); } } if (isValid) { objCourseHelper.InsertCourse(courseDetails); } } } catch (Exception ex) { valid = 0; } Jcon.Result = valid; return(Json(Jcon)); }
public IHttpActionResult GetById(int id) { Course course = CourseHelper.GetById(id); return(Ok(course)); }