public ActionResult DeleteConfirmed(int id)
        {
            AspNetPTM_TeacherFeedback aspNetPTM_TeacherFeedback = db.AspNetPTM_TeacherFeedback.Find(id);

            db.AspNetPTM_TeacherFeedback.Remove(aspNetPTM_TeacherFeedback);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,PTMID,HeadingID,FeedBack")] AspNetPTM_TeacherFeedback aspNetPTM_TeacherFeedback)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetPTM_TeacherFeedback).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.HeadingID = new SelectList(db.AspNetFeedBackForms.Where(x => x.SessionID == SessionID), "Id", "Question", aspNetPTM_TeacherFeedback.HeadingID);
     ViewBag.PTMID     = new SelectList(db.AspNetPTMAttendances.Where(x => x.AspNetParentTeacherMeeting.SessionID == SessionID), "Id", "ParentID", aspNetPTM_TeacherFeedback.PTMID);
     return(View(aspNetPTM_TeacherFeedback));
 }
 public void TeacherFeed(List <feedbacks> teacherFeedback)
 {
     foreach (var item in teacherFeedback)
     {
         if (item.feedback == null)
         {
             item.feedback = "";
         }
         AspNetPTM_TeacherFeedback aspnetptmteacherfeedback = db.AspNetPTM_TeacherFeedback.Where(x => x.Id == item.Id).FirstOrDefault();
         aspnetptmteacherfeedback.FeedBack = item.feedback;
         db.SaveChanges();
     }
 }
        // GET: AspNetPTM_TeacherFeedback/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetPTM_TeacherFeedback aspNetPTM_TeacherFeedback = db.AspNetPTM_TeacherFeedback.Find(id);

            if (aspNetPTM_TeacherFeedback == null)
            {
                return(HttpNotFound());
            }
            return(View(aspNetPTM_TeacherFeedback));
        }
        // GET: AspNetPTM_TeacherFeedback/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetPTM_TeacherFeedback aspNetPTM_TeacherFeedback = db.AspNetPTM_TeacherFeedback.Find(id);

            if (aspNetPTM_TeacherFeedback == null)
            {
                return(HttpNotFound());
            }
            ViewBag.HeadingID = new SelectList(db.AspNetFeedBackForms.Where(x => x.SessionID == SessionID), "Id", "Question", aspNetPTM_TeacherFeedback.HeadingID);
            ViewBag.PTMID     = new SelectList(db.AspNetPTMAttendances.Where(x => x.AspNetParentTeacherMeeting.SessionID == SessionID), "Id", "ParentID", aspNetPTM_TeacherFeedback.PTMID);
            return(View(aspNetPTM_TeacherFeedback));
        }
        public ActionResult Create([Bind(Include = "Id,Title,Description,Date,Time,Status")] AspNetParentTeacherMeeting aspNetParentTeacherMeeting, AspNetAnnouncement aspNetAnnouncement)
        {
            if (ModelState.IsValid)
            {
                var transactionObj = db.Database.BeginTransaction();
                try
                {
                    var Session = db.AspNetSessions.Where(x => x.Status == "Active").FirstOrDefault().Id;
                    aspNetParentTeacherMeeting.SessionID = Session;

                    db.AspNetParentTeacherMeetings.Add(aspNetParentTeacherMeeting);
                    db.SaveChanges();
                    int        MeetingID     = db.AspNetParentTeacherMeetings.Max(x => x.Id);
                    List <int> SubjectIDs    = db.AspNetSubjects.Where(x => x.AspNetClass.SessionID == Session).Select(x => x.Id).ToList();
                    var        parentSubject = (from parentchild in db.AspNetParent_Child
                                                join studentsubject in db.AspNetStudent_Subject on parentchild.ChildID equals studentsubject.StudentID
                                                where SubjectIDs.Contains(studentsubject.SubjectID)
                                                select new { parentchild.ParentID, studentsubject.SubjectID }).ToList();
                    foreach (var parentsubject in parentSubject)
                    {
                        AspNetPTMAttendance PTMAttendace = new AspNetPTMAttendance();
                        PTMAttendace.ParentID  = parentsubject.ParentID;
                        PTMAttendace.SubjectID = parentsubject.SubjectID;
                        PTMAttendace.Status    = "Absent";
                        PTMAttendace.Rating    = -1;
                        PTMAttendace.MeetingID = MeetingID;
                        db.AspNetPTMAttendances.Add(PTMAttendace);
                        db.SaveChanges();

                        int        PTMAttendaceID    = db.AspNetPTMAttendances.Max(x => x.Id);
                        List <int> ParentQuestionIDs = db.AspNetFeedBackForms.Where(x => x.AspNetPTMFormRole.RoleName == "Parent" && x.SessionID == Session).Select(x => x.Id).ToList();
                        foreach (var questionID in ParentQuestionIDs)
                        {
                            AspNetPTM_ParentFeedback PTM_ParentFeedback = new AspNetPTM_ParentFeedback();
                            PTM_ParentFeedback.PTMID     = PTMAttendaceID;
                            PTM_ParentFeedback.HeadingID = questionID;
                            db.AspNetPTM_ParentFeedback.Add(PTM_ParentFeedback);
                            db.SaveChanges();
                        }
                        List <int> TeacherQuestionIDs = db.AspNetFeedBackForms.Where(x => x.AspNetPTMFormRole.RoleName == "Teacher" && x.SessionID == Session).Select(x => x.Id).ToList();
                        foreach (var questionID in TeacherQuestionIDs)
                        {
                            AspNetPTM_TeacherFeedback PTM_TeacherFeedback = new AspNetPTM_TeacherFeedback();
                            PTM_TeacherFeedback.PTMID     = PTMAttendaceID;
                            PTM_TeacherFeedback.HeadingID = questionID;
                            db.AspNetPTM_TeacherFeedback.Add(PTM_TeacherFeedback);
                            db.SaveChanges();
                            ///////////////////////////////////////////////////////////////////////////////////////////
                        }
                    }


                    var NotificationObj = new AspNetNotification();
                    NotificationObj.Description = aspNetParentTeacherMeeting.Description;
                    NotificationObj.Subject     = aspNetParentTeacherMeeting.Title;
                    NotificationObj.SenderID    = User.Identity.GetUserId();
                    NotificationObj.Time        = DateTime.Now;
                    NotificationObj.SessionID   = Session;
                    db.AspNetNotifications.Add(NotificationObj);
                    db.SaveChanges();

                    var NotificationID = db.AspNetNotifications.Max(x => x.Id);
                    var receiverId     = (from teacher in db.AspNetUsers.Where(x => x.Status != "False" && x.AspNetUsers_Session.Any(y => y.SessionID == Session))
                                          where teacher.AspNetRoles.Select(y => y.Name).Contains("Teacher") ||
                                          teacher.AspNetRoles.Select(y => y.Name).Contains("Student") ||
                                          teacher.AspNetRoles.Select(y => y.Name).Contains("Parent")

                                          select new { teacher.Id }).ToList();

                    List <string> obled = new List <string>();

                    foreach (var sender in receiverId)
                    {
                        var notificationRecieve = new AspNetNotification_User();
                        notificationRecieve.NotificationID = NotificationID;
                        notificationRecieve.UserID         = sender.Id;
                        notificationRecieve.Seen           = false;
                        db.AspNetNotification_User.Add(notificationRecieve);
                        db.SaveChanges();



                        obled.Add(sender.Id);
                    }

                    //Message start
                    //var classe = db.AspNetClasses.Where(p => p.Id == aspNetHomework.ClassId).FirstOrDefault();
                    Utility obj = new Utility();
                    obj.SMSToOffitialsp("Dear Principal, Parent Teacher Meeting is scheduled on" + aspNetParentTeacherMeeting.Date + " at " + aspNetParentTeacherMeeting.Time + "., Title : " + aspNetParentTeacherMeeting.Title + " IPC NGS Preschool, Aziz Avenue, Lahore.");
                    obj.SMSToOffitialsa("Dear Admin, Parent Teacher Meeting is scheduled on " + aspNetParentTeacherMeeting.Date + " at " + aspNetParentTeacherMeeting.Time + "., Title : " + aspNetParentTeacherMeeting.Title + " IPC NGS Preschool, Aziz Avenue, Lahore.");
                    AspNetMessage oob = new AspNetMessage();
                    oob.Message = "Dear Parent, The Parent Teacher Meeting is scheduled on " + aspNetParentTeacherMeeting.Date + " at " + aspNetParentTeacherMeeting.Time + ". Your regularity and punctuality will be appreciated. IPC NGS Preschool, Aziz Avenue, Lahore.";
                    //oob.Message = "Parent Teacher Meeting is arranged,  Title : " + aspNetParentTeacherMeeting.Title + "For discription login to Portal please";
                    obj.SendSMS(oob, obled);
                    //Message end



                    var PTMNOTIFICATIOn = new AspNetNotificationController();
                    PTMNOTIFICATIOn.PTMNotification();
                    db.SaveChanges();
                    transactionObj.Commit();
                }

                catch (Exception ex)
                {
                    transactionObj.Dispose();
                }
                return(RedirectToAction("Index"));
            }

            return(View(aspNetParentTeacherMeeting));
        }