public void DeleteSection(int id) { using (var model = new graderEntities()) { var sectionExist = (from CourseInstance in model.CourseInstances where CourseInstance.CourseInstanceID == id select CourseInstance).First(); if (sectionExist == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } foreach (var scr in model.StudentCourseRegistrations.Where(s => s.CourseInstanceID == sectionExist.CourseInstanceID)) { foreach (var sub in model.SUBMISSIONs.Where(sb => sb.StudentCourseRegistrationID == scr.StudentCourseRegistrationID)) { model.SUBMISSIONs.Remove(sub); } model.StudentCourseRegistrations.Remove(scr); } foreach (var c in model.Course_Assignments.Where(ca => ca.CourseInstanceID == sectionExist.CourseInstanceID)) { model.Course_Assignments.Remove(c); } model.CourseInstances.Remove(sectionExist); model.SaveChanges(); } }
//[ValidateAntiForgeryToken] public ActionResult LogOff() { //System.Web.HttpContext.Current.Session.Timeout = 10; User user; try { user = new graderEntities().Users.Where(u => u.Email == System.Web.HttpContext.Current.User.Identity.Name).First(); } catch (Exception e) { return(RedirectToAction("Login", "Account")); } try { // Setting. var ctx = Request.GetOwinContext(); var authenticationManager = ctx.Authentication; // Sign Out. authenticationManager.SignOut(); } catch (Exception ex) { // Info return(RedirectToAction("Index", "Account")); } // Info. return(this.RedirectToAction("Index", "Home")); }
/// <summary> /// Student Index. /// </summary> /// <returns>Student home page view.</returns> public ActionResult Index() { User user; try { user = getCurrentUser(); } catch (Exception e) { return(RedirectToAction("Login", "Account")); } if (user.UserRoleID != 2) { return(RedirectToAction("AccessDenied", "Home")); } var entity = new graderEntities(); MultiViewModel MVM = new MultiViewModel(); MVM.SCRs = entity.StudentCourseRegistrations.Where(p => p.STUDENTID == user.UserId); MVM.CourseAssignments = GetCourseAssignments(); MVM.CourseInstances = GetCourseInstances(); MVM.Assignments = GetAssignments(); MVM.Submissions = GetSubmissions(); MVM.Courses = GetCourses(); return(View(MVM)); }
public void DeleteUser(int id) { using (var model = new graderEntities()) { var user = (from User in model.Users where User.UserId == id select User).First(); if (user == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (user.UserRoleID != 4 || model.Users.Where(u => u.UserRoleID == 4).Count() != 1) { foreach (StudentCourseRegistration scr in model.StudentCourseRegistrations.Where(s => s.STUDENTID == id)) { foreach (SUBMISSION s in model.SUBMISSIONs.Where(a => a.StudentCourseRegistrationID == scr.StudentCourseRegistrationID)) { model.SUBMISSIONs.Remove(s); } model.StudentCourseRegistrations.Remove(scr); } model.Users.Remove(user); model.SaveChanges(); } } }
public void DeleteQuestion(int id) { using (var model = new graderEntities()) { var questionExist = model.Questions.SingleOrDefault(q => q.QuestionID == id); if (questionExist == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } model.Questions.Remove(questionExist); model.SaveChanges(); } }
/// <summary> /// Gets the student-course registrations of a certain student. /// </summary> /// <param name="id">The identifier of the student.</param> /// <returns>The student-course registrations of a certain student</returns> public IEnumerable <StudentCourseRegistration> SCRbyStudentId(int id) { IEnumerable <StudentCourseRegistration> scr1; IEnumerable <StudentCourseRegistration> scr2 = null; using (var model = new graderEntities()) { scr1 = model.StudentCourseRegistrations; foreach (StudentCourseRegistration s in scr1) { if (s.STUDENTID == id) { scr2.ToList().Add(s); } } } return(scr2); }
public void DeleteStudent(int id) { using (var model = new graderEntities()) { StudentCourseRegistration scr = model.StudentCourseRegistrations.Where(s => s.StudentCourseRegistrationID == id).First(); if (scr == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } foreach (var sub in model.SUBMISSIONs.Where(sb => sb.StudentCourseRegistrationID == scr.StudentCourseRegistrationID)) { model.SUBMISSIONs.Remove(sub); } model.StudentCourseRegistrations.Remove(scr); model.SaveChanges(); } }
/// <summary> /// Displays the teachers and admins specific to the logged in student to for contact. /// </summary> /// <returns>Contact view page</returns> public ActionResult Contact() { User userC; try { userC = getCurrentUser(); } catch (Exception e) { return(RedirectToAction("Login", "Account")); } if (userC.UserRoleID != 2) { return(RedirectToAction("AccessDenied", "Home")); } ViewBag.Message = "Your contact page"; User user = getCurrentUser(); List <User> users = new List <User>(); using (var model = new graderEntities()) { foreach (User u in model.Users.Where(a => a.UserRoleID == 4)) { users.Add(u); } foreach (StudentCourseRegistration s in model.StudentCourseRegistrations.Where(a => a.STUDENTID == user.UserId)) { if (!users.Contains(model.Users.Where(u => u.UserId == model.CourseInstances.Where(c => c.CourseInstanceID == s.CourseInstanceID).FirstOrDefault().TEACHERID).FirstOrDefault())) { users.Add(model.Users.Where(u => u.UserId == model.CourseInstances.Where(c => c.CourseInstanceID == s.CourseInstanceID).FirstOrDefault().TEACHERID).FirstOrDefault()); } } } return(View(users)); }
/// <summary> /// Home Index /// </summary> /// <returns>The landing page view</returns> public ActionResult Index() { User user; try { user = new graderEntities().Users.Where(u => u.Email == System.Web.HttpContext.Current.User.Identity.Name).First(); if (user.UserRoleID == 2) { return(Redirect("http://bobthegrader.azurewebsites.net/Students/Index")); } if (user.UserRoleID >= 3) { return(RedirectToAction("Index", "Teachers")); } } catch (Exception e) { } return(View()); }
public void DeleteAssignment(int id) { using (var model = new graderEntities()) { var assignmentExist = (from Course_Assignments in model.Course_Assignments where Course_Assignments.Course_AssignmentsID == id select Course_Assignments).First(); if (assignmentExist == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } foreach (Question q in model.Questions.Where(q => q.AssignmentID == assignmentExist.AssignmentID)) { foreach (StudentCourseRegistration scr in model.StudentCourseRegistrations.Where(s => s.CourseInstanceID == assignmentExist.CourseInstanceID)) { SUBMISSION sub = model.SUBMISSIONs.Where(s => s.StudentCourseRegistrationID == scr.StudentCourseRegistrationID && s.QuestionID == q.QuestionID).First(); model.SUBMISSIONs.Remove(sub); } } model.Course_Assignments.Remove(assignmentExist); model.SaveChanges(); } }
public void DeleteAssignment(int id) { using (var model = new graderEntities()) { var assignmentExist = (from Assignment in model.Assignments where Assignment.AssignmentID == id select Assignment).First(); if (assignmentExist == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } foreach (Question q in model.Questions.Where(q => q.AssignmentID == assignmentExist.AssignmentID)) { foreach (SUBMISSION sub in model.SUBMISSIONs.Where(s => s.QuestionID == q.QuestionID)) { model.SUBMISSIONs.Remove(sub); } model.Questions.Remove(q); } model.Assignments.Remove(assignmentExist); model.SaveChanges(); } }
//[ValidateAntiForgeryToken] public ActionResult Login(LoginViewModel model, string returnUrl) { string mail = model.Email; string password = model.Password; bool checkEmail = false; bool checkPass = false; foreach (User u in new graderEntities().Users) { if (mail.ToLower().Equals(u.Email.ToLower())) { checkEmail = true; if (password.Equals(u.Password)) { checkPass = true; } break; } } if (checkEmail && checkPass) { try { // Verification. if (ModelState.IsValid) { // Initialization. var loginInfo = this.databaseManager.LoginByUsernamePassword(model.Email, model.Password).ToList(); // Verification. if (loginInfo != null && loginInfo.Count() > 0) { // Initialization. var logindetails = loginInfo.First(); // Login In. this.SignInUser(logindetails.email, false); // Info. string s = ""; string email = model.Email; User current = new graderEntities().Users.Where(u => u.Email == email).First(); if (current.UserRoleID == 2) { //Response.Redirect("~/Students/"); s = "http://bobthegrader.azurewebsites.net/Students/Index"; } else if (current.UserRoleID == 3 || current.UserRoleID == 4) { //Response.Redirect("~/Teachers/"); s = "http://bobthegrader.azurewebsites.net/Teachers/Index"; } else { s = "http://bobthegrader.azurewebsites.net/Home/AccessDenied"; } return(this.RedirectToLocal(s)); } else { // Setting. ModelState.AddModelError(string.Empty, "Invalid username or password."); } } } catch (Exception ex) { throw new Exception("bob is real"); } } else { ViewBag.message = "<p style='color: #d9230f'>Incorrect email or password.</p>"; return(View(model)); } // If we got this far, something failed, redisplay form //return this.View(model); return(this.RedirectToLocal(returnUrl)); }
public ActionResult Register(User user) { string email = user.Email; bool check = false; foreach (User u in new graderEntities().Users) { if (email.ToLower().Equals(u.Email.ToLower())) { check = true; break; } } if (check == false) { using (var db = new graderEntities()) { user.UserRoleID = 2; int max = db.Users.Select(u => u.UserId).DefaultIfEmpty().Max() + 1; user.UserId = max; try { db.Users.Add(user); } catch (System.Data.SqlClient.SqlException e) { Response.Write("<script>alert('Email already exists!')</script>"); return(RedirectToAction("Register", "Account")); } foreach (Course c in db.Courses.Where(c => c.Deadline >= DateTime.Now)) { foreach (CourseInstance ci in db.CourseInstances.Where(i => i.CourseID == c.CourseID)) { DirectoryInfo dir = new DirectoryInfo(@"D:\home\site\wwwroot\Files\SCR\" + ci.CourseInstanceID); if (dir.Exists) { StreamReader read = new StreamReader(dir.GetFiles().First().FullName); List <string> left = new List <string>(); var mail = read.ReadLine(); bool change = false; while (mail != null) { if (mail.ToLower().Equals(user.Email.ToLower())) { change = true; StudentCourseRegistration scr = new StudentCourseRegistration { CourseInstanceID = ci.CourseInstanceID, STUDENTID = user.UserId }; db.StudentCourseRegistrations.Add(scr); foreach (var casgm in db.Course_Assignments.Where(ca => ca.CourseInstanceID == scr.CourseInstanceID)) { foreach (var q in db.Questions.Where(q => q.AssignmentID == casgm.AssignmentID)) { SUBMISSION sub = new SUBMISSION(); sub.StudentCourseRegistrationID = scr.StudentCourseRegistrationID; sub.GRADE = 0; sub.QuestionID = q.QuestionID; sub.TRIES = 0; sub.FILE = null; sub.SubmittedDate = null; sub.Result = null; db.SUBMISSIONs.Add(sub); } } } else { left.Add(mail); } mail = read.ReadLine(); } read.Close(); if (change) { StreamWriter write = new StreamWriter(dir.GetFiles().First().FullName); foreach (var name in left) { write.WriteLine(name); } ; write.Close(); } } } } db.SaveChanges(); } } else { ViewBag.message = "<p style='color: #d9230f'>Email already exists.</p>"; return(View(user)); } return(RedirectToAction("LogIn", "Account")); }
public ActionResult Submit(HttpPostedFileBase file, int id) { User user; try { user = getCurrentUser(); } catch (Exception e) { return(RedirectToAction("Login", "Account")); } if (user.UserRoleID != 2) { return(RedirectToAction("AccessDenied", "Home")); } MultiViewModel MVM = new MultiViewModel(); using (var model = new graderEntities()) { Course_Assignments cas = (from Course_Assignments in model.Course_Assignments where Course_Assignments.Course_AssignmentsID == id select Course_Assignments).First(); int aid = cas.AssignmentID; Assignment assignment = (from Assignment in model.Assignments where Assignment.AssignmentID == aid select Assignment).First(); IEnumerable <Question> questions = (from Question in model.Questions where Question.AssignmentID == aid select Question).ToList(); IEnumerable <SUBMISSION> subs = (from SUBMISSION in model.SUBMISSIONs select SUBMISSION).ToList(); int qid = int.Parse(Request["questionID"]); int subid = int.Parse(Request["subID"]); SUBMISSION sub = (from SUBMISSION in model.SUBMISSIONs where SUBMISSION.SubmissionID == subid select SUBMISSION).First(); if (file == null) { return(RedirectToAction("Submit")); } if (file.ContentLength >= 0) { //-->should add a message "Already solved" if (sub.Result != null) { if (sub.Result.Equals("Solved!")) { return(RedirectToAction("Index")); } } Question question = (from Question in model.Questions where Question.QuestionID == qid select Question).First(); //-->should add a message "No more tries left" if (question.MaximumTries == sub.TRIES) { return(RedirectToAction("Index")); } ; //-->should add a message "Deadline passed" if (assignment.DEADLINE < DateTime.Now) { return(RedirectToAction("Index")); } sub.SubmittedDate = DateTime.Now; string extension = Path.GetExtension(file.FileName); // the reading happens through a text file, i think we can also read the static java file //if needed if (extension == ".zip") { var fileName = Path.GetFileName(file.FileName); string path = Server.MapPath(@"~\Files") + "\\" + System.Web.HttpContext.Current.User.Identity.Name.Substring(0, System.Web.HttpContext.Current.User.Identity.Name.IndexOf("@")) + "\\" + assignment.AssignmentID + "\\" + question.QuestionID; GC.Collect(); GC.WaitForPendingFinalizers(); if (Directory.Exists(path)) { DirectoryInfo di = new DirectoryInfo(path); foreach (FileInfo fil in di.GetFiles()) { fil.Delete(); } } Directory.CreateDirectory(Server.MapPath(@"~\Files") + "\\" + System.Web.HttpContext.Current.User.Identity.Name.Substring(0, System.Web.HttpContext.Current.User.Identity.Name.IndexOf("@")) + "\\" + assignment.AssignmentID + "\\" + question.QuestionID); path = Path.Combine(path, fileName); file.SaveAs(path); ViewBag.HtmlStr = Request["submit"].Substring(17); int line = Program.run(subid, path); string output = ""; //right format if (line > -10003) { sub.TRIES++; if (line == 0) { output = "Solved!"; sub.GRADE = question.MaximumGrade - question.MaximumGrade * (sub.TRIES - 1) / question.MaximumTries; } else if (line == -10001) { output = "No output provided."; } else if (line == -10002) { output = "Compilation Error."; } else if (line > 0) { output = "Wrong value(s) starting line " + line; } else { output = "Excess of lines in output starting line " + (-line); } } else if (line == -10006) { output = "No Files Found."; } else if (line == -10005) { output = "Directory Not Found. Please Resubmit."; } else if (line == -10004) { output = "No Java File Found."; } else if (line == -10003) { output = "Excess of Files. Non Java Files Found."; } sub.Result = output; sub.FILE = Path.GetDirectoryName(path); model.SaveChanges(); MVM.assignment = assignment; MVM.Questions = questions; MVM.Submissions = subs; Thread.Sleep(3000); return(RedirectToAction("Submit", "Students", new { id = cas.Course_AssignmentsID })); } else { sub.Result = "File submitted is not of correct format."; model.SaveChanges(); return(RedirectToAction("Submit", "Students", new { id = cas.Course_AssignmentsID })); } } else { return(RedirectToAction("Submit", "Students", new { id = cas.Course_AssignmentsID })); } } }