public ActionResult Edit([Bind(Include = "AssignmentId,SSId,ObtainedMarks,FilePath,Id")] SSAssignment ssassignment, HttpPostedFileBase file, int?ids, int?idsc, int?idc, int?ida, int?idss) { ViewBag.idss = idss; ViewBag.idc = idc; ViewBag.ids = ids; ViewBag.idsc = idsc; ViewBag.ida = ida; Assignment var = db.Assignments.Find(ssassignment.AssignmentId); int? om = ssassignment.ObtainedMarks; if (om == null) { om = -999; } if (ModelState.IsValid && var.TotalMarks >= om) { db.Entry(ssassignment).State = EntityState.Modified; db.SaveChanges(); if (file != null && file.ContentLength > 0) { if (System.IO.File.Exists(AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "../../" + ssassignment.FilePath)) { System.IO.File.Delete(AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "../../" + ssassignment.FilePath); } string path = System.IO.Path.Combine(Server.MapPath("~/Assignments/Solutions"), ssassignment.Id.ToString() + System.IO.Path.GetExtension(file.FileName)); ssassignment.FilePath = "/Assignments/Solutions/" + ssassignment.Id + System.IO.Path.GetExtension(file.FileName); file.SaveAs(path); db.SaveChanges(); } if (adtype() == "Student") { return(RedirectToAction("Index", "Assignment", new { idsc = idsc, ids = ids, idc = idc, ida = ida, idss = idss })); } return(RedirectToAction("Index", new { idsc = idsc, ids = ids, idc = idc, ida = ida, idss = idss })); } ViewBag.Error = ""; if (var.TotalMarks < ssassignment.ObtainedMarks) { ViewBag.Error = "Obtained Marks cannot be greater than total marks."; } ViewBag.UserType = adtype(); if (adtype() == "Admin" || adtype() == "Teacher") { if (adtype() == "Teacher" && db.Assignments.Where(a => a.Id == ida && a.SectionCourse.Teacher.AspNetUser.UserName == User.Identity.Name).Count() == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.AssignmentId = new SelectList(db.Assignments, "Id", "Name", ssassignment.AssignmentId); ViewBag.SSId = new SelectList(db.SectionStudents, "Id", "StudentId", ssassignment.SSId); return(View(ssassignment)); } else if (adtype() == "Student" && ida != null && db.Assignments.Where(a => a.SectionCourse.Section.SectionStudents.Where(ss => ss.Student.AspNetUser.UserName == User.Identity.Name).Count() > 0).Count() > 0) { ViewBag.AssignmentId = new SelectList(db.Assignments, "Id", "Name", ssassignment.AssignmentId); ViewBag.SSId = new SelectList(db.SectionStudents, "Id", "StudentId", ssassignment.SSId); return(View(ssassignment)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
// GET: /StudentAssignment/Details/5 public ActionResult Details(int?id) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SSAssignment ssassignment = db.SSAssignments.Find(id); if (ssassignment == null) { return(HttpNotFound()); } return(View(ssassignment)); }
public ActionResult DeleteConfirmed(int id, int?ids, int?idsc, int?idc, int?ida, int?idss) { ViewBag.idss = idss; ViewBag.idc = idc; ViewBag.ids = ids; ViewBag.idsc = idsc; ViewBag.ida = ida; SSAssignment ssassignment = db.SSAssignments.Find(id); if (System.IO.File.Exists(AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "../../" + ssassignment.FilePath)) { System.IO.File.Delete(AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "../../" + ssassignment.FilePath); } db.SSAssignments.Remove(ssassignment); db.SaveChanges(); return(RedirectToAction("Index", new { idsc = idsc, ids = ids, idc = idc, ida = ida, idss = idss })); }
// GET: /StudentAssignment/Delete/5 public ActionResult Delete(int?id, int?ids, int?idsc, int?idc, int?ida, int?idss) { ViewBag.idss = idss; ViewBag.idc = idc; ViewBag.ids = ids; ViewBag.idsc = idsc; ViewBag.ida = ida; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SSAssignment ssassignment = db.SSAssignments.Find(id); if (ssassignment == null) { return(HttpNotFound()); } return(View(ssassignment)); }
// GET: /StudentAssignment/Edit/5 public ActionResult Edit(int?id, int?ids, int?idsc, int?idc, int?ida, int?idss) { ViewBag.idss = idss; ViewBag.idc = idc; ViewBag.ids = ids; ViewBag.idsc = idsc; ViewBag.ida = ida; ViewBag.Error = ""; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SSAssignment ssassignment = db.SSAssignments.Find(id); if (ssassignment == null) { return(HttpNotFound()); } ViewBag.UserType = adtype(); if (adtype() == "Admin" || adtype() == "Teacher") { if (adtype() == "Teacher" && db.Assignments.Where(a => a.Id == ida && a.SectionCourse.Teacher.AspNetUser.UserName == User.Identity.Name).Count() == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewBag.AssignmentId = new SelectList(db.Assignments, "Id", "Name", ssassignment.AssignmentId); ViewBag.SSId = new SelectList(db.SectionStudents, "Id", "StudentId", ssassignment.SSId); return(View(ssassignment)); } else if (adtype() == "Student" && ida != null && db.Assignments.Where(a => a.SectionCourse.Section.SectionStudents.Where(ss => ss.Student.AspNetUser.UserName == User.Identity.Name).Count() > 0).Count() > 0) { ViewBag.AssignmentId = new SelectList(db.Assignments, "Id", "Name", ssassignment.AssignmentId); ViewBag.SSId = new SelectList(db.SectionStudents, "Id", "StudentId", ssassignment.SSId); return(View(ssassignment)); } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }
private int AssignmentMarks(int aid, int ssid) { SSAssignment var = db.SSAssignments.Where(e => e.AssignmentId == aid && e.SSId == ssid).First(); return((int)var.ObtainedMarks); }
public ActionResult Create([Bind(Include = "AssignmentId,SSId,ObtainedMarks,FilePath,Id")] SSAssignment ssassignment, HttpPostedFileBase file, int?ids, int?idsc, int?idc, int?ida, int?idss) { ViewBag.Error = ""; ViewBag.idss = idss; ViewBag.idc = idc; ViewBag.ids = ids; ViewBag.idsc = idsc; ViewBag.ida = ida; Assignment var = db.Assignments.Find(ssassignment.AssignmentId); int? om = ssassignment.ObtainedMarks; if (om == null) { om = -999; } if (ModelState.IsValid && var.TotalMarks > om) { db.SSAssignments.Add(ssassignment); db.SaveChanges(); if (file != null && file.ContentLength > 0) { string path = System.IO.Path.Combine(Server.MapPath("~/Assignments/Solutions"), ssassignment.Id.ToString() + System.IO.Path.GetExtension(file.FileName)); ssassignment.FilePath = "/Assignments/Solutions/" + ssassignment.Id + System.IO.Path.GetExtension(file.FileName); file.SaveAs(path); db.SaveChanges(); } else { ssassignment.FilePath = " "; db.SaveChanges(); } if (adtype() == "Student") { return(RedirectToAction("Index", "Assignment", new { idsc = idsc, ids = ids, idc = idc, ida = ida, idss = idss })); } return(RedirectToAction("Index", new { idsc = idsc, ids = ids, idc = idc, ida = ida, idss = idss })); } if (var.TotalMarks < ssassignment.ObtainedMarks) { ViewBag.Error = "Obtained Marks cannot be greater than total marks."; } ViewBag.UserType = adtype(); if (adtype() == "Admin" || adtype() == "Teacher") { if (adtype() == "Teacher" && db.Assignments.Where(a => a.Id == ida && a.SectionCourse.Teacher.AspNetUser.UserName == User.Identity.Name).Count() == 0) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (ida != null && (ids != null || idc != null)) { ViewBag.AssignmentId = new SelectList(db.Assignments, "Id", "Name", ssassignment.AssignmentId); ViewBag.SSId = new SelectList(db.SectionStudents.Where(ss => db.SSAssignments.Where(sse => sse.SSId == ss.Id).Count() == 0 && ss.SectionId == ids), "Id", "Id"); var look = db.SectionStudents.Where(ss => db.SSAssignments.Where(sse => sse.SSId == ss.Id).Count() == 0 && (ss.SectionId == ids || ss.Section.SectionCourses.Where(sc => sc.CourseId == idc).Count() > 0)); IList <SelectListItem> status = new List <SelectListItem> { }; foreach (SectionStudent item in look) { SelectListItem m = new SelectListItem(); m.Text = item.Student.RegistrationNo; m.Value = item.Id.ToString(); if (m.Value == ssassignment.SSId.ToString()) { m.Selected = true; } status.Add(m); } ViewBag.SSId = status; return(View(ssassignment)); } } else if (adtype() == "Student") { if (ida != null && (ids != null || idc != null) && db.Assignments.Where(a => a.SectionCourse.Section.SectionStudents.Where(ss => ss.Student.AspNetUser.UserName == User.Identity.Name).Count() > 0).Count() > 0) { ViewBag.AssignmentId = new SelectList(db.Assignments, "Id", "Name", ida); ViewBag.SSId = new SelectList(db.SectionStudents.Where(ss => db.SSAssignments.Where(sse => sse.SSId == ss.Id).Count() == 0), "Id", "Id"); var look = db.SectionStudents.Where(ss => db.SSAssignments.Where(sse => sse.SSId == ss.Id && sse.AssignmentId == ida && sse.SectionStudent.Student.AspNetUser.UserName == User.Identity.Name).Count() == 0 && (ss.SectionId == ids || ss.Section.SectionCourses.Where(sc => sc.CourseId == idc).Count() > 0)); IList <SelectListItem> status = new List <SelectListItem> { }; foreach (SectionStudent item in look) { SelectListItem m = new SelectListItem(); m.Text = item.Student.RegistrationNo; m.Value = item.Id.ToString(); m.Selected = true; status.Add(m); } ViewBag.SSId = status; return(View()); } } return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); }