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));
        }
Exemple #2
0
        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"));
        }
Exemple #3
0
        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"));
        }