public string SeeNotification(int Id) { string status = "error"; AspNetNotification_User Notification = db.AspNetNotification_User.Where(x => x.Id == Id).Select(x => x).FirstOrDefault(); if (Notification == null) { status = "no data found"; } else { Notification.Seen = true; if (db.SaveChanges() > 0) { status = "success"; } } return(status); }
public ActionResult NotificationDetail(int?id) { AspNetNotification_User aspNetNotificationUser = db.AspNetNotification_User.Where(x => x.Id == id).FirstOrDefault(); aspNetNotificationUser.Seen = true; db.SaveChanges(); var AspNetNotification = db.AspNetNotifications.Find(aspNetNotificationUser.NotificationID); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // List<int> student = db.Student_Subject.Where(x => SubjectIDs.Contains(x.SubjectID)).Select(s => s.StudentID).ToList(); if (AspNetNotification == null) { return(HttpNotFound()); } return(View(AspNetNotification)); }
public void Notify(int Id) { db.AspNetStudent_Term_Assessment.FirstOrDefault(x => x.Id == Id).NotifyTeacher = true; var STAID = db.AspNetStudent_Term_Assessment.FirstOrDefault(x => x.Id == Id); AspNetNotification AspNetNotification = new AspNetNotification(); AspNetNotification.Time = DateTime.Now; AspNetNotification.Subject = STAID.AspNetSubject.SubjectName; AspNetNotification.SenderID = User.Identity.GetUserId(); AspNetNotification.Description = "Correction of term assessment of student " + STAID.AspNetUser.Name + " of class " + STAID.AspNetSubject.AspNetClass.ClassName; db.AspNetNotifications.Add(AspNetNotification); db.SaveChanges(); AspNetNotification_User AspNetNotification_User = new AspNetNotification_User(); AspNetNotification_User.Seen = false; AspNetNotification_User.NotificationID = AspNetNotification.Id; AspNetNotification_User.UserID = STAID.AspNetSubject.AspNetClass.TeacherID; db.AspNetNotification_User.Add(AspNetNotification_User); db.SaveChanges(); }
public ActionResult Save_Holiday(string check, string title, DateTime start, DateTime end) { AspNetHoliday_Calendar_Notification cn = new AspNetHoliday_Calendar_Notification(); cn.Title = title; cn.StartDate = start; cn.EndDate = end; db.AspNetHoliday_Calendar_Notification.Add(cn); db.SaveChanges(); ///////////////////////////////NOTIFICATION/////////////////////////////////// if (check == "On") { var NotificationObj = new AspNetNotification(); NotificationObj.Description = ""; NotificationObj.Subject = title; NotificationObj.SenderID = User.Identity.GetUserId(); NotificationObj.Time = DateTime.Now; NotificationObj.Url = ""; db.AspNetNotifications.Add(NotificationObj); db.SaveChanges(); var NotificationID = db.AspNetNotifications.Max(x => x.Id); var allusers = db.AspNetEmployees.Where(x => x.VirtualRoleId == 35).Select(x => x.UserId).ToList(); foreach (var receiver in allusers) { var notificationRecieve = new AspNetNotification_User(); notificationRecieve.NotificationID = NotificationID; notificationRecieve.UserID = Convert.ToString(receiver); notificationRecieve.Seen = false; db.AspNetNotification_User.Add(notificationRecieve); db.SaveChanges(); } } return(View("Calendar_Notify")); }
// GET: AspNetPushNotifications/Details/5 public ActionResult Details(int?id) { var UserNameLog = User.Identity.Name; AspNetUser currentUser = db.AspNetUsers.First(x => x.UserName == UserNameLog); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AspNetNotification_User aspNetNotification = db.AspNetNotification_User.Where(x => x.Id == id).FirstOrDefault(); if (aspNetNotification.UserID == currentUser.Id) { aspNetNotification.Seen = true; db.SaveChanges(); } if (aspNetNotification == null) { return(HttpNotFound()); } return(View(aspNetNotification.AspNetNotification)); }
// GET: AspNetPushNotifications/Details/5 public ActionResult Details(int?id) { var UserNameLog = User.Identity.Name; AspNetUser currentUser = db.AspNetUsers.First(x => x.UserName == UserNameLog); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } if (this.User.IsInRole("Teacher")) { ViewBag.AchorTagText = "Reply to Student Comment"; } else if (this.User.IsInRole("Student")) { ViewBag.AchorTagText = "See Teacher Reply"; } else { ViewBag.AchorTagText = ""; } AspNetNotification_User aspNetNotification = db.AspNetNotification_User.Where(x => x.Id == id).FirstOrDefault(); if (aspNetNotification.UserID == currentUser.Id) { aspNetNotification.Seen = true; db.SaveChanges(); } if (aspNetNotification == null) { return(HttpNotFound()); } return(View(aspNetNotification.AspNetNotification)); }
public ActionResult Create([Bind(Include = "Id,Title,Description")] AspNetAnnouncement aspNetAnnouncement) { string subjects = Request.Form["subjects"]; IEnumerable <string> selectedsubjects = subjects.Split(','); if (ModelState.IsValid) { var dbContextTransaction = db.Database.BeginTransaction(); try { aspNetAnnouncement.Date = DateTime.Now; db.AspNetAnnouncements.Add(aspNetAnnouncement); db.SaveChanges(); int announcementID = db.AspNetAnnouncements.Max(item => item.Id); List <int> SubjectIDs = new List <int>(); foreach (var item in selectedsubjects) { int subjectID = Convert.ToInt32(item); SubjectIDs.Add(subjectID); } foreach (var item in SubjectIDs) { AspNetAnnouncement_Subject ann_sub = new AspNetAnnouncement_Subject(); ann_sub.SubjectID = item; ann_sub.AnnouncementID = announcementID; db.AspNetAnnouncement_Subject.Add(ann_sub); db.SaveChanges(); } List <string> student = db.AspNetStudent_Subject.Where(x => SubjectIDs.Contains(x.SubjectID)).Select(s => s.StudentID).ToList(); foreach (var item in student) { AspNetStudent_Announcement stu_ann = new AspNetStudent_Announcement(); stu_ann.StudentID = item; stu_ann.AnnouncementID = announcementID; stu_ann.Seen = false; db.AspNetStudent_Announcement.Add(stu_ann); db.SaveChanges(); /////////////////////////////////////////////////////Push Notifications Module//////////////////////////////////////////////////////////// //var pushNotificationObj = new AspNetPushNotification(); //pushNotificationObj.Message = "New Announcement: " + aspNetAnnouncement.Title + ", Description: " + aspNetAnnouncement.Description; //pushNotificationObj.UserID = item; //pushNotificationObj.IsOpenParent = false; //pushNotificationObj.IsOpenStudent = false; //pushNotificationObj.Time = DateTime.Now; //db.AspNetPushNotifications.Add(pushNotificationObj); //db.SaveChanges(); } ////////////////////////////////////////////////NOTIFICATION/////////////////////////////////////////////////////////////////// var NotificationObj = new AspNetNotification(); NotificationObj.Description = aspNetAnnouncement.Description; NotificationObj.Subject = aspNetAnnouncement.Title; NotificationObj.SenderID = User.Identity.GetUserId(); NotificationObj.Time = DateTime.Now; NotificationObj.Url = "/AspNetAnnouncement/details/" + aspNetAnnouncement.Id; NotificationObj.SessionID = SessionID; db.AspNetNotifications.Add(NotificationObj); db.SaveChanges(); var NotificationID = db.AspNetNotifications.Max(x => x.Id); List <string> students = db.AspNetStudent_Subject.Where(x => SubjectIDs.Contains(x.SubjectID)).Select(s => s.StudentID).ToList(); var users = new List <String>(); foreach (var item in students) { var parentID = db.AspNetParent_Child.Where(x => x.ChildID == item).Select(x => x.ParentID).FirstOrDefault(); users.Add(parentID); } var allusers = users.Union(students); //Message start //var classe = db.AspNetClasses.Where(p => p.Id == aspNetHomework.ClassId).FirstOrDefault(); //Utility obj = new Utility(); //obj.SMSToOffitialsp("Dear Principal, Announcement has been made with Title: " + aspNetAnnouncement.Title + "- IPC NGS Preschool, Aziz Avenue, Lahore."); //obj.SMSToOffitialsa("Dear Admin, Announcement has been made with Title: " + aspNetAnnouncement.Title + "- IPC NGS Preschool, Aziz Avenue, Lahore."); //AspNetMessage oob = new AspNetMessage(); //oob.Message = "Dear Parents, Announcement has been made with Title: " + aspNetAnnouncement.Title + "For discription login to Portal please - IPC NGS Preschool, Aziz Avenue, Lahore."; //obj.SendSMS(oob, users); //Message end foreach (var receiver in allusers) { var notificationRecieve = new AspNetNotification_User(); notificationRecieve.NotificationID = NotificationID; notificationRecieve.UserID = Convert.ToString(receiver); notificationRecieve.Seen = false; db.AspNetNotification_User.Add(notificationRecieve); db.SaveChanges(); } dbContextTransaction.Commit(); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// var UserNameLog = User.Identity.Name; AspNetUser a = db.AspNetUsers.First(x => x.UserName == UserNameLog); string UserIDLog = a.Id; var classObjLog = Request.Form["ClassID"]; var logMessage = "A new Announcement Added, Topic: " + aspNetAnnouncement.Title + ", Description: " + aspNetAnnouncement.Description + ", ClassIDs: " + classObjLog; var LogControllerObj = new AspNetLogsController(); LogControllerObj.CreateLogSave(logMessage, UserIDLog); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } catch (Exception) { dbContextTransaction.Dispose(); } return(RedirectToAction("Teacher_Announcement", "Teacher_Dashboard")); } return(View(aspNetAnnouncement)); }
}// 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 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)); }
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 ActionResult Create(AspNetProject aspNetProject) { HttpPostedFileBase file = Request.Files["attachment"]; if (ModelState.IsValid) { if (file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Content/Projects"), fileName); file.SaveAs(path); aspNetProject.FileName = fileName; } else { aspNetProject.FileName = "-/-"; } if (db.AspNetProjects.Where(x => x.FileName == aspNetProject.FileName).Count() > 0) { TempData["Error"] = "Document already exists kindly change document name"; return(RedirectToAction("Create")); } else { db.AspNetProjects.Add(aspNetProject); db.SaveChanges(); } int ProjectID = db.AspNetProjects.Max(x => x.Id); List <string> StudentIDs = db.AspNetStudent_Subject.Where(s => s.SubjectID == aspNetProject.SubjectID).Select(s => s.StudentID).ToList(); foreach (var item in StudentIDs) { AspNetStudent_Project student_project = new AspNetStudent_Project(); student_project.StudentID = item; student_project.ProjectID = ProjectID; student_project.SubmissionStatus = false; student_project.SubmittedFileName = "-/-"; db.AspNetStudent_Project.Add(student_project); db.SaveChanges(); } /////////////////////////////////////////////////NOTIFICATION///////////////////////////////////// var NotificationObj = new AspNetNotification(); NotificationObj.Description = aspNetProject.Description; NotificationObj.Subject = aspNetProject.Title; NotificationObj.SenderID = User.Identity.GetUserId(); NotificationObj.Time = DateTime.Now; NotificationObj.Url = "/AspNetProject/Details/" + aspNetProject.Id; db.AspNetNotifications.Add(NotificationObj); db.SaveChanges(); var NotificationID = db.AspNetNotifications.Max(x => x.Id); var students = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.StudentID).ToList(); var users = new List <String>(); foreach (var item in students) { var parentID = db.AspNetParent_Child.Where(x => x.ChildID == item).Select(x => x.ParentID).FirstOrDefault(); users.Add(parentID); } var allusers = users.Union(students); foreach (var receiver in allusers) { var notificationRecieve = new AspNetNotification_User(); notificationRecieve.NotificationID = NotificationID; notificationRecieve.UserID = Convert.ToString(receiver); notificationRecieve.Seen = false; db.AspNetNotification_User.Add(notificationRecieve); db.SaveChanges(); } /////////////////////////////////////Email///////////////////////////////////////// var subject = db.AspNetSubjects.Where(x => x.Id == aspNetProject.SubjectID).Select(x => x.SubjectName).FirstOrDefault(); var StudentEmail = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.StudentID).ToList(); var StudentRoll = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.AspNetUser.UserName).ToList(); string[] studentRollList = new string[StudentRoll.Count]; int c = 0; foreach (var item in StudentRoll) { studentRollList[c] = item; c++; } var StudentName = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.AspNetUser.Name).ToList(); string[] studentNamelist = new string[StudentName.Count]; int i = 0; foreach (var item in StudentName) { studentNamelist[i] = item; i++; } var Users = new List <String>(); foreach (var item in StudentEmail) { Users.Add(db.AspNetParent_Child.Where(x => x.ChildID == item).Select(x => x.ParentID).FirstOrDefault()); } //Message start //var classe = db.AspNetClasses.Where(p => p.Id == aspNetHomework.ClassId).FirstOrDefault(); Utility obj = new Utility(); obj.SMSToOffitialsp("Dear Principal, Project has been assigned. IPC NGS Preschool, Aziz Avenue, Lahore."); obj.SMSToOffitialsa("Dear Admin, Project has been assigned. IPC NGS Preschool, Aziz Avenue, Lahore."); AspNetMessage oob = new AspNetMessage(); oob.Message = "Dear Parents, The thematic project has been assigned to your child on portal. IPC NGS Preschool, Aziz Avenue, Lahore.";// Title : " + aspNetProject.Title + ", For discription login to Portal please - obj.SendSMS(oob, Users); //Message end List <string> EmailList = new List <string>(); foreach (var sender in Users) { EmailList.Add(db.AspNetUsers.Where(x => x.Id == sender).Select(x => x.Email).FirstOrDefault()); } var j = 0; foreach (var toEmail in EmailList) { try { NotificationObj.Subject = studentNamelist[j] + "(" + studentRollList[j] + ") " + " Subject:" + subject + " Title:" + aspNetProject.Title; j++; string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString(); string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString(); SmtpClient client = new SmtpClient("smtpout.secureserver.net", 25); client.EnableSsl = false; client.Timeout = 100000; client.DeliveryMethod = SmtpDeliveryMethod.Network; client.UseDefaultCredentials = false; client.Credentials = new NetworkCredential(senderEmail, senderPassword); MailMessage mailMessage = new MailMessage(senderEmail, toEmail, NotificationObj.Subject, NotificationObj.Description); mailMessage.CC.Add(new MailAddress(senderEmail)); mailMessage.IsBodyHtml = true; mailMessage.BodyEncoding = UTF8Encoding.UTF8; client.Send(mailMessage); } catch (Exception ex) { } } return(RedirectToAction("Index")); } ViewBag.ClassID = new SelectList(db.AspNetClasses.Where(x => x.SessionID == SessionID), "Id", "ClassName"); ViewBag.SubjectID = new SelectList(db.AspNetSubjects.Where(x => x.AspNetClass.SessionID == SessionID), "Id", "SubjectName", aspNetProject.SubjectID); TempData["Create"] = "Project has been created"; return(View(aspNetProject)); }
public JsonResult AddDiary(Homework aspNetHomework) { AspNetHomework aspNetHomeworks = new AspNetHomework(); aspNetHomeworks.ClassId = aspNetHomework.ClassId; aspNetHomeworks.Date = Convert.ToDateTime(aspNetHomework.Date); aspNetHomeworks.PrincipalApproved_status = "Approved"; db.AspNetHomeworks.Add(aspNetHomeworks); db.SaveChanges(); var HomeWorkID = db.AspNetHomeworks.Max(x => x.Id); foreach (var subject in aspNetHomework.subject_Homework) { AspNetSubject_Homework aspNetSubject_Homework = new AspNetSubject_Homework(); aspNetSubject_Homework.HomeworkID = HomeWorkID; aspNetSubject_Homework.SubjectID = subject.SubjectID; aspNetSubject_Homework.HomeworkDetail = subject.HomeworkDetail; db.AspNetSubject_Homework.Add(aspNetSubject_Homework); db.SaveChanges(); } List <string> ParentList = new List <string>(); var StudentList = db.AspNetStudents.Where(x => x.ClassID == aspNetHomework.ClassId).Select(x => x.StudentID).ToList(); foreach (var student in StudentList) { AspNetStudent_HomeWork aspNetStudent_Homework = new AspNetStudent_HomeWork(); aspNetStudent_Homework.HomeworkID = HomeWorkID; aspNetStudent_Homework.Reading = aspNetHomework.Reading; aspNetStudent_Homework.TeacherComments = aspNetHomework.TeacherComment; aspNetStudent_Homework.Status = "Not Seen by Parents"; aspNetStudent_Homework.StudentID = student; aspNetStudent_Homework.ParentComments = ""; db.AspNetStudent_HomeWork.Add(aspNetStudent_Homework); db.SaveChanges(); //var parent = db.AspNetParent_Child.Where(p => p.ChildID == student).FirstOrDefault(); //if(parent != null) //{ // ParentList.Add(parent.ParentID); //} //else //{ // var mee = "This student id don't have parent " + student + " NGS Portal"; // Utility ob = new Utility(); // ob.messagetosupport(mee); //} } var classe = db.AspNetClasses.Where(p => p.Id == aspNetHomework.ClassId).FirstOrDefault(); Utility obj = new Utility(); obj.SMSToOffitialsp("Dear Principal, Homework for Class: " + classe.ClassName + " has been assigned. IPC Aziz Avenue Campus."); obj.SMSToOffitialsa("Dear Admin, Homework for Class: " + classe.ClassName + " has been assigned. IPC Aziz Avenue Campus."); //////////////////////////////////NOTIFICATION/////////////////////////////////// var NotificationObj = new AspNetNotification(); NotificationObj.Description = "Today's Diray is assigned"; NotificationObj.Subject = "Diary"; NotificationObj.SenderID = User.Identity.GetUserId(); NotificationObj.Time = DateTime.Now; NotificationObj.Url = "/AspNetHomework/Details/" + aspNetHomework.ClassId; NotificationObj.SessionID = SessionID; db.AspNetNotifications.Add(NotificationObj); db.SaveChanges(); var NotificationID = db.AspNetNotifications.Max(x => x.Id); var users = new List <String>(); foreach (var item in StudentList) { var parentID = db.AspNetParent_Child.Where(x => x.ChildID == item).Select(x => x.ParentID).FirstOrDefault(); users.Add(parentID); } var allusers = users.Union(StudentList); foreach (var receiver in allusers) { var notificationRecieve = new AspNetNotification_User(); notificationRecieve.NotificationID = NotificationID; notificationRecieve.UserID = Convert.ToString(receiver); notificationRecieve.Seen = false; db.AspNetNotification_User.Add(notificationRecieve); db.SaveChanges(); } //////////////////////////////////////////Email////////////////////////////////////////// var students = db.AspNetStudents.Where(x => x.ClassID == aspNetHomework.ClassId).Select(x => x).ToList(); string[] studentRollList = new string[students.Count]; int r = 0; foreach (var item in students) { studentRollList[r] = item.AspNetUser.UserName; r++; } //var StudentName = db.AspNetStudent_Project.Where(sp => sp.ProjectID == aspNetProject.Id).Select(x => x.AspNetUser.Name).ToList(); string[] studentNamelist = new string[students.Count]; int i = 0; foreach (var item in students) { studentNamelist[i] = item.AspNetUser.Name; i++; } var Users = new List <String>(); foreach (var item in StudentList) { Users.Add(db.AspNetParent_Child.Where(x => x.ChildID == item).Select(x => x.ParentID).FirstOrDefault()); } List <string> EmailList = new List <string>(); foreach (var sender in Users) { EmailList.Add(db.AspNetUsers.Where(x => x.Id == sender).Select(x => x.Email).FirstOrDefault()); } var j = 0; //foreach (var toEmail in EmailList) //{ // try // { // var Subject = studentNamelist[j] + "(" + studentRollList[j] + ") " + " Diary"; // j++; // string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString(); // string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString(); // SmtpClient client = new SmtpClient("smtpout.secureserver.net", 25); // client.EnableSsl = false; // client.Timeout = 100000; // client.DeliveryMethod = SmtpDeliveryMethod.Network; // client.UseDefaultCredentials = false; // client.Credentials = new NetworkCredential(senderEmail, senderPassword); // MailMessage mailMessage = new MailMessage(senderEmail, toEmail, Subject, NotificationObj.Description); // mailMessage.CC.Add(new MailAddress(senderEmail)); // mailMessage.IsBodyHtml = true; // mailMessage.BodyEncoding = UTF8Encoding.UTF8; // client.Send(mailMessage); // } // catch (Exception ex) // { // } //} return(Json("", JsonRequestBehavior.AllowGet)); }