Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "NotificationID,NotificationTypeID,Name,Detail,NotifiedDate")] Notification notification, string[] ParentID)
        {
            ViewBag.Message = "";
            ViewBag.Error   = "Error";
            try
            {
                db.Notifications.Add(notification);
                db.SaveChanges();

                foreach (string eid in ParentID)
                {
                    NotificationParent notificationparent = new NotificationParent();
                    notificationparent.NotificationID = notification.NotificationID;
                    notificationparent.ParentID       = int.Parse(eid);
                    db.NotificationParents.Add(notificationparent);
                    db.SaveChanges();
                }

                ViewBag.Error   = "";
                ViewBag.Message = "Created Successfully, Please click REFRESH button to view";
            }
            catch { }
            var        notificationparentList = db.NotificationParents.Where(t => t.NotificationID == notification.NotificationID);
            List <int> idList = new List <int>();

            foreach (NotificationParent te in notificationparentList)
            {
                idList.Add(te.ParentID);
            }
            ViewBag.ParentID = new MultiSelectList(db.Parents.OrderByDescending(e => e.Name), "ParentID", "Name", idList);
            return(PartialView(notification));
        }
Ejemplo n.º 2
0
        public ActionResult Edit([Bind(Include = "NotificationID,NotificationTypeID,Name,Detail,NotifiedDate")] Notification notification, string[] ParentID)
        {
            Session["err"] = "Error";
            Session["msg"] = "";
            List <int> idList = new List <int>();
            var        notificationparentList = db.NotificationParents.Where(t => t.NotificationID == notification.NotificationID).ToList();

            try
            {
                db.Entry(notification).State = EntityState.Modified;
                db.SaveChanges();


                foreach (NotificationParent te in notificationparentList)
                {
                    db.NotificationParents.Remove(te);
                    db.SaveChanges();
                }
                foreach (string eid in ParentID)
                {
                    NotificationParent notificationparent = new NotificationParent();
                    notificationparent.NotificationID = notification.NotificationID;
                    notificationparent.ParentID       = int.Parse(eid);
                    db.NotificationParents.Add(notificationparent);
                    db.SaveChanges();
                }

                Session["msg"] = "Modified Successfully";
                Session["err"] = "";

                return(RedirectToAction("Index"));
            }
            catch { }

            foreach (NotificationParent te in notificationparentList)
            {
                idList.Add(te.ParentID);
            }
            ViewBag.ParentID           = new MultiSelectList(db.Parents.OrderByDescending(e => e.Name), "ParentID", "Name", idList);
            ViewBag.Error              = Session["err"];
            ViewBag.Message            = Session["msg"];
            Session["err"]             = "";
            Session["msg"]             = "";
            ViewBag.NotificationTypeID = new SelectList(db.NotificationTypes, "NotificationTypeID", "Name");
            return(View(notification));
        }
        public ActionResult Edit([Bind(Include = "NotificationID,NotificationTypeID,Name,Detail,NotifiedDate")] Notification notification, string[] NotifyID)
        {
            Session["err"] = "Error";
            Session["msg"] = "";
            List <int> idList = new List <int>();

            try
            {
                db.Entry(notification).State = EntityState.Modified;
                db.SaveChanges();

                int notifyid = notification.NotificationTypeID;
                switch (notifyid)
                {
                case 1:
                    ViewBag.NotifyTo = "School";
                    var notificationschoolList = db.NotificationSchools.Where(t => t.NotificationID == notification.NotificationID).ToList();
                    foreach (NotificationSchool te in notificationschoolList)
                    {
                        db.NotificationSchools.Remove(te);
                        db.SaveChanges();
                    }
                    foreach (string eid in NotifyID)
                    {
                        NotificationSchool notificationschool = new NotificationSchool();
                        notificationschool.NotificationID = notification.NotificationID;
                        notificationschool.SchoolID       = int.Parse(eid);
                        db.NotificationSchools.Add(notificationschool);
                        db.SaveChanges();
                    }
                    break;

                case 2:
                    ViewBag.NotifyTo = "Teacher";
                    var notificationteacherList = db.NotificationTeachers.Where(t => t.NotificationID == notification.NotificationID).ToList();
                    foreach (NotificationTeacher te in notificationteacherList)
                    {
                        db.NotificationTeachers.Remove(te);
                        db.SaveChanges();
                    }
                    foreach (string eid in NotifyID)
                    {
                        NotificationTeacher notificationteacher = new NotificationTeacher();
                        notificationteacher.NotificationID = notification.NotificationID;
                        notificationteacher.TeacherID      = int.Parse(eid);
                        db.NotificationTeachers.Add(notificationteacher);
                        db.SaveChanges();
                    }
                    break;

                case 3:
                    ViewBag.NotifyTo = "Parent";
                    var notificationparentList = db.NotificationParents.Where(t => t.NotificationID == notification.NotificationID).ToList();
                    foreach (NotificationParent te in notificationparentList)
                    {
                        db.NotificationParents.Remove(te);
                        db.SaveChanges();
                    }
                    foreach (string eid in NotifyID)
                    {
                        NotificationParent notificationparent = new NotificationParent();
                        notificationparent.NotificationID = notification.NotificationID;
                        notificationparent.ParentID       = int.Parse(eid);
                        db.NotificationParents.Add(notificationparent);
                        db.SaveChanges();
                    }
                    break;

                case 4:
                    ViewBag.NotifyTo = "Student";
                    var notificationstudentList = db.NotificationStudents.Where(t => t.NotificationID == notification.NotificationID).ToList();
                    foreach (NotificationStudent te in notificationstudentList)
                    {
                        db.NotificationStudents.Remove(te);
                        db.SaveChanges();
                    }
                    foreach (string eid in NotifyID)
                    {
                        NotificationStudent notificationstudent = new NotificationStudent();
                        notificationstudent.NotificationID = notification.NotificationID;
                        notificationstudent.StudentID      = int.Parse(eid);
                        db.NotificationStudents.Add(notificationstudent);
                        db.SaveChanges();
                    }
                    break;

                case 5:
                    ViewBag.NotifyTo = "Employee";
                    var notificationemployeeList = db.NotificationEmployees.Where(t => t.NotificationID == notification.NotificationID).ToList();
                    foreach (NotificationEmployee te in notificationemployeeList)
                    {
                        db.NotificationEmployees.Remove(te);
                        db.SaveChanges();
                    }
                    foreach (string eid in NotifyID)
                    {
                        NotificationEmployee notificationemployee = new NotificationEmployee();
                        notificationemployee.NotificationID = notification.NotificationID;
                        notificationemployee.EmployeeID     = int.Parse(eid);
                        db.NotificationEmployees.Add(notificationemployee);
                        db.SaveChanges();
                    }
                    break;

                default:
                    break;
                }

                Session["msg"] = "Modified Successfully";
                Session["err"] = "";
            }
            catch { }

            return(Redirect("/Notification/Index/" + notification.NotificationID + "?notifyid=" + notification.NotificationTypeID));
        }
        public ActionResult Create([Bind(Include = "NotificationID,NotificationTypeID,Name,Detail,NotifiedDate")] Notification notification, string[] NotifyID, int id)
        {
            ViewBag.Message = "";
            ViewBag.Error   = "Error";
            notification.NotificationTypeID = id;
            try
            {
                db.Notifications.Add(notification);
                db.SaveChanges();

                switch (id)
                {
                case 1:
                    ViewBag.NotifyTo           = "School";
                    ViewBag.NotifyID           = new MultiSelectList(db.Schools.OrderByDescending(e => e.Name), "SchoolID", "Name");
                    ViewBag.NotificationTypeID = new SelectList(db.NotificationTypes, "NotificationTypeID", "Name");
                    foreach (string eid in NotifyID)
                    {
                        NotificationSchool notificationschool = new NotificationSchool();
                        notificationschool.NotificationID = notification.NotificationID;
                        notificationschool.SchoolID       = int.Parse(eid);
                        db.NotificationSchools.Add(notificationschool);
                        db.SaveChanges();
                    }
                    break;

                case 2:
                    ViewBag.NotifyTo           = "Teacher";
                    ViewBag.NotifyID           = new MultiSelectList(db.Teachers.OrderByDescending(e => e.Name), "TeacherID", "Name");
                    ViewBag.NotificationTypeID = new SelectList(db.NotificationTypes, "NotificationTypeID", "Name");
                    foreach (string eid in NotifyID)
                    {
                        NotificationTeacher notificationteacher = new NotificationTeacher();
                        notificationteacher.NotificationID = notification.NotificationID;
                        notificationteacher.TeacherID      = int.Parse(eid);
                        db.NotificationTeachers.Add(notificationteacher);
                        db.SaveChanges();
                    }
                    break;

                case 3:
                    ViewBag.NotifyTo           = "Parent";
                    ViewBag.NotifyID           = new MultiSelectList(db.Parents.OrderByDescending(e => e.Name), "ParentID", "Name");
                    ViewBag.NotificationTypeID = new SelectList(db.NotificationTypes, "NotificationTypeID", "Name");
                    foreach (string eid in NotifyID)
                    {
                        NotificationParent notificationparent = new NotificationParent();
                        notificationparent.NotificationID = notification.NotificationID;
                        notificationparent.ParentID       = int.Parse(eid);
                        db.NotificationParents.Add(notificationparent);
                        db.SaveChanges();
                    }
                    break;

                case 4:
                    ViewBag.NotifyTo           = "Student";
                    ViewBag.NotifyID           = new MultiSelectList(db.Students.OrderByDescending(e => e.Name), "StudentID", "Name");
                    ViewBag.NotificationTypeID = new SelectList(db.NotificationTypes, "NotificationTypeID", "Name");
                    foreach (string eid in NotifyID)
                    {
                        NotificationStudent notificationstudent = new NotificationStudent();
                        notificationstudent.NotificationID = notification.NotificationID;
                        notificationstudent.StudentID      = int.Parse(eid);
                        db.NotificationStudents.Add(notificationstudent);
                        db.SaveChanges();
                    }
                    break;

                case 5:
                    ViewBag.NotifyTo           = "Employee";
                    ViewBag.NotifyID           = new MultiSelectList(db.Employees.OrderByDescending(e => e.Name), "EmployeeID", "Name");
                    ViewBag.NotificationTypeID = new SelectList(db.NotificationTypes, "NotificationTypeID", "Name");
                    foreach (string eid in NotifyID)
                    {
                        NotificationEmployee notificationemployee = new NotificationEmployee();
                        notificationemployee.NotificationID = notification.NotificationID;
                        notificationemployee.EmployeeID     = int.Parse(eid);
                        db.NotificationEmployees.Add(notificationemployee);
                        db.SaveChanges();
                    }
                    break;

                default:
                    break;
                }

                ViewBag.Error   = "";
                ViewBag.Message = "Created Successfully, Please click REFRESH button to view";
            }
            catch { }
            return(PartialView());
        }