Exemplo n.º 1
0
        public ActionResult SendGuardianRegistrationEmail(int id, int StudentId, string EmailAddress)
        {
            Student   student   = null;
            ClassRoom classRoom = null;
            School    school    = null;

            try
            {
                classRoom = db.ClassRooms.Find(id);
                student   = db.Students.Find(StudentId);
                school    = db.Schools.Where(s => s.SchoolID == classRoom.SchoolID).FirstOrDefault();
                if (school == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Data Integrity Error. Classroom not assigned to existing school"));
                }

                EmailMessage email = new EmailMessage()
                {
                    ToAddress    = EmailAddress,
                    EmailSubject = school.SchoolName + " Online Permission Slip Registration"
                };
                email.HtmlMessageText = "<a href=\"" + Url.Action("AddStudent", "Manage", new { id = student.ID }, protocol: Request.Url.Scheme) + "\">Click Here to add your student to your profile</a>" +
                                        "<br>" +
                                        "If you haven't registered, you can <a href=\"" + Url.Action("Register", "Account", null, protocol: Request.Url.Scheme) + "\">Click Here to Register</a> first" +
                                        "<p>" +
                                        "Online Permission Slips allows better communication and transparency regarding events for your students' class, " + classRoom.GetClassName() +
                                        "<br />" +
                                        "<br />" +
                                        "<U>You will need to provide the following for verification:</U><br />" +
                                        "<ul>" +
                                        "<li><b>You students ID Number: " + student.StudentNumber.ToString() + "</b></li>" +
                                        "<li><b>Your Student's Full Name: " + student.FullName + "</b></li>" +
                                        "</ul>" +
                                        "</p>" +
                                        "<p>" +
                                        "Online Permission Slips will always protect your student's information, as well as yours, ensuring privacy and limited access to the information." +
                                        "<br>" +
                                        "Only the school and you will be able to access your student's permission slips and related information." +
                                        "</p>";
                email.MessageText = "Click the following link to add your student to your profile" + Environment.NewLine +
                                    "Click to Add: " + Url.Action("AddStudent", "Manage", new { id = student.ID }, protocol: Request.Url.Scheme) + Environment.NewLine + Environment.NewLine +
                                    "If you haven't registered, you can Click Here to Register first:" + Url.Action("Register", "Account", null, protocol: Request.Url.Scheme) + Environment.NewLine + Environment.NewLine +
                                    "Online Permission Slips allows better communication and transparency regarding events for your students' class, " + classRoom.GetClassName() + Environment.NewLine +
                                    Environment.NewLine +
                                    "You will need to provide the following for verification:" + Environment.NewLine +
                                    "You students ID Number: " + student.StudentNumber.ToString() + Environment.NewLine +
                                    "Your Student's Full Name: " + student.FullName + Environment.NewLine +
                                    Environment.NewLine +
                                    "Online Permission Slips will always protect your student's information, as well as yours, ensuring privacy and limited access to the information." + Environment.NewLine +
                                    "Only the school and you will be able to access your student's permission slips and related information.";

                MailGunUtility.SendSimpleMessage(email);
            }
            catch (Exception ex)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Exception Emailing Guardians :: " + ex.ToString()));
            }
            //TODO :: Add Indication that messages were sent??
            return(RedirectToAction("Details", "ClassRooms", new { id, message = ClassRoomMessageId.EmailsSent }));
        }
 public ActionResult Index(PTOEmail email)
 {
     try
     {
         MailGunUtility.SendSimpleMessage(email);
         return(RedirectToAction("EmailSent"));
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("", "Error Sending Email:: " + ex.Message);
         return(View(email));
     }
 }
Exemplo n.º 3
0
        public Task SendAsync(IdentityMessage message)
        {
            // Plug in your email service here to send an email.
            EmailMessage email = new EmailMessage();

            email.EmailSubject    = message.Subject;
            email.HtmlMessageText = message.Body.Replace(Environment.NewLine, "<br />");
            email.MessageText     = message.Body;
            email.ToAddress       = message.Destination;
            MailGunUtility.SendSimpleMessage(email);

            return(Task.FromResult(0));
        }
        public ActionResult Create([Bind(Include = "ClassRoomID,PermissionSlipCategoryID,PermissionSlipTemplateID,Name,Location,StartDateTime,EndDateTime,Cost,RequireChaperone,RequireChaperoneBackgroundCheck,EmailGuardians")] CreatePermissionSlip createPermissionSlip)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    PermissionSlip p = new PermissionSlip()
                    {
                        PermissionSlipCategoryID = createPermissionSlip.PermissionSlipCategoryID,
                        PermissionSlipTemplateID = createPermissionSlip.PermissionSlipTemplateID,
                        ClassRoomID      = createPermissionSlip.ClassRoomID,
                        Name             = createPermissionSlip.Name,
                        Location         = createPermissionSlip.Location,
                        StartDateTime    = createPermissionSlip.StartDateTime,
                        EndDateTime      = createPermissionSlip.EndDateTime,
                        Cost             = createPermissionSlip.Cost,
                        RequireChaperone = createPermissionSlip.RequireChaperone,
                        RequireChaperoneBackgroundCheck = createPermissionSlip.RequireChaperoneBackgroundCheck
                    };

                    db.PermissionSlips.Add(p);
                    db.SaveChanges();
                    db.Entry(p).Reload();                     // Make sure the ID is populated
                    if (createPermissionSlip.EmailGuardians)
                    {
                        List <Student> students = db.ClassRooms.Where(c => c.ID == createPermissionSlip.ClassRoomID).SelectMany(c => c.Students).ToList();
                        foreach (Student s in students)
                        {
                            foreach (AspNetUser g in s.Guardians)
                            {
                                if (g.EmailConfirmed)
                                {
                                    string EmailMessage = "Permission Slip Created for your student's class. " +
                                                          Url.Action("PermissionSlipApproval", "PermissionSlips", new RouteValueDictionary(new { PermissionSlipID = p.ID, StudentID = s.ID }), protocol: Request.Url.Scheme);
                                    //for each guardian of class, send email
                                    MailGunUtility.SendSimpleMessage(new EmailMessage()
                                    {
                                        EmailSubject    = "Class Room Permission Slip",
                                        ToAddress       = g.Email,
                                        MessageText     = EmailMessage,
                                        HtmlMessageText = EmailMessage
                                    });
                                }
                            }
                        }
                        ////for each guardian of class, send email
                        //MailGunUtility.SendSimpleMessage(new EmailMessage()
                        //{
                        //	MessageText = "Permission Slip Created for your student's class"
                        //});
                    }

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

            InitializeViewBagsForCreate();
            return(View(createPermissionSlip));
        }