public JsonResult SaveEvent(Event e)
        {
            e.UserId = User.Identity.GetUserId();
            var status = false;

            using (SEA_DatabaseEntities dc = new SEA_DatabaseEntities())
            {
                if (e.EventID > 0)
                {
                    //Update the event
                    var v = dc.Events.Where(a => a.EventID == e.EventID).FirstOrDefault();
                    if (v != null)
                    {
                        v.Subject     = e.Subject;
                        v.Start       = e.Start;
                        v.End         = e.End;
                        v.Description = e.Description;
                        v.IsFullDay   = e.IsFullDay;
                        v.ThemeColor  = e.ThemeColor;
                    }
                }
                else
                {
                    dc.Events.Add(e);
                }

                dc.SaveChanges();
                status = true;
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        //        public ActionResult Index()
        //        {
        //            var aspNetClasses = (from cls in db.AspNetClasses.Include(a => a.AspNetUser)
        //                                 join std_cls in db.AspNetStudent_Session_class on
        //cls.Id equals std_cls.ClassID
        //                                 where std_cls.SessionID == 17
        //                                 select cls);
        //            return View(aspNetClasses.Distinct().ToList());
        //        }

        public void ClassExcelRecord()
        {
            SEA_DatabaseEntities db = new SEA_DatabaseEntities();
            List <AspNetClass>   ClassList;

            ClassList = db.AspNetClasses.Select(x => x).ToList();

            ExcelPackage   pck = new ExcelPackage();
            ExcelWorksheet ws  = pck.Workbook.Worksheets.Add("Report");

            ws.Cells["A1"].Value = "Class Name";
            ws.Cells["B1"].Value = "Teacher";
            ws.Cells["C1"].Value = "Class";
            ws.Cells["D1"].Value = "Section";

            int rowStart = 2;

            foreach (var item in ClassList)
            {
                ws.Cells[string.Format("A{0}", rowStart)].Value = item.ClassName;
                ws.Cells[string.Format("B{0}", rowStart)].Value = item.AspNetUser.UserName;
                ws.Cells[string.Format("C{0}", rowStart)].Value = item.Class;
                ws.Cells[string.Format("D{0}", rowStart)].Value = item.Section;
                rowStart++;
            }
            ws.Cells["A:AZ"].AutoFitColumns();
            Response.Clear();
            Response.ContentType = "application/vnd.openxmlformates-officedocument.spreadsheetml.sheet";
            Response.AddHeader("content-disposition", "attachment:filename=" + "ExcelReport.xlsx");
            Response.BinaryWrite(pck.GetAsByteArray());
            Response.End();

            //return RedirectToAction("TeacherIndex");
        }
 public JsonResult GetEvents()
 {
     using (SEA_DatabaseEntities dc = new SEA_DatabaseEntities())
     {
         var id     = User.Identity.GetUserId();
         var events = dc.Events.Where(x => x.UserId == id || x.IsPublic == true).Select(x => new { x.Description, x.End, x.EventID, x.IsFullDay, x.Subject, x.ThemeColor, x.Start, x.IsPublic }).ToList();
         return(new JsonResult {
             Data = events, JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
 }
        public void FeeChallan_ExcelReport(string month)
        {
            SEA_DatabaseEntities db = new SEA_DatabaseEntities();

            var challanlist = (from feemonth in db.StudentFeeMonths
                               join std in db.AspNetStudents on feemonth.StudentId equals std.Id
                               join challan in db.StudentChallanForms on std.Id equals challan.StudentId
                               where feemonth.Status == "Pending" && feemonth.Months == month && feemonth.Id == challan.StudentFeeMonthId
                               select new { challan.ChallanNo, feemonth.Months, feemonth.FeePayable, feemonth.IssueDate, std.AspNetUser.Name, std.AspNetClass.ClassName, feemonth.DueDate, feemonth.ValildityDate, }).ToList();


            ExcelPackage   pck = new ExcelPackage();
            ExcelWorksheet ws  = pck.Workbook.Worksheets.Add("Report");

            ws.Cells["A1"].Value = "Challan No";
            ws.Cells["B1"].Value = "Payable before due date";
            ws.Cells["C1"].Value = "Issue Date";
            ws.Cells["D1"].Value = "Registration No";
            ws.Cells["E1"].Value = "Student Name";
            ws.Cells["F1"].Value = "Class";
            ws.Cells["G1"].Value = "Due Date";
            ws.Cells["H1"].Value = "For the month of";
            ws.Cells["I1"].Value = "Payable after due date";
            ws.Cells["J1"].Value = "Validity Date";


            int rowStart = 2;

            foreach (var item in challanlist)
            {
                ws.Cells[string.Format("A{0}", rowStart)].Value = item.ChallanNo;
                ws.Cells[string.Format("B{0}", rowStart)].Value = item.FeePayable;
                ws.Cells[string.Format("C{0}", rowStart)].Value = item.IssueDate;
                ws.Cells[string.Format("D{0}", rowStart)].Value = "";
                ws.Cells[string.Format("E{0}", rowStart)].Value = item.Name;
                ws.Cells[string.Format("F{0}", rowStart)].Value = item.ClassName;
                ws.Cells[string.Format("G{0}", rowStart)].Value = item.DueDate;
                ws.Cells[string.Format("H{0}", rowStart)].Value = month;
                ws.Cells[string.Format("I{0}", rowStart)].Value = item.FeePayable;
                ws.Cells[string.Format("J{0}", rowStart)].Value = item.ValildityDate;

                rowStart++;
            }
            ws.Cells["A:AZ"].AutoFitColumns();
            Response.Clear();
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("content-disposition", "attachment:filename=ExcelReport.xls");
            Response.BinaryWrite(pck.GetAsByteArray());
            Response.End();

            //return RedirectToAction("TeacherIndex");
        }
        public JsonResult DeleteEvent(int eventID)
        {
            var status = false;

            using (SEA_DatabaseEntities dc = new SEA_DatabaseEntities())
            {
                var v = dc.Events.Where(a => a.EventID == eventID).FirstOrDefault();
                if (v != null)
                {
                    dc.Events.Remove(v);
                    dc.SaveChanges();
                    status = true;
                }
            }
            return(new JsonResult {
                Data = new { status = status }
            });
        }
        public ActionResult NewSubjectsForTeacher(string ClassID1, string teachers)
        {
            int?classId = Convert.ToInt32(ClassID1);
            List <AspNetTeacherSubject> AllTeacherSubjectOfCurrentClass = db.AspNetTeacherSubjects.Where(x => x.AspNetSubject.ClassID == classId).ToList();

            int?teacherId = Convert.ToInt32(teachers);

            var SubjectsToRemoveOfCurrentTeacher = AllTeacherSubjectOfCurrentClass.Where(x => x.TeacherID == teacherId);

            db.AspNetTeacherSubjects.RemoveRange(SubjectsToRemoveOfCurrentTeacher);

            db.SaveChanges();


            var TeacherGenericSubjectsToRemove = db.Teacher_GenericSubjects.Where(x => x.TeacherId == teacherId).ToList();;

            db.Teacher_GenericSubjects.RemoveRange(TeacherGenericSubjectsToRemove);

            db.SaveChanges();


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

            if (Request.Form["MandatorySubjects"] != null)
            {
                selectedsubjects.AddRange(Request.Form["MandatorySubjects"].Split(',').ToList());
            }

            if (Request.Form["OptionalSubjects"] != null)
            {
                selectedsubjects.AddRange(Request.Form["OptionalSubjects"].Split(',').ToList());
            }

            List <string> listofIDs = selectedsubjects.ToList();
            List <int>    myIntegersSubjectsList = listofIDs.Select(s => int.Parse(s)).ToList();


            if (selectedsubjects != null)
            {
                foreach (var item in selectedsubjects)
                {
                    AspNetTeacherSubject teacherSubject = new AspNetTeacherSubject();

                    teacherSubject.TeacherID = teacherId;
                    teacherSubject.SubjectID = Convert.ToInt32(item);

                    db.AspNetTeacherSubjects.Add(teacherSubject);

                    db.SaveChanges();
                }
            }

            SEA_DatabaseEntities db1 = new SEA_DatabaseEntities();



            if (selectedsubjects != null)
            {
                var AllSubjectsOfTeacher = from subject in db.AspNetSubjects
                                           where myIntegersSubjectsList.Contains(subject.Id)
                                           select subject;


                foreach (var sub in AllSubjectsOfTeacher)
                {
                    foreach (var sub1 in db.GenericSubjects.ToList())
                    {
                        if (sub.SubjectName == sub1.SubjectName && sub.CourseType == sub1.SubjectType)
                        {
                            Teacher_GenericSubjects genericSubject = new Teacher_GenericSubjects();

                            genericSubject.SubjectId = sub1.Id;
                            genericSubject.TeacherId = teacherId;

                            db1.Teacher_GenericSubjects.Add(genericSubject);
                            db1.SaveChanges();
                        }
                    }
                }
            }



            int?SessionId = db.AspNetClasses.Where(x => x.Id == classId).FirstOrDefault().SessionID;

            var EmployeeExist = db.Aspnet_Employee_Session.Where(x => x.Emp_Id == teacherId && x.Session_Id == SessionId).FirstOrDefault();

            if (EmployeeExist == null)
            {
                Aspnet_Employee_Session ES = new Aspnet_Employee_Session();
                ES.Emp_Id     = teacherId;
                ES.Session_Id = SessionId;
                db.Aspnet_Employee_Session.Add(ES);
                db.SaveChanges();
            }

            var UserId = db.AspNetEmployees.Where(x => x.Id == teacherId).FirstOrDefault().UserId;

            var EmployeeExist1 = db.AspNetUsers_Session.Where(x => x.UserID == UserId && x.SessionID == SessionId).FirstOrDefault();

            if (EmployeeExist1 == null)
            {
                AspNetUsers_Session US = new AspNetUsers_Session();
                US.UserID    = UserId;
                US.SessionID = SessionId;
                db.AspNetUsers_Session.Add(US);
                db.SaveChanges();
            }


            return(RedirectToAction("ClassIndex"));
        }
        public ActionResult Edit(LessonViewModel LessonViewModel)
        {
            AspnetLesson Lesson = db.AspnetLessons.Where(x => x.Id == LessonViewModel.Id).FirstOrDefault();

            Lesson.Name            = LessonViewModel.LessonName;
            Lesson.Video_Url       = LessonViewModel.LessonVideoURL;
            Lesson.TopicId         = LessonViewModel.TopicId;
            Lesson.DurationMinutes = LessonViewModel.LessonDuration;
            Lesson.Description     = LessonViewModel.LessonDescription;
            db.SaveChanges();


            HttpPostedFileBase Assignment  = Request.Files["Assignment"];
            HttpPostedFileBase Attachment1 = Request.Files["Attachment1"];
            HttpPostedFileBase Attachment2 = Request.Files["Attachment2"];
            HttpPostedFileBase Attachment3 = Request.Files["Attachment3"];

            var fileName = "";

            if (Assignment.ContentLength > 0)
            {
                fileName = Path.GetFileName(Assignment.FileName);
                Assignment.SaveAs(Server.MapPath("~/Content/StudentAssignments/") + fileName);
            }
            AspnetStudentAssignment studentAssignment = db.AspnetStudentAssignments.Where(x => x.LessonId == Lesson.Id).FirstOrDefault();

            if (studentAssignment != null)
            {
                if (fileName != "")
                {
                    studentAssignment.FileName = fileName;
                }

                studentAssignment.Name = LessonViewModel.AssignmentName;
                string DueDate = Convert.ToString(LessonViewModel.AssignmentDueDate);

                if (DueDate == "1/1/0001 12:00:00 AM")
                {
                    studentAssignment.DueDate = null;
                }
                else
                {
                    studentAssignment.DueDate = LessonViewModel.AssignmentDueDate;
                }

                studentAssignment.Description = LessonViewModel.AssignmentDescription;
                db.SaveChanges();
            }
            else
            {
                if (Assignment.ContentLength > 0)
                {
                    AspnetStudentAssignment studentAssignment1 = new AspnetStudentAssignment();

                    studentAssignment1.FileName = fileName;

                    studentAssignment1.Name = LessonViewModel.AssignmentName;


                    string DueDate = Convert.ToString(LessonViewModel.AssignmentDueDate);


                    if (DueDate == "1/1/0001 12:00:00 AM")
                    {
                        studentAssignment1.DueDate = null;
                    }
                    else
                    {
                        studentAssignment1.DueDate = LessonViewModel.AssignmentDueDate;
                    }


                    studentAssignment1.Description  = LessonViewModel.AssignmentDescription;
                    studentAssignment1.CreationDate = DateTime.Now;
                    studentAssignment1.LessonId     = Lesson.Id;

                    db.AspnetStudentAssignments.Add(studentAssignment1);
                    db.SaveChanges();
                }
            }


            List <AspnetStudentAttachment> studentAttachments = db.AspnetStudentAttachments.Where(x => x.LessonId == Lesson.Id).ToList();
            List <AspnetStudentLink>       studentLinks       = db.AspnetStudentLinks.Where(x => x.LessonId == Lesson.Id).ToList();



            //db.AspnetStudentAttachments.RemoveRange(studentAttachments);
            //db.SaveChanges();

            db.AspnetStudentLinks.RemoveRange(studentLinks);
            db.SaveChanges();

            SEA_DatabaseEntities db1 = new SEA_DatabaseEntities();

            List <AspnetStudentAttachment> studentAttachments1 = db1.AspnetStudentAttachments.Where(x => x.LessonId == Lesson.Id).ToList();

            int TotalAttachments = studentAttachments1.Count;

            if (TotalAttachments == 0)
            {
                if (Attachment1.ContentLength > 0)
                {
                    var fileName1 = Path.GetFileName(Attachment1.FileName);
                    Attachment1.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);

                    AspnetStudentAttachment studentAttachment1 = new AspnetStudentAttachment();

                    studentAttachment1.Name         = LessonViewModel.AttachmentName1;
                    studentAttachment1.Path         = fileName1;
                    studentAttachment1.CreationDate = DateTime.Now;
                    studentAttachment1.LessonId     = Lesson.Id;
                    db.AspnetStudentAttachments.Add(studentAttachment1);
                    db.SaveChanges();
                }
                if (Attachment2.ContentLength > 0)
                {
                    var fileName1 = Path.GetFileName(Attachment2.FileName);
                    Attachment2.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);

                    AspnetStudentAttachment studentAttachment2 = new AspnetStudentAttachment();

                    studentAttachment2.Name         = LessonViewModel.AttachmentName2;
                    studentAttachment2.Path         = fileName1;
                    studentAttachment2.CreationDate = DateTime.Now;
                    studentAttachment2.LessonId     = Lesson.Id;
                    db.AspnetStudentAttachments.Add(studentAttachment2);

                    db.SaveChanges();
                }

                if (Attachment3.ContentLength > 0)
                {
                    var fileName1 = Path.GetFileName(Attachment3.FileName);
                    Attachment3.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);

                    AspnetStudentAttachment studentAttachment3 = new AspnetStudentAttachment();

                    studentAttachment3.Name         = LessonViewModel.AttachmentName3;
                    studentAttachment3.Path         = fileName1;
                    studentAttachment3.CreationDate = DateTime.Now;
                    studentAttachment3.LessonId     = Lesson.Id;
                    db.AspnetStudentAttachments.Add(studentAttachment3);
                    db.SaveChanges();
                }
            }
            else
            {
                if (TotalAttachments == 1)
                {
                    var FirstElement = studentAttachments1.ElementAt(0);
                    FirstElement.Name = LessonViewModel.AttachmentName1;

                    var FileName = FirstElement.Path;

                    if (Attachment1.ContentLength > 0)
                    {
                        var fileName1 = Path.GetFileName(Attachment1.FileName);
                        FileName = fileName1;
                        Attachment1.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);
                    }
                    FirstElement.Path = FileName;
                    db1.SaveChanges();

                    if (Attachment2.ContentLength > 0)
                    {
                        var fileName1 = Path.GetFileName(Attachment2.FileName);
                        Attachment2.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);

                        AspnetStudentAttachment studentAttachment2 = new AspnetStudentAttachment();

                        studentAttachment2.Name         = LessonViewModel.AttachmentName2;
                        studentAttachment2.Path         = fileName1;
                        studentAttachment2.CreationDate = DateTime.Now;
                        studentAttachment2.LessonId     = Lesson.Id;
                        db.AspnetStudentAttachments.Add(studentAttachment2);

                        db.SaveChanges();
                    }

                    if (Attachment3.ContentLength > 0)
                    {
                        var fileName1 = Path.GetFileName(Attachment3.FileName);
                        Attachment3.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);

                        AspnetStudentAttachment studentAttachment3 = new AspnetStudentAttachment();

                        studentAttachment3.Name         = LessonViewModel.AttachmentName3;
                        studentAttachment3.Path         = fileName1;
                        studentAttachment3.CreationDate = DateTime.Now;
                        studentAttachment3.LessonId     = Lesson.Id;
                        db.AspnetStudentAttachments.Add(studentAttachment3);
                        db.SaveChanges();
                    }
                }

                else if (TotalAttachments == 2)
                {
                    var FirstElement = studentAttachments1.ElementAt(0);
                    FirstElement.Name = LessonViewModel.AttachmentName1;

                    var FileName0 = FirstElement.Path;

                    if (Attachment1.ContentLength > 0)
                    {
                        var fileName1 = Path.GetFileName(Attachment1.FileName);
                        FileName0 = fileName1;
                        Attachment1.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);
                    }
                    FirstElement.Path = FileName0;
                    db1.SaveChanges();


                    var SecondElement = studentAttachments1.ElementAt(1);
                    SecondElement.Name = LessonViewModel.AttachmentName2;

                    var FileName1 = SecondElement.Path;

                    if (Attachment2.ContentLength > 0)
                    {
                        var fileName2 = Path.GetFileName(Attachment2.FileName);
                        FileName1 = fileName2;
                        Attachment2.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName2);
                    }
                    SecondElement.Path = FileName1;
                    db1.SaveChanges();



                    if (Attachment3.ContentLength > 0)
                    {
                        var fileName1 = Path.GetFileName(Attachment3.FileName);
                        Attachment3.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);

                        AspnetStudentAttachment studentAttachment3 = new AspnetStudentAttachment();

                        studentAttachment3.Name         = LessonViewModel.AttachmentName3;
                        studentAttachment3.Path         = fileName1;
                        studentAttachment3.CreationDate = DateTime.Now;
                        studentAttachment3.LessonId     = Lesson.Id;
                        db.AspnetStudentAttachments.Add(studentAttachment3);
                        db.SaveChanges();
                    }
                }

                else
                {
                    var FirstElement = studentAttachments1.ElementAt(0);
                    FirstElement.Name = LessonViewModel.AttachmentName1;

                    var FileName0 = FirstElement.Path;

                    if (Attachment1.ContentLength > 0)
                    {
                        var fileName1 = Path.GetFileName(Attachment1.FileName);
                        FileName0 = fileName1;
                        Attachment1.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName1);
                    }
                    FirstElement.Path = FileName0;
                    db1.SaveChanges();


                    var SecondElement = studentAttachments1.ElementAt(1);
                    SecondElement.Name = LessonViewModel.AttachmentName2;

                    var FileName1 = SecondElement.Path;

                    if (Attachment2.ContentLength > 0)
                    {
                        var fileName2 = Path.GetFileName(Attachment2.FileName);
                        FileName1 = fileName2;
                        Attachment2.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName2);
                    }
                    SecondElement.Path = FileName1;
                    db1.SaveChanges();


                    var ThirdElement = studentAttachments1.ElementAt(2);
                    ThirdElement.Name = LessonViewModel.AttachmentName3;

                    var FileName2 = ThirdElement.Path;

                    if (Attachment3.ContentLength > 0)
                    {
                        var fileName3 = Path.GetFileName(Attachment3.FileName);
                        FileName2 = fileName3;
                        Attachment2.SaveAs(Server.MapPath("~/Content/StudentAttachments/") + fileName3);
                    }
                    ThirdElement.Path = FileName2;
                    db1.SaveChanges();
                }
            }



            if (LessonViewModel.LinkUrl1 != null)
            {
                AspnetStudentLink link1 = new AspnetStudentLink();

                link1.URL          = LessonViewModel.LinkUrl1;
                link1.CreationDate = DateTime.Now;
                link1.LessonId     = Lesson.Id;
                db.AspnetStudentLinks.Add(link1);
                db.SaveChanges();
            }

            if (LessonViewModel.LinkUrl2 != null)
            {
                AspnetStudentLink link2 = new AspnetStudentLink();

                link2.URL          = LessonViewModel.LinkUrl2;
                link2.CreationDate = DateTime.Now;
                link2.LessonId     = Lesson.Id;
                db.AspnetStudentLinks.Add(link2);
                db.SaveChanges();
            }


            if (LessonViewModel.LinkUrl3 != null)
            {
                AspnetStudentLink link3 = new AspnetStudentLink();

                link3.URL          = LessonViewModel.LinkUrl3;
                link3.CreationDate = DateTime.Now;
                link3.LessonId     = Lesson.Id;
                db.AspnetStudentLinks.Add(link3);
                db.SaveChanges();
            }


            return(RedirectToAction("ViewTopicsAndLessons", "AspnetSubjectTopics"));
        }
        }// Student Assignment Submission

        public ActionResult SaveCommentHead(int LessonID, string Title, string Body)
        {
            var id = User.Identity.GetUserId();
            AspnetComment_Head commentHead = new AspnetComment_Head();
            string             EncrID      = LessonID + Title + Body + id;

            commentHead.EncryptedID = Encrpt.Encrypt(EncrID, true);


            var newString = Regex.Replace(commentHead.EncryptedID, @"[^0-9a-zA-Z]+", "s");

            string str = newString.Substring(0, 32);


            commentHead.EncryptedID = str;

            //Comment_Head commentHead = new Comment_Head();
            commentHead.Comment_Head = Title;
            commentHead.CommentBody  = Body;
            commentHead.LessonId     = LessonID;
            commentHead.CreatedBy    = id;

            commentHead.CreationDate = GetLocalDateTime.GetLocalDateTimeFunction();
            db.AspnetComment_Head.Add(commentHead);
            db.SaveChanges();


            var UserId          = User.Identity.GetUserId();
            var UserName        = db.AspNetUsers.Where(x => x.Id == UserId).FirstOrDefault().Name;
            var NotificationObj = new AspNetNotification();

            NotificationObj.Description = UserName + " asked a Question";
            NotificationObj.Subject     = "Student Comment ";
            NotificationObj.SenderID    = UserId;
            NotificationObj.Time        = GetLocalDateTime.GetLocalDateTimeFunction();
            NotificationObj.Url         = "/TeacherCommentsOnCourses/CommentsPage1/" + commentHead.Id;

            db.AspNetNotifications.Add(NotificationObj);
            db.SaveChanges();


            int?TopicId   = db.AspnetLessons.Where(x => x.Id == LessonID).FirstOrDefault().TopicId;
            int?SubjectId = db.AspnetSubjectTopics.Where(x => x.Id == TopicId).FirstOrDefault().SubjectId;

            var AllTeachers = db.Teacher_GenericSubjects.Where(x => x.SubjectId == SubjectId).Select(x => x.TeacherId);

            var UnionTeachers = AllTeachers.Distinct();

            var AllEmployeesUserId = from employee in db.AspNetEmployees
                                     where AllTeachers.Contains(employee.Id)
                                     select new
            {
                employee.UserId,
            };



            SEA_DatabaseEntities db2 = new SEA_DatabaseEntities();

            foreach (var receiver in AllEmployeesUserId)
            {
                var notificationRecieve = new AspNetNotification_User();
                notificationRecieve.NotificationID = NotificationObj.Id;
                notificationRecieve.UserID         = Convert.ToString(receiver.UserId);
                notificationRecieve.Seen           = false;
                db2.AspNetNotification_User.Add(notificationRecieve);
                try
                {
                    db2.SaveChanges();
                }

                catch (Exception ex)
                {
                    var Msg = ex.Message;
                }
            }


            return(Json("", JsonRequestBehavior.AllowGet));
        }
        public ActionResult CommentReply(int CommentHeadId, string UserComment)
        {
            var id = User.Identity.GetUserId();

            int           count      = db.AspnetComments.Count();
            AspnetComment commentobj = new AspnetComment();

            if (count == 0)
            {
                commentobj.ParentCommentId = null;
                commentobj.Comment         = UserComment;
                commentobj.CreationDate    = GetLocalDateTime.GetLocalDateTimeFunction();
                commentobj.HeadId          = CommentHeadId;
                commentobj.CreatedBy       = id;
                db.AspnetComments.Add(commentobj);
                db.SaveChanges();
            }
            else
            {
                int LastId = db.AspnetComments.OrderByDescending(o => o.Id).FirstOrDefault().Id;
                commentobj.ParentCommentId = LastId;
                commentobj.Comment         = UserComment;
                commentobj.CreationDate    = GetLocalDateTime.GetLocalDateTimeFunction();
                commentobj.HeadId          = CommentHeadId;
                commentobj.CreatedBy       = id;

                db.AspnetComments.Add(commentobj);
                db.SaveChanges();
            }


            var        UserNameLog = User.Identity.Name;
            AspNetUser currentUser = db.AspNetUsers.First(x => x.UserName == UserNameLog);

            var UserId          = User.Identity.GetUserId();
            var UserName        = db.AspNetUsers.Where(x => x.Id == UserId).FirstOrDefault().Name;
            var NotificationObj = new AspNetNotification();

            NotificationObj.Description = "Teacher " + UserName + " Replied";
            NotificationObj.Subject     = "Reply To Student Comment";
            NotificationObj.SenderID    = UserId;
            NotificationObj.Time        = GetLocalDateTime.GetLocalDateTimeFunction();
            NotificationObj.Url         = "/StudentCourses/CommentsPage1/" + CommentHeadId;

            db.AspNetNotifications.Add(NotificationObj);
            db.SaveChanges();

            //int? LessonID = db.AspnetComment_Head.Where(x => x.Id == CommentHeadId).FirstOrDefault().LessonId;
            //int? TopicId = db.AspnetLessons.Where(x => x.Id == LessonID).FirstOrDefault().TopicId;
            //int? SubjectId = db.AspnetSubjectTopics.Where(x => x.Id == TopicId).FirstOrDefault().SubjectId;


            //var AllStudents = db.Student_GenericSubjects.Where(x => x.GenericSubjectId == SubjectId).Select(x => x.StudentId);

            //var DistinctStudents = AllStudents.Distinct();

            //foreach (var receiver in DistinctStudents)
            //{
            var receiver = db.AspnetComment_Head.Where(x => x.Id == CommentHeadId).Select(x => x.CreatedBy).FirstOrDefault();

            SEA_DatabaseEntities db2 = new SEA_DatabaseEntities();


            var notificationRecieve = new AspNetNotification_User();

            notificationRecieve.NotificationID = NotificationObj.Id;
            notificationRecieve.UserID         = Convert.ToString(receiver);
            notificationRecieve.Seen           = false;
            db2.AspNetNotification_User.Add(notificationRecieve);
            db2.SaveChanges();


            // }

            return(Json("", JsonRequestBehavior.AllowGet));
        }
        public async Task <String> Login(string UserName, string Password)
        {
            SEA_DatabaseEntities db = new SEA_DatabaseEntities();

            LoginViewModel model = new LoginViewModel();

            model.UserName   = UserName;
            model.Password   = Password;
            model.RememberMe = false;

            var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout : false);

            LoginUser login = new LoginUser();

            switch (result)
            {
            case SignInStatus.Success:

                var userID = SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();

                var USER = db.AspNetUsers.Where(x => x.Id == userID).Select(x => x).FirstOrDefault();
                login.Id   = userID;
                login.Name = USER.Name;

                if (UserManager.IsInRole(userID, "Teacher"))
                {
                    login.Role = "Teacher";
                }
                else if (UserManager.IsInRole(userID, "Student"))
                {
                    login.Role = "Student";
                }
                else if (UserManager.IsInRole(userID, "Admin"))
                {
                    login.Role = "Admin";
                }
                else if (UserManager.IsInRole(userID, "Principal"))
                {
                    login.Role = "Principal";
                }
                else if (UserManager.IsInRole(userID, "Accountant"))
                {
                    login.Role = "Accountant";
                }
                else if (UserManager.IsInRole(userID, "Parent"))
                {
                    login.Role = "Parent";
                }

                if (USER.Status == "False")
                {
                    login.Message = "Admin Has disabled your account";
                }
                else
                {
                    login.Message = "Login Success";
                }



                var    javaScriptSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
                string jsonString           = javaScriptSerializer.Serialize(login);

                return(jsonString);

            case SignInStatus.Failure:
                login.Message = "Invalid login attempt.";

                var    javaScriptSerializer1 = new System.Web.Script.Serialization.JavaScriptSerializer();
                string jsonString1           = javaScriptSerializer1.Serialize(login);

                return(jsonString1);

            default:
                login.Message = "Invalid login attempt.";
                var    javaScriptSerializer2 = new System.Web.Script.Serialization.JavaScriptSerializer();
                string jsonString2           = javaScriptSerializer2.Serialize(login);

                return(jsonString2);
            }
        }