public (bool isCreated, int notiId) Create(NotificationApiModel notification, List <USER> users) { var newNotification = new NOTIFICATION(); newNotification.CreatedAt = DateTime.Now; newNotification.Module = notification.module; newNotification.ModuleObjectID = notification.moduleObjectId; newNotification.Submodule = notification.subModule; newNotification.SubmoduleObjectID = notification.subModuleObjectId; newNotification.NotificationContent = notification.content; newNotification.NotificationTitle = notification.title; try { db.NOTIFICATIONs.Add(newNotification); foreach (var user in users) { if (user != null) { var userNotification = new USER_NOTIFICATION(); userNotification.IsRead = false; userNotification.NOTIFICATION = newNotification; userNotification.NOTIFICATION = newNotification; userNotification.USER_ID = user.ID; db.USER_NOTIFICATION.Add(userNotification); } } db.SaveChanges(); return(true, newNotification.ID); } catch { throw; } }
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: TeacherNotification/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } USER_NOTIFICATION uSER_NOTIFICATION = db.USER_NOTIFICATION.Find(id); if (uSER_NOTIFICATION == null) { return(HttpNotFound()); } return(View(uSER_NOTIFICATION)); }
// GET: Notifications/Accept/5 public ActionResult Accept(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } USER_NOTIFICATION uSER_NOTIFICATION = db.USER_NOTIFICATION.Find(id); if (uSER_NOTIFICATION == null) { return(RedirectToAction("Index")); } return(View(uSER_NOTIFICATION)); }
public ActionResult DeleteConfirmed(int id) { USER_NOTIFICATION uSER_NOTIFICATION = db.USER_NOTIFICATION.Find(id); var subject = db.SUBJECT_ASSIGNMENT_TEMP.Find(uSER_NOTIFICATION.SubjectAssignmentTempID); if (subject != null) { db.SUBJECT_ASSIGNMENT_TEMP.Remove(subject); } db.USER_NOTIFICATION.Remove(uSER_NOTIFICATION); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { USER_NOTIFICATION uSER_NOTIFICATION = db.USER_NOTIFICATION.Find(id); if (uSER_NOTIFICATION == null) { return(RedirectToAction("Index")); } if (uSER_NOTIFICATION.Name == "added") { SUBJECT_ASSIGNMENT_TEMP subject = db.SUBJECT_ASSIGNMENT_TEMP.Find(uSER_NOTIFICATION.SubjectAssignmentTempID); db.SUBJECT_ASSIGNMENT_TEMP.Remove(subject); } uSER_NOTIFICATION.StatusID = 2; db.SaveChanges(); return(RedirectToAction("Index")); }
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")); }