protected void UploadButton_Click(object sender, EventArgs e) { if (FileUploadControl.HasFile) { LTISpoof sessionData; int reviewID; string filename, filepath; //string org = Session["OrganizationID"].ToString(); //int course = (int)Session["CourseID"]; //string lab = Session["AssignmentName"].ToString(); //string lnum = Session["StudentID"].ToString(); //string filepath = Session["OrganizationID"].ToString() + "/" // + Session["CourseID"].ToString() + "/" // + Session["AssignmentName"].ToString() + "/" // + Session["StudentID"].ToString() + "/"; try { sessionData = new LTISpoof() { Name = Session["StudentName"].ToString(), StudentID = Session["StudentID"].ToString(), OrganizationID = Session["OrganizationID"].ToString(), CourseID = (int)Session["CourseID"], Roles = Session["UserRoles"].ToString(), AssignmentName = Session["AssignmentName"].ToString() }; reviewID = (int)Session["ReviewID"]; filename = Path.GetFileName(FileUploadControl.FileName); filepath = Server.MapPath("~/App_Data/" + filename); FileUploadControl.SaveAs(filepath); StatusLabel.Text = "Upload status: File uploaded! "; } catch (Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message + " : " + ex.StackTrace; return; } using (PeerReviewModel db = new PeerReviewModel()) { //retrieve incomplete review var review = db.Reviews.Find((int)Session["ReviewID"]); if (review == null) { StatusLabel.Text = "Error: Review could not be retrieved."; return; } review.FilePath = filepath; db.Entry(review).State = EntityState.Modified; db.SaveChanges(); } } }
public ActionResult Edit([Bind(Include = "ID,AssignmentGroup,FilePath")] Submission submission) { if (ModelState.IsValid) { db.Entry(submission).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(submission)); }
public ActionResult Edit([Bind(Include = "OrganizationID,CourseID,StudentID,Name,Group")] Student student) { if (ModelState.IsValid) { db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(student)); }
public ActionResult Edit([Bind(Include = "ID,FilePath")] Review review) { if (ModelState.IsValid) { db.Entry(review).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(review)); }
public ActionResult Create([Bind(Include = "AssignmentAppID")] AssignmentGroup assignmentGroup) { assignmentGroup.OrganizationID = Session["OrganizationID"].ToString(); assignmentGroup.CourseID = (int)Session["CourseID"]; assignmentGroup.ReviewAppID = Session["AssignmentName"].ToString(); //check if assignmentgroup already exists var dbGroup = db.AssignmentGroups.Find(assignmentGroup.OrganizationID, assignmentGroup.CourseID, assignmentGroup.ReviewAppID); if (dbGroup == null && ModelState.IsValid) { //create new db.AssignmentGroups.Add(assignmentGroup); db.SaveChanges(); } else { //edit old db.Entry(assignmentGroup).State = EntityState.Modified; db.SaveChanges(); } return(RedirectToAction("ReviewAdmin", "Tool")); }
protected void UploadButton_Click(object sender, EventArgs e) { if (FileUploadControl.HasFile) { string filename = "File upload failed"; string org = Session["OrganizationID"].ToString(); int course = (int)Session["CourseID"]; string lab = Session["AssignmentName"].ToString(); string lnum = Session["StudentID"].ToString(); string filepath = Session["OrganizationID"].ToString() + "/" + Session["CourseID"].ToString() + "/" + Session["AssignmentName"].ToString() + "/" + Session["StudentID"].ToString() + "/"; try { filename = Path.GetFileName(FileUploadControl.FileName); FileUploadControl.SaveAs(Server.MapPath("~/App_Data/" + filename)); StatusLabel.Text = "Upload status: File uploaded! "; } catch (Exception ex) { StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message + "/n" + ex.StackTrace; } //add submission to database using (PeerReviewModel db = new PeerReviewModel()) { //db.Database.Delete(); //db.Database.Create(); //get student var student = db.Students.Find(org, course, lnum); if (student == null) { //throw error } //get list of student's submissions var studentSubmissions = student.Submissions; if (studentSubmissions != null && studentSubmissions.Count > 0) { //update submission with new file foreach (Submission s in studentSubmissions) { if (s.AssignmentGroup == Session["AssignmentName"].ToString() && s.Submitter.Equals(student)) { //TODO: delete old file s.FilePath = Server.MapPath("~/App_Data/" + filename); db.Entry(s).State = EntityState.Modified; db.SaveChanges(); return; } } } //create submission db.Submissions.Add(new Submission() { Submitter = student, AssignmentGroup = Session["AssignmentName"].ToString(), FilePath = Server.MapPath("~/App_Data/" + filename) }); db.SaveChanges(); } } }
protected void Page_Load(object sender, EventArgs e) { LTISpoof sessionData; try { sessionData = new LTISpoof() { Name = Session["StudentName"].ToString(), StudentID = Session["StudentID"].ToString(), OrganizationID = Session["OrganizationID"].ToString(), CourseID = (int)Session["CourseID"], Roles = Session["UserRoles"].ToString(), AssignmentName = Session["AssignmentName"].ToString() }; } catch (Exception ex) { StatusLabel.Text = "Session Error: " + ex.Message; return; } using (PeerReviewModel db = new PeerReviewModel()) { //get student var student = db.Students.Where(s => s.OrganizationID == sessionData.OrganizationID && s.CourseID == sessionData.CourseID && s.StudentID == sessionData.StudentID).Include("Reviews") .Include("Reviews.ReviewedSubmission") .Include("Reviews.ReviewedSubmission.Submitter") .FirstOrDefault(); //var student = db.Students.Find(sessionData.OrganizationID, sessionData.CourseID, sessionData.StudentID); //db.Entry(student).Reference(s => s.Reviews).Load(); if (student == null) { //if user does not exist, display error StatusLabel.Text = "You have not been registered to use this tool. Contact your instructor for assistance."; return;//TODO: redirect to error screen } //check if student has unfinished review var reviewList = student.Reviews.ToList(); for (int j = 0; j < reviewList.Count; j++) { var r = reviewList[j]; db.Entry(r).Reference(s => s.ReviewedSubmission).Load(); if (String.IsNullOrWhiteSpace(r.FilePath)) { //display incomplete review SubmitterNameLabel.Text = r.ReviewedSubmission.Submitter.Name; SubmissionNameLabel.Text = r.ReviewedSubmission.AssignmentGroup; GroupLabel.Text = r.ReviewedSubmission.Submitter.Group; //save review id to session Session["ReviewID"] = r.ID; return; } } foreach (Review r in student.Reviews) { } List <Submission> submissions = new List <Submission>(); int i = 0; do { submissions = db.Submissions .Where(s => s.Submitter.OrganizationID == sessionData.OrganizationID && s.Submitter.CourseID == sessionData.CourseID && s.Submitter.Group != student.Group && s.Reviews.Count <= i) .Include("Submitter") .ToList(); i++; } while (submissions == null || submissions.Count < 1 || i > 2); if (submissions == null || submissions.Count == 0) { StatusLabel.Text = "All submissions reviewed." + " Each submitted assignment from another group already has 3 or more reviews. Check back later."; } else { //get random submission Random rand = new Random(); int randNum = rand.Next(submissions.Count); var submission = submissions[randNum]; if (submission == null) { StatusLabel.Text = "Error: the randomly selected submission was null!"; return; } //add incomplete review Review review = new Review() { Reviewer = student, ReviewedSubmission = submission }; db.Reviews.Add(review); db.SaveChanges(); //display incomplete review SubmitterNameLabel.Text = review.ReviewedSubmission.Submitter.Name; SubmissionNameLabel.Text = review.ReviewedSubmission.AssignmentGroup; GroupLabel.Text = review.ReviewedSubmission.Submitter.Group; //save review id to session Session["ReviewID"] = review.ID; } //get list of submissions with i++ reviews belonging to a different student group //display review input form for random submission } }
public ActionResult Upload() { Session["TestMessage"] = "Session Works!"; LTISpoof sessionData; try { // Parse and validate the request Request.CheckForRequiredLtiParameters(); var ltiRequest = new LtiRequest(null); ltiRequest.ParseRequest(Request); if (!ltiRequest.ConsumerKey.Equals("12345")) { ViewBag.Message = "Invalid Consumer Key"; return(View()); } var oauthSignature = Request.GenerateOAuthSignature("secret"); if (!oauthSignature.Equals(ltiRequest.Signature)) { ViewBag.Message = "Invalid Signature"; return(View()); } Session["StudentName"] = ltiRequest.LisPersonNameFull; Session["StudentID"] = ltiRequest.LisPersonEmailPrimary; //Session["StudentID"] = ltiRequest.LisPersonSourcedId; Session["OrganizationID"] = ltiRequest.ToolConsumerInstanceGuid; Session["CourseID"] = int.Parse(ltiRequest.ContextId);//TODO: replace with string; more versitile Session["UserRoles"] = ltiRequest.Roles; Session["AssignmentName"] = ltiRequest.ResourceLinkTitle; sessionData = new LTISpoof() { Name = Session["StudentName"].ToString(), StudentID = Session["StudentID"].ToString(), OrganizationID = Session["OrganizationID"].ToString(), CourseID = (int)Session["CourseID"], Roles = Session["UserRoles"].ToString(), AssignmentName = Session["AssignmentName"].ToString() }; // The request is legit, so display the tool ViewBag.Message = string.Empty; var model = new ToolModel { ConsumerSecret = "secret", LtiRequest = ltiRequest }; //check if user is an instructor or admin if (Session["UserRoles"] != null && (Session["UserRoles"].ToString().Contains("Instructor") || Session["UserRoles"].ToString().Contains("Admin"))) { //if they are, redirect to dashboard return(RedirectToAction("Admin")); } using (PeerReviewModel db = new PeerReviewModel()) { //check if user exists var student = db.Students.Find(sessionData.OrganizationID, sessionData.CourseID, sessionData.StudentID); if (student == null) { //if user does not exist, display error ViewBag.Message = "You have not been registered to use this tool. Contact your instructor for assistance."; return(View()); } else { //if they do, update the entry with their name student.Name = Session["StudentName"].ToString(); db.Entry(student).State = EntityState.Modified; db.SaveChanges(); return(Redirect(url: "~/upload.aspx")); } } } catch (LtiException e) { ViewBag.Message = e.Message; //return Redirect(url: "~/upload.aspx"); return(View()); } }
public ActionResult Review() { Session["TestMessage"] = "Session Works!"; LTISpoof sessionData; try { // Parse and validate the request Request.CheckForRequiredLtiParameters(); var ltiRequest = new LtiRequest(null); ltiRequest.ParseRequest(Request); if (!ltiRequest.ConsumerKey.Equals("12345")) { ViewBag.Message = "Invalid Consumer Key"; return(View()); } var oauthSignature = Request.GenerateOAuthSignature("secret"); if (!oauthSignature.Equals(ltiRequest.Signature)) { ViewBag.Message = "Invalid Signature"; return(View()); } Session["StudentName"] = ltiRequest.LisPersonNameFull; Session["StudentID"] = ltiRequest.LisPersonEmailPrimary; //Session["StudentID"] = ltiRequest.LisPersonSourcedId; Session["OrganizationID"] = ltiRequest.ToolConsumerInstanceGuid; Session["CourseID"] = int.Parse(ltiRequest.ContextId);//TODO: replace with string; more versitile Session["UserRoles"] = ltiRequest.Roles; Session["AssignmentName"] = ltiRequest.ResourceLinkTitle; sessionData = new LTISpoof() { Name = Session["StudentName"].ToString(), StudentID = Session["StudentID"].ToString(), OrganizationID = Session["OrganizationID"].ToString(), CourseID = (int)Session["CourseID"], Roles = Session["UserRoles"].ToString(), AssignmentName = Session["AssignmentName"].ToString() }; // The request is legit, so display the tool ViewBag.Message = string.Empty; var model = new ToolModel { ConsumerSecret = "secret", LtiRequest = ltiRequest }; //check if user is an instructor or admin if (sessionData.Roles != null && (sessionData.Roles.Contains("Instructor") || sessionData.Roles.Contains("Admin"))) { //if they are, redirect to dashboard return(RedirectToAction("ReviewAdmin")); } using (PeerReviewModel db = new PeerReviewModel()) { //check if user exists var student = db.Students.Find(sessionData.OrganizationID, sessionData.CourseID, sessionData.StudentID); if (student == null) { //if user does not exist, display error ViewBag.Message = "You have not been registered to use this tool. Contact your instructor for assistance."; return(View());//TODO: redirect to error screen } else { //if they do, update the entry with their name student.Name = sessionData.Name; db.Entry(student).State = EntityState.Modified; db.SaveChanges(); } //create the view model var viewModel = new ReviewHome() { ReviewerName = sessionData.Name, AssignmentName = sessionData.AssignmentName, FinishedReviews = student.Reviews.Count }; //check that review tool has been registered var assignmentGroup = db.AssignmentGroups.Find(sessionData.OrganizationID, sessionData.CourseID, sessionData.AssignmentName); if (assignmentGroup == null || string.IsNullOrWhiteSpace(assignmentGroup.AssignmentAppID)) { ViewBag.Message = "This review tool has not been registered with a submission assignment. Contact your instructor to resolve this issue."; return(View(viewModel));//TODO: redirect to error screen } //get list of submissions in assignment group List <Submission> submissions = db.Submissions .Where(s => s.Submitter.OrganizationID == sessionData.OrganizationID && s.Submitter.CourseID == sessionData.CourseID) .ToList(); if (submissions == null || submissions.Count == 0) { ViewBag.Message = "No submissions found." + " Either no assignments have been submitted, or the review tool is registered incorrectly."; return(View(viewModel)); } submissions = db.Submissions .Where(s => s.Submitter.OrganizationID == sessionData.OrganizationID && s.Submitter.CourseID == sessionData.CourseID && s.Submitter.Group != student.Group) .ToList(); if (submissions == null || submissions.Count == 0) { ViewBag.Message = "No submissions found for you to review." + " No student from another group has submitted an assignment yet. Check back later."; return(View(viewModel)); } return(View(viewModel)); } } catch (LtiException e) { ViewBag.Message = e.Message; //return Redirect(url: "~/upload.aspx"); return(View()); } }