public ActionResult DeleteConfirmed(int id)
        {
            AspNetStudent_HomeWork aspNetStudent_HomeWork = db.AspNetStudent_HomeWork.Find(id);

            db.AspNetStudent_HomeWork.Remove(aspNetStudent_HomeWork);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,StudentID,HomeworkID,Reading,TeacherComments,ParentComments,Status")] AspNetStudent_HomeWork aspNetStudent_HomeWork)
 {
     if (ModelState.IsValid)
     {
         db.Entry(aspNetStudent_HomeWork).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", new { HomeWorkId = aspNetStudent_HomeWork.HomeworkID }));
     }
     ViewBag.HomeworkID = new SelectList(db.AspNetHomeworks, "Id", "Id", aspNetStudent_HomeWork.HomeworkID);
     ViewBag.StudentID  = new SelectList(db.AspNetUsers, "Id", "Email", aspNetStudent_HomeWork.StudentID);
     return(View(aspNetStudent_HomeWork));
 }
        // GET: AspNetStudent_HomeWork/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AspNetStudent_HomeWork aspNetStudent_HomeWork = db.AspNetStudent_HomeWork.Find(id);

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

            if (aspNetStudent_HomeWork == null)
            {
                return(HttpNotFound());
            }
            ViewBag.HomeworkID = new SelectList(db.AspNetHomeworks, "Id", "Id", aspNetStudent_HomeWork.HomeworkID);
            ViewBag.StudentID  = new SelectList(db.AspNetUsers, "Id", "Email", aspNetStudent_HomeWork.StudentID);

            return(View(aspNetStudent_HomeWork));
        }
Example #5
0
        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));
        }