public ActionResult DeleteConfirmed(int id) { string userId = getCurrentUserId(); var user = db.USER.Where(x => x.AspNetUserID == userId).FirstOrDefault(); var teacherId = user.TeacherID; var adminID = db.USER.Where(x => x.UserTypeID == 2).FirstOrDefault().ID; SUBJECT_ASSIGNMENT sUBJECT_ASSIGNMENT = db.SUBJECT_ASSIGNMENT.Find(id); USER_NOTIFICATION temp = db.USER_NOTIFICATION.Where(x => x.SubjectAssignmentID == sUBJECT_ASSIGNMENT.ID && x.Name.Contains("deleted")).FirstOrDefault(); if (temp == null) { USER_NOTIFICATION noti = new USER_NOTIFICATION(); noti.Date = DateTime.Now; noti.Name = "deleted"; noti.Description = db.SUBJECT.Where(x => x.ID == sUBJECT_ASSIGNMENT.SubjectID).FirstOrDefault().Name + " deleted by " + user.Name; noti.SenderID = user.ID; noti.UserID = adminID; noti.StatusID = 1; noti.SubjectAssignmentID = sUBJECT_ASSIGNMENT.ID; noti.SubjectName = sUBJECT_ASSIGNMENT.SUBJECT.Name; db.USER_NOTIFICATION.Add(noti); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "ID,TeacherID,IsSubstitute,IsSubstituteDescription,StudentGroupID,SubjectID,SubjectTypeID, StudiesTypeID, Semester, Hours, ReplacedName")] SUBJECT_ASSIGNMENT sUBJECT_ASSIGNMENT) { if (ModelState.IsValid) { SUBJECT_ASSIGNMENT_TEMP subjectAssignmentTemp = new SUBJECT_ASSIGNMENT_TEMP(); string id = getCurrentUserId(); var user = db.USER.Where(x => x.AspNetUserID == id).FirstOrDefault(); var teacherId = user.TeacherID; subjectAssignmentTemp.TeacherID = teacherId.Value; //sUBJECT_ASSIGNMENT.TeacherID = teacherId.Value; subjectAssignmentTemp.Hours = sUBJECT_ASSIGNMENT.Hours; subjectAssignmentTemp.IsSubstitute = sUBJECT_ASSIGNMENT.IsSubstitute; subjectAssignmentTemp.IsSubstituteDescription = sUBJECT_ASSIGNMENT.IsSubstituteDescription; subjectAssignmentTemp.Semester = sUBJECT_ASSIGNMENT.Semester; subjectAssignmentTemp.StudentGroupID = sUBJECT_ASSIGNMENT.StudentGroupID; subjectAssignmentTemp.StudiesTypeID = sUBJECT_ASSIGNMENT.StudiesTypeID; subjectAssignmentTemp.SubjectID = sUBJECT_ASSIGNMENT.SubjectID; subjectAssignmentTemp.SubjectTypeID = sUBJECT_ASSIGNMENT.SubjectTypeID; subjectAssignmentTemp.ReplacedName = sUBJECT_ASSIGNMENT.ReplacedName; db.SUBJECT_ASSIGNMENT_TEMP.Add(subjectAssignmentTemp); //db.SUBJECT_ASSIGNMENT.Add(sUBJECT_ASSIGNMENT); db.SaveChanges(); var adminID = db.USER.Where(x => x.UserTypeID == 2).FirstOrDefault().ID; USER_NOTIFICATION noti = new USER_NOTIFICATION(); noti.Date = DateTime.Now; noti.Name = "added"; if (subjectAssignmentTemp.IsSubstitute == true) { noti.Description = "substitution for " + subjectAssignmentTemp.ReplacedName + " added by " + user.Name; } else { noti.Description = db.SUBJECT.Where(x => x.ID == subjectAssignmentTemp.SubjectID).FirstOrDefault().Name + " added by " + user.Name; } noti.SenderID = user.ID; noti.UserID = adminID; noti.StatusID = 1; noti.SubjectAssignmentTempID = subjectAssignmentTemp.ID; noti.SubjectName = subjectAssignmentTemp.SUBJECT.Name; db.USER_NOTIFICATION.Add(noti); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentGroupID = new SelectList(db.STUDENT_GROUP, "ID", "Name", sUBJECT_ASSIGNMENT.StudentGroupID); ViewBag.SubjectID = new SelectList(db.SUBJECT, "ID", "Name", sUBJECT_ASSIGNMENT.SubjectID); ViewBag.SubjectTypeID = new SelectList(db.SUBJECT_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.SubjectTypeID); ViewBag.StudiesTypeID = new SelectList(db.STUDIES_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.StudiesTypeID); return(View(sUBJECT_ASSIGNMENT)); }
// GET: Teacher/Delete/5 public ActionResult DeleteSubject(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SUBJECT_ASSIGNMENT sUBJECT_ASSIGNMENT = db.SUBJECT_ASSIGNMENT.Find(id); if (sUBJECT_ASSIGNMENT == null) { return(HttpNotFound()); } return(View(sUBJECT_ASSIGNMENT)); }
public ActionResult DeleteSubjectConfirmed(int id) { SUBJECT_ASSIGNMENT sUBJECT_ASSIGNMENT = db.SUBJECT_ASSIGNMENT.Find(id); if (sUBJECT_ASSIGNMENT != null) { var subject = sUBJECT_ASSIGNMENT.SUBJECT; subject.UsedHours -= sUBJECT_ASSIGNMENT.Hours; db.SUBJECT_ASSIGNMENT.Remove(sUBJECT_ASSIGNMENT); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult CreateSubject([Bind(Include = "ID,IsSubstitute,IsSubstituteDescription,StudentGroupID,SubjectID,SubjectTypeID, StudiesTypeID, Semester, Hours, ReplacedName")] SUBJECT_ASSIGNMENT sUBJECT_ASSIGNMENT) { if (ModelState.IsValid) { sUBJECT_ASSIGNMENT.TeacherID = (int)Session["TeacherID"]; db.SUBJECT_ASSIGNMENT.Add(sUBJECT_ASSIGNMENT); var subject = db.SUBJECT.Where(x => x.ID == sUBJECT_ASSIGNMENT.SubjectID).FirstOrDefault(); subject.UsedHours += sUBJECT_ASSIGNMENT.Hours; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentGroupID = new SelectList(db.STUDENT_GROUP, "ID", "Name", sUBJECT_ASSIGNMENT.StudentGroupID); ViewBag.SubjectID = new SelectList(db.SUBJECT, "ID", "Name", sUBJECT_ASSIGNMENT.SubjectID); ViewBag.SubjectTypeID = new SelectList(db.SUBJECT_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.SubjectTypeID); ViewBag.StudiesTypeID = new SelectList(db.STUDIES_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.StudiesTypeID); return(View(sUBJECT_ASSIGNMENT)); }
public ActionResult EditSubject([Bind(Include = "ID,TeacherID,IsSubstitute,IsSubstituteDescription,StudentGroupID,SubjectID,SubjectTypeID, StudiesTypeID, Semester, Hours, ReplacedName")] SUBJECT_ASSIGNMENT sUBJECT_ASSIGNMENT) { var actualHours = (int)Session["ActualHours"]; var editedHours = sUBJECT_ASSIGNMENT.Hours; var resultHours = editedHours - actualHours; if (ModelState.IsValid) { db.Entry(sUBJECT_ASSIGNMENT).State = EntityState.Modified; var subject = db.SUBJECT.Where(x => x.ID == sUBJECT_ASSIGNMENT.SubjectID).FirstOrDefault(); subject.UsedHours += resultHours; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.StudentGroupID = new SelectList(db.STUDENT_GROUP, "ID", "Name", sUBJECT_ASSIGNMENT.StudentGroupID); ViewBag.SubjectID = new SelectList(db.SUBJECT, "ID", "SubjectCode", sUBJECT_ASSIGNMENT.SubjectID); ViewBag.TeacherID = new SelectList(db.TEACHER, "ID", "FirstName", sUBJECT_ASSIGNMENT.TeacherID); ViewBag.SubjectTypeID = new SelectList(db.SUBJECT_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.SubjectTypeID); ViewBag.StudiesTypeID = new SelectList(db.STUDIES_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.StudiesTypeID); return(View(sUBJECT_ASSIGNMENT)); }
public ActionResult EditSubject(int?id) { int assignedHours; int usedHours; int freeHours; if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SUBJECT_ASSIGNMENT sUBJECT_ASSIGNMENT = db.SUBJECT_ASSIGNMENT.Find(id); var subject = db.SUBJECT.Find(sUBJECT_ASSIGNMENT.SubjectID); assignedHours = subject.AssignedHours; usedHours = subject.UsedHours; freeHours = (assignedHours - usedHours) < 0 ? 0 : (assignedHours - usedHours); ViewBag.AssignedHours = assignedHours; ViewBag.UsedHours = usedHours; ViewBag.FreeHours = freeHours; Session["ActualHours"] = sUBJECT_ASSIGNMENT.Hours; if (sUBJECT_ASSIGNMENT == null) { return(HttpNotFound()); } ViewBag.StudentGroupID = new SelectList(db.STUDENT_GROUP, "ID", "Name", sUBJECT_ASSIGNMENT.StudentGroupID); ViewBag.SubjectID = new SelectList(db.SUBJECT, "ID", "SubjectCode", sUBJECT_ASSIGNMENT.SubjectID); ViewBag.TeacherID = new SelectList(db.TEACHER, "ID", "FirstName", sUBJECT_ASSIGNMENT.TeacherID); ViewBag.SubjectTypeID = new SelectList(db.SUBJECT_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.SubjectTypeID); ViewBag.StudiesTypeID = new SelectList(db.STUDIES_TYPE_DICT, "ID", "Description", sUBJECT_ASSIGNMENT.StudiesTypeID); return(View(sUBJECT_ASSIGNMENT)); }
public ActionResult AcceptConfirmed(int id) { USER_NOTIFICATION uSER_NOTIFICATION = db.USER_NOTIFICATION.Find(id); if (uSER_NOTIFICATION == null) { return(RedirectToAction("Index")); } if (uSER_NOTIFICATION.Name.Contains("added")) { SUBJECT_ASSIGNMENT_TEMP subject = db.SUBJECT_ASSIGNMENT_TEMP.Find(uSER_NOTIFICATION.SubjectAssignmentTempID); SUBJECT_ASSIGNMENT resultSubject = new SUBJECT_ASSIGNMENT { Hours = subject.Hours, IsSubstitute = subject.IsSubstitute, IsSubstituteDescription = subject.IsSubstituteDescription, Semester = subject.Semester, StudentGroupID = subject.StudentGroupID, StudiesTypeID = subject.StudiesTypeID, SubjectID = subject.SubjectID, SubjectTypeID = subject.SubjectTypeID, TeacherID = subject.TeacherID, ReplacedName = subject.ReplacedName }; var s = db.SUBJECT.Find(resultSubject.SubjectID); s.UsedHours += resultSubject.Hours; db.SUBJECT_ASSIGNMENT.Add(resultSubject); db.SUBJECT_ASSIGNMENT_TEMP.Remove(subject); } else if (uSER_NOTIFICATION.Name.Contains("deleted")) { var subject = db.SUBJECT_ASSIGNMENT.Find(uSER_NOTIFICATION.SubjectAssignmentID); var s = subject.SUBJECT; s.UsedHours -= subject.Hours; db.SUBJECT_ASSIGNMENT.Remove(subject); } else if (uSER_NOTIFICATION.Name.Contains("modified")) { SUBJECT_ASSIGNMENT_TEMP subject_temp = uSER_NOTIFICATION.SUBJECT_ASSIGNMENT_TEMP; SUBJECT_ASSIGNMENT subject = db.SUBJECT_ASSIGNMENT.Find(uSER_NOTIFICATION.SubjectAssignmentID); int hours = subject_temp.Hours - subject.Hours; var s = db.SUBJECT.Find(subject_temp.SubjectID); s.UsedHours += hours; subject.Hours = subject_temp.Hours; subject.IsSubstitute = subject_temp.IsSubstitute; subject.IsSubstituteDescription = subject_temp.IsSubstituteDescription; subject.Semester = subject_temp.Semester; subject.StudentGroupID = subject_temp.StudentGroupID; subject.StudiesTypeID = subject_temp.StudiesTypeID; subject.SubjectID = subject_temp.SubjectID; subject.SubjectTypeID = subject_temp.SubjectTypeID; subject.TeacherID = subject_temp.TeacherID; subject.ReplacedName = subject_temp.ReplacedName; db.SaveChanges(); db.SUBJECT_ASSIGNMENT_TEMP.Remove(subject_temp); } uSER_NOTIFICATION.StatusID = 3; db.SaveChanges(); return(RedirectToAction("Index")); }