public List<assignment> getAssignments(string id , string cid) { var query = from x in db.assignments where x.tid == id && x.cid == cid select x; List<assignment> data = new List<assignment>(); DateTime d = DateTime.Now; foreach (var q in query) { assignment a = new assignment(); a.aid = q.aid; a.cid = q.cid; a.tid = q.tid; a.aNumber = q.aNumber; a.totalMarks = q.totalMarks; a.startDate = q.startDate; a.endDate = q.endDate; a.solutionFilePath = q.solutionFilePath; a.questionFilePath = q.questionFilePath; if ( q.endDate >= d ) data.Add(a); } return data; }
public void SaveAssignment(assignment ass, string id) { teacher t = db.teachers.SingleOrDefault(x => x.tid == id); cours c = db.courses.SingleOrDefault(x => x.cid.Equals(ass.cid)); ass.tid = id; t.assignments.Add(ass); c.assignments.Add(ass); db.assignments.Add(ass); db.SaveChanges(); }
public assignment GetAssignmentForUpdation( int aid ) { var query = from x in db.assignments.Where(f => f.aid.Equals(aid)) select x; assignment q = new assignment(); foreach (var a in query) { q.aid = a.aid; q.tid = a.tid; q.cid = a.cid; q.aNumber = a.aNumber; q.totalMarks = a.totalMarks; q.startDate = a.startDate; q.endDate = a.endDate; q.questionFilePath = a.questionFilePath; q.solutionFilePath = a.solutionFilePath; } return q; }
public assignment getAssignmentData(string cid, int aNo) { var query = from x in db.assignments where ( x.aNumber==aNo && x.cid.Equals(cid)) select x; assignment ass = new assignment(); foreach (var q in query) { ass.aid = q.aid; ass.aNumber = q.aNumber; ass.cid = q.cid; ass.startDate = q.startDate; ass.endDate = q.endDate; ass.solutionFilePath = q.solutionFilePath; ass.totalMarks = q.totalMarks; } return ass; }
public ActionResult EditAssignment(assignment assign) { if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher")) { try { string tid = Session["id"].ToString(); string id = tid; var startdate = Request["startDate"]; var enddate = Request["endDate"]; LogTeacher log = new LogTeacher(); log.courseId = assign.cid; log.discription = "Edit Assignment"; log.totalMarks = assign.totalMarks; log.tName = tid; log.type = "Assignment"; log.date = DateTime.Today; db.LogTeachers.Add(log); if (!startdate.Equals(Request["start"])) { string[] str = startdate.Split(' '); string[] time = str[1].Split(':'); string[] date = str[0].Split('/'); string tt = str[2]; if (tt.Equals("AM")) { DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]), Convert.ToInt32(time[1]), 0); assign.startDate = dt; } else { DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]) + 12, Convert.ToInt32(time[1]), 0); assign.startDate = dt; } } else { string[] str = Request["start"].Split(' '); string[] time = str[1].Split(':'); string[] date = str[0].Split('/'); string tt = str[2]; if (tt.Equals("AM")) { var outputLines = new List<string>(); string s = "" + Convert.ToInt32(date[2]) + "/" + Convert.ToInt32(date[1]) + "/" + Convert.ToInt32(date[0]) + " " + Convert.ToInt32(time[0]) + ":" + Convert.ToInt32(time[1]); outputLines.Add(s); System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines); //DateTime dt = new DateTime(2014, 04, 12); DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])); assign.startDate = dt; } else { var outputLines = new List<string>(); string s = "" + Convert.ToInt32(date[2]) + "/" + Convert.ToInt32(date[1]) + "/" + Convert.ToInt32(date[0]) + " " + Convert.ToInt32(time[0]) + ":" + Convert.ToInt32(time[1]); outputLines.Add(s); System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines); //DateTime dt = new DateTime(2014, 04, 12); DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])); assign.startDate = dt; } } if (!enddate.Equals(Request["end"])) { string[] str1 = enddate.Split(' '); string[] time1 = str1[1].Split(':'); string[] date1 = str1[0].Split('/'); string tt1 = str1[2]; if (tt1.Equals("AM")) { DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]), Convert.ToInt32(time1[1]), 0); assign.endDate = dt; } else { DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]) + 12, Convert.ToInt32(time1[1]), 0); assign.endDate = dt; } } else { string[] str1 = Request["end"].Split(' '); string[] time1 = str1[1].Split(':'); string[] date1 = str1[0].Split('/'); string tt1 = str1[2]; if (tt1.Equals("AM")) { var outputLines = new List<string>(); string s = "" + Convert.ToInt32(date1[2]) + "/" + Convert.ToInt32(date1[1]) + "/" + Convert.ToInt32(date1[0]) + " " + Convert.ToInt32(time1[0]) + ":" + Convert.ToInt32(time1[1]); outputLines.Add(s); System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines); //DateTime dt = new DateTime(2014, 04, 23); DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[1]), Convert.ToInt32(date1[0])); assign.endDate = dt; } else { var outputLines = new List<string>(); string s = "" + Convert.ToInt32(date1[2]) + "/" + Convert.ToInt32(date1[1]) + "/" + Convert.ToInt32(date1[0]) + " " + Convert.ToInt32(time1[0]) + ":" + Convert.ToInt32(time1[1]); outputLines.Add(s); System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines); //DateTime dt = new DateTime(2014,04,23); DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[1]), Convert.ToInt32(date1[0])); assign.endDate = dt; } } if (Request.Files[0].ContentLength != 0) { HttpPostedFileBase file = Request.Files[0]; if (file.ContentType.Equals("application/pdf")) { file.SaveAs(Server.MapPath(@"~\Files\" + file.FileName)); var dataFile = Server.MapPath(@"~\Files\" + file.FileName); assign.questionFilePath = dataFile; } else { ViewBag.ErrorType = "File Uploading"; ViewBag.message = "Please upload a text code file and text output file"; return View("ErrorPage"); } } else { assign.questionFilePath = Request["Q"]; } if (Request.Files[1].ContentLength != 0) { HttpPostedFileBase file1 = Request.Files[1]; if (file1.ContentType.Equals("text/plain")) { file1.SaveAs(Server.MapPath(@"~\Files\" + file1.FileName)); var dataFile1 = Server.MapPath(@"~\Files\" + file1.FileName); assign.solutionFilePath = dataFile1; } else { ViewBag.ErrorType = "File Uploading"; ViewBag.message = "Please upload a text code file and text output file"; return View("ErrorPage"); } } else { assign.solutionFilePath = Request["S"]; } db.Entry(assign).State = EntityState.Modified; try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { var outputLines = new List<string>(); foreach (var eve in e.EntityValidationErrors) { outputLines.Add(string.Format( "{0}: Entity of type \"{1}\" in state \"{2}\" has the following validation errors:", DateTime.Now, eve.Entry.Entity.GetType().Name, eve.Entry.State)); foreach (var ve in eve.ValidationErrors) { outputLines.Add(string.Format( "- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage)); } } System.IO.File.AppendAllLines(@"d:\errors.txt", outputLines); throw; } return View("TeacherHome"); } catch (Exception e) { ViewBag.ErrorType = "Exception"; ViewBag.message = e.Message; return View("ErrorPage"); } } else return RedirectToAction("signIn" , "Home"); }
public ActionResult SaveAssignment( assignment ass ) { if (Session["id"] != null && db.users.Find(Session["id"]).type.Equals("Teacher")) { try { string tid = Session["id"].ToString(); string id = tid; var startdate = Request["startDate"]; var enddate = Request["endDate"]; string[] str = startdate.Split(' '); string[] time = str[1].Split(':'); string[] date = str[0].Split('/'); string tt = str[2]; LogTeacher log = new LogTeacher(); log.courseId = ass.cid; log.discription = "Save Assignment"; log.totalMarks = ass.totalMarks; log.tName = tid; log.type = "Assignment"; log.date = DateTime.Today; db.LogTeachers.Add(log); if (tt.Equals("AM")) { DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]), Convert.ToInt32(time[1]), 0); ass.startDate = dt; } else { DateTime dt = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[0]), Convert.ToInt32(date[1]), Convert.ToInt32(time[0]) + 12, Convert.ToInt32(time[1]), 0); ass.startDate = dt; } string[] str1 = enddate.Split(' '); string[] time1 = str1[1].Split(':'); string[] date1 = str1[0].Split('/'); string tt1 = str1[2]; if (tt1.Equals("AM")) { DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]), Convert.ToInt32(time1[1]), 0); ass.endDate = dt; } else { DateTime dt = new DateTime(Convert.ToInt32(date1[2]), Convert.ToInt32(date1[0]), Convert.ToInt32(date1[1]), Convert.ToInt32(time1[0]) + 12, Convert.ToInt32(time1[1]), 0); ass.endDate = dt; } HttpPostedFileBase file = Request.Files[0]; file.SaveAs(Server.MapPath(@"~\Files\" + file.FileName)); var dataFile = Server.MapPath(@"~\Files\" + file.FileName); ass.questionFilePath = dataFile; HttpPostedFileBase file1 = Request.Files[1]; if (file.ContentType.Equals("application/pdf") && file1.ContentType.Equals("text/plain")) { file1.SaveAs(Server.MapPath(@"~\Files\" + file1.FileName)); var dataFile1 = Server.MapPath(@"~\Files\" + file1.FileName); ass.solutionFilePath = dataFile1; teacher.SaveAssignment(ass, id); return View("TeacherHome"); } else { ViewBag.ErrorType = "File Uploading"; ViewBag.message = "Please upload a text code file and text output file"; return View("ErrorPage"); } } catch (Exception e) { ViewBag.ErrorType = "Exception"; ViewBag.message = e.Message; return View("ErrorPage"); } } else { return RedirectToAction("signIn" , "Home"); } }