public ActionResult ViewResponse(int id) { if (Session["username"] == null || Session["usertype"] == null) { return(RedirectToRoute(new { controller = "Index", action = "Index", id = 1 })); } AssignmentSolutionModel asModel = new AssignmentSolutionModel(); List <Solution> listSolutions = new List <Solution>(); using (XorHubEntities db = new XorHubEntities()) { asModel.Assignment = db.Assignments.Where(a => a.AssignmentId == id).FirstOrDefault(); listSolutions = db.Solutions.Where(s => s.AssignmentId == id && s.Stat.Equals("A")).ToList(); } ViewBag.solutions = listSolutions; return(View(asModel)); }
public new ActionResult Response(int id) { if (Session["username"] == null || Session["usertype"] == null) { return(RedirectToRoute(new { controller = "Index", action = "Index", id = 1 })); } Solution sol = new Solution(); using (XorHubEntities db = new XorHubEntities()) { sol = db.Solutions.Where(s => s.SolutionId == id).FirstOrDefault(); sol.Assignment = db.Assignments.Where(a => a.AssignmentId == sol.AssignmentId).FirstOrDefault(); } if (Session["usertype"].ToString().Equals("T")) { ViewBag.IsDisplay = true; } else { ViewBag.IsDisplay = false; } return(View(sol)); }
public ActionResult Login(LoginInfo model) { using (XorHubEntities db = new XorHubEntities()) { List <SelectListItem> list = new List <SelectListItem>(); foreach (var item in db.Batches) { list.Add(new SelectListItem { Text = item.Name, Value = item.BatchId.ToString() }); } ViewData["BatchList"] = list; } if (ModelState["Username"].Errors.Count > 0 || ModelState["Passwd"].Errors.Count > 0) { return(View("Index", model)); } using (XorHubEntities db = new XorHubEntities()) { model = db.LoginInfoes.Where(u => u.Username.Equals(model.Username) && u.Passwd.Equals(model.Passwd)).FirstOrDefault(); if (model == null) { ViewBag.Message = "Invalid Username or password!!"; ModelState.Clear(); return(View("Index")); } } if (model.Usertype.Equals("T")) { if (!model.Stat) { ViewBag.Message = "User Not Authorized! Contact Admin.."; return(View("Index")); } else { Session["username"] = model.Username; Session["usertype"] = model.Usertype; ViewBag.username = model.Username; return(RedirectToAction("Teacher", "home")); } } if (model.Usertype.Equals("A")) { Session["username"] = model.Username; Session["usertype"] = model.Usertype; ViewBag.username = model.Username; return(RedirectToAction("Admin", "home")); } Session["username"] = model.Username; Session["usertype"] = model.Usertype; ViewBag.username = model.Username; return(RedirectToAction("Student", "home")); }
public ActionResult TeacherResponse(int id) { if (Session["username"] == null || Session["usertype"] == null) { return(RedirectToRoute(new { controller = "Index", action = "Index", id = 1 })); } AssignmentSolutionModel asModel = new AssignmentSolutionModel(); List <Solution> listSolutions = new List <Solution>(); using (XorHubEntities db = new XorHubEntities()) { asModel.Assignment = db.Assignments.Where(a => a.AssignmentId == id).FirstOrDefault(); listSolutions = db.Solutions.Where(s => s.AssignmentId == id).ToList(); } ViewBag.filePath = "~/Database/Questions/" + asModel.Assignment.AssignmentId + ".pdf"; ViewBag.solutions = listSolutions; return(View("TeacherResponse", asModel)); }
public void ApproveTeacher(string username) { using (XorHubEntities db = new XorHubEntities()) { db.LoginInfoes.Where(l => l.Username.Equals(username)).FirstOrDefault().Stat = true; db.SaveChanges(); } }
public ActionResult Reject(Solution sol) { using (XorHubEntities db = new XorHubEntities()) { var soln = db.Solutions.Where(s => s.SolutionId == sol.SolutionId).FirstOrDefault(); soln.Stat = "R"; soln.Comment = sol.Comment; db.SaveChanges(); } return(RedirectToAction("TeacherResponse", new { id = sol.AssignmentId })); }
public ActionResult GetAssignments() { List <Assignment> assignmentList = new List <Assignment>(); using (XorHubEntities db = new XorHubEntities()) { var userName = Session["username"].ToString(); var userBatchId = db.LoginInfoes.Where(u => u.Username.Equals(userName)).FirstOrDefault().BatchId; assignmentList = db.Assignments.Where(a => a.BatchId == userBatchId).ToList(); } return(Json(assignmentList, JsonRequestBehavior.AllowGet)); }
// GET: Index public ActionResult Index(int?id) { if (Session["usertype"] != null) { switch (Session["usertype"].ToString()) { case "A": return(RedirectToAction("Admin", "Home")); case "T": return(RedirectToAction("Teacher", "Home")); case "S": return(RedirectToAction("Student", "Home")); default: break; } } if (id != null) { switch (id) { case 1: ViewBag.Message = "Login Required!"; break; case 2: ViewBag.Message = "Access Denied!"; break; default: ViewBag.Message = ""; break; } } using (XorHubEntities db = new XorHubEntities()) { List <SelectListItem> list = new List <SelectListItem>(); foreach (var item in db.Batches) { list.Add(new SelectListItem { Text = item.Name, Value = item.BatchId.ToString() }); } ViewData["BatchList"] = list; } return(View()); }
public ActionResult Teacher(int?id) { if (id == 1) { ViewBag.Message = "Please Select File!"; } if (id == 4) { ViewBag.Message = "Please Select Valid Date!"; } if (Session["username"] == null || Session["usertype"] == null) { return(RedirectToRoute(new { controller = "Index", action = "Index", id = 1 })); //return RedirectToAction("Index", "Index", 1); } if (!Session["usertype"].Equals("T")) { return(RedirectToRoute(new { controller = "Index", action = "Index", id = 2 })); //return RedirectToAction("Index", "Index", 2); } using (XorHubEntities db = new XorHubEntities()) { List <SelectListItem> list = new List <SelectListItem>(); foreach (var item in db.Batches) { list.Add(new SelectListItem { Text = item.Name, Value = item.BatchId.ToString() }); } ViewData["BatchList"] = list; } return(View()); }
public JsonResult GetTeacherRequests() { List <LoginInfo> listTeachers = new List <LoginInfo>(); using (XorHubEntities db = new XorHubEntities()) { foreach (var item in db.LoginInfoes.Where(l => l.Usertype.Equals("T") && !l.Stat).ToList()) { listTeachers.Add(new LoginInfo { Name = item.Name, Username = item.Username }); } } return(Json(listTeachers, JsonRequestBehavior.AllowGet)); }
// GET: Assignment public ActionResult StudentResponse(int id) { if (Session["username"] == null || Session["usertype"] == null) { return(RedirectToRoute(new { controller = "Index", action = "Index", id = 1 })); } AssignmentSolutionModel asModel = new AssignmentSolutionModel(); asModel.Solution = new Solution() { Stat = "P" }; using (XorHubEntities db = new XorHubEntities()) { List <SelectListItem> list = new List <SelectListItem>(); foreach (var item in db.Batches) { list.Add(new SelectListItem { Text = item.Name, Value = item.BatchId.ToString() }); } asModel.Assignment = db.Assignments.Where(a => a.AssignmentId == id).FirstOrDefault(); var sol = db.Solutions.Where(s => s.AssignmentId == id && s.Stat.Equals("A")).FirstOrDefault(); if (sol != null) { asModel.Solution = sol; } ViewData["BatchList"] = list; } ViewBag.filePath = "~/Database/Questions/" + id + ".pdf"; ViewBag.state = false; return(View(asModel)); }
public ActionResult Logout() { using (XorHubEntities db = new XorHubEntities()) { List <SelectListItem> list = new List <SelectListItem>(); foreach (var item in db.Batches) { list.Add(new SelectListItem { Text = item.Name, Value = item.BatchId.ToString() }); } ViewData["BatchList"] = list; } Session["username"] = null; Session["usertype"] = null; ViewBag.Message = "Logged Out Successfully"; return(View("Index")); }
public ActionResult Register(int BatchId, LoginInfo model) { using (XorHubEntities db = new XorHubEntities()) { List <SelectListItem> list = new List <SelectListItem>(); foreach (var item in db.Batches) { list.Add(new SelectListItem { Text = item.Name, Value = item.BatchId.ToString() }); } ViewData["BatchList"] = list; } if (ModelState["Name"].Errors.Count > 0 || ModelState["Username"].Errors.Count > 0 || ModelState["Passwd"].Errors.Count > 0) { return(View("Index", model)); } if (model.Usertype.Equals("T")) { model.BatchId = null; model.Stat = false; } else { model.Stat = true; } using (XorHubEntities db = new XorHubEntities()) { db.LoginInfoes.Add(model); db.SaveChanges(); } ViewBag.Message = "User Registered Successfully!! "; ModelState.Clear(); return(View("Index")); }
public JsonResult GetAssignmentsForTeacher(int batchId) { List <Assignment> assignmentList = new List <Assignment>(); List <Assignment> finalList = new List <Assignment>(); using (XorHubEntities db = new XorHubEntities()) { var userName = Session["username"].ToString(); assignmentList = db.Assignments.Where(a => (a.BatchId == batchId) && (a.TeacherName.Equals(userName))).ToList(); } foreach (var item in assignmentList) { finalList.Add(new Assignment { AssignmentId = item.AssignmentId, Title = item.Title, TeacherName = item.TeacherName, Deadline = item.Deadline }); } return(Json(finalList, JsonRequestBehavior.AllowGet)); }
public ActionResult PostQuestion(HttpPostedFileBase QueFile, Assignment assignment) { assignment.PostedDate = DateTime.Now; if (assignment.Deadline < assignment.PostedDate) { return(RedirectToAction("Teacher", "Home", new { id = 4 })); } assignment.TeacherName = Session["username"].ToString(); if (!Directory.Exists(Server.MapPath("~/Database/Questions/"))) { Directory.CreateDirectory(Server.MapPath("~/Database/Questions/")); } using (XorHubEntities db = new XorHubEntities()) { db.Assignments.Add(assignment); db.SaveChanges(); } try { QueFile.SaveAs(Path.Combine(Server.MapPath("~/Database/Questions"), assignment.AssignmentId.ToString() + ".pdf")); } catch (Exception ex) { return(RedirectToAction("Teacher", "Home", new { id = 1 })); } ViewBag.Message = "Question Successfully uploaded!"; return(RedirectToAction("Teacher", "Home")); }
public ActionResult Submit(HttpPostedFileBase solutionDoc, AssignmentSolutionModel asModel) { if (asModel.Assignment.Deadline < DateTime.Now) { ViewBag.Message = "Deadline crossed! Cannot Submit Solution"; ViewBag.filePath = "~/Database/Questions/" + asModel.Assignment.AssignmentId + ".pdf"; return(View("StudentResponse", asModel)); } if (!Directory.Exists(Server.MapPath("~/Database/Solutions/" + Session["username"].ToString()))) { Directory.CreateDirectory(Server.MapPath("~/Database/Solutions/" + Session["username"].ToString())); } try { solutionDoc.SaveAs(Path.Combine(Server.MapPath("~/Database/Solutions/" + Session["username"].ToString() + "/"), asModel.Assignment.AssignmentId + ".pdf")); } catch (Exception ex) { ViewBag.Message = "Please Select File!"; ViewBag.filePath = "~/Database/Questions/" + asModel.Assignment.AssignmentId + ".pdf"; return(View("StudentResponse", asModel)); } Solution soln = new Solution() { AssignmentId = asModel.Assignment.AssignmentId, Username = Session["username"].ToString(), Stat = "P", UploadedOn = DateTime.Now, Document = asModel.Assignment.AssignmentId + ".pdf", Comment = "" }; using (XorHubEntities db = new XorHubEntities()) { try { string userName = Session["username"].ToString(); if (db.Solutions.Any(s => s.Username.Equals(userName) && s.AssignmentId == asModel.Assignment.AssignmentId)) { var tmp = db.Solutions.Where(s => s.Username.Equals(userName) && s.AssignmentId == asModel.Assignment.AssignmentId).FirstOrDefault(); tmp = soln; db.SaveChanges(); } else { db.Solutions.Add(soln); db.SaveChanges(); } } catch (DbEntityValidationException e) { } } return(RedirectToRoute(new { Controller = "Home", Action = "Student", id = 3 } )); }
public ActionResult Student(int?id) { if (Session["username"] == null || Session["usertype"] == null) { return(RedirectToRoute(new { controller = "Index", action = "Index", id = 1 })); } switch (Session["usertype"].ToString()) { case "T": return(RedirectToRoute(new { controller = "Home", action = "Teacher", id = 2 })); case "A": return(RedirectToRoute(new { controller = "Home", action = "Admin", id = 2 })); case "S": default: break; } switch (id) { case 1: ViewBag.Message = "Assignment Submitted Successfully!"; break; } List <Assignment> assignmentList = new List <Assignment>(); List <Solution> solutionList = new List <Solution>(); using (XorHubEntities db = new XorHubEntities()) { var userName = Session["username"].ToString(); var userBatchId = db.LoginInfoes.Where(u => u.Username.Equals(userName)).FirstOrDefault().BatchId; assignmentList = db.Assignments.Where(a => a.BatchId == userBatchId).ToList(); solutionList = db.Solutions.Where(s => s.Username.Equals(userName)).ToList(); foreach (Solution sol in solutionList) { sol.Assignment = db.Assignments.Where(a => a.AssignmentId == sol.AssignmentId).ToList().FirstOrDefault(); } } ViewBag.Assignments = assignmentList; ViewBag.Solutions = solutionList; return(View()); }