public ActionResult Upload([Bind(Exclude = "AssessmentDocument")] OnlineAssessment onlineAssessment) { if (ModelState.IsValid) { var studentUser = User.Identity.Name; var studentId = db.students.Where(p => p.StudentEmail == studentUser).Select(o => o.StID).FirstOrDefault(); byte[] assessmentData = null; if (Request.Files.Count > 0) { HttpPostedFileBase httpPostedFile = Request.Files["AssessmentDocument"]; using (var binary = new BinaryReader(httpPostedFile.InputStream)) { assessmentData = binary.ReadBytes(httpPostedFile.ContentLength); } } var assessment = db.OnlineAssessments.Where(s => s.AssessmentID == onlineAssessment.AssessmentID && s.StID == studentId).FirstOrDefault(); if (assessment != null) { onlineAssessment.Document = assessmentData; onlineAssessment.StID = studentId; onlineAssessment.Feedback = "Pending"; onlineAssessment.StaffId = 0; db.OnlineAssessments.Add(onlineAssessment); } else { assessment.Document = onlineAssessment.Document; db.Entry(assessment).State = EntityState.Modified; } db.SaveChanges(); } return(RedirectToAction("StudentSubjectList")); }
public ActionResult DeleteConfirmed(int id) { OnlineAssessment onlineAssessment = db.OnlineAssessments.Find(id); db.OnlineAssessments.Remove(onlineAssessment); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "OnlineAssessmentID,StID,AssessmentID,StaffId,Document,Feedback")] OnlineAssessment onlineAssessment) { if (ModelState.IsValid) { db.Entry(onlineAssessment).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AssessmentID = new SelectList(db.Assessments, "AssessmentID", "AssessmentName", onlineAssessment.AssessmentID); ViewBag.StaffId = new SelectList(db.Staffs, "StaffId", "Name", onlineAssessment.StaffId); ViewBag.StID = new SelectList(db.students, "StID", "StudentName", onlineAssessment.StID); return(View(onlineAssessment)); }
// GET: OnlineAssessments/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OnlineAssessment onlineAssessment = db.OnlineAssessments.Find(id); if (onlineAssessment == null) { return(HttpNotFound()); } return(View(onlineAssessment)); }
public ActionResult Create(OnlineAssessment onlineAssessment) { if (ModelState.IsValid) { db.OnlineAssessments.Add(onlineAssessment); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.AssessmentID = new SelectList(db.Assessments, "AssessmentID", "AssessmentName", onlineAssessment.AssessmentID); ViewBag.StaffId = new SelectList(db.Staffs, "StaffId", "Name", onlineAssessment.StaffId); ViewBag.StID = new SelectList(db.students, "StID", "StudentName", onlineAssessment.StID); return(View(onlineAssessment)); }
// GET: OnlineAssessments/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } OnlineAssessment onlineAssessment = db.OnlineAssessments.Find(id); if (onlineAssessment == null) { return(HttpNotFound()); } ViewBag.AssessmentID = new SelectList(db.Assessments, "AssessmentID", "AssessmentName", onlineAssessment.AssessmentID); ViewBag.StaffId = new SelectList(db.Staffs, "StaffId", "Name", onlineAssessment.StaffId); ViewBag.StID = new SelectList(db.students, "StID", "StudentName", onlineAssessment.StID); return(View(onlineAssessment)); }