示例#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));
     }
 }
示例#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));
        }
示例#4
0
        public ActionResult ResubscribeConfirmed()
        {
            string          userId             = "";
            ApplicationUser user               = null;
            bool            UnsubscribeDeleted = false;

            try
            {
                userId = User.Identity.GetUserId();
                user   = UserManager.FindById(userId);

                UnsubscribeDeleted = MailGunUtility.DeleteUnsubscribed(user.Email);
            }
            catch (Exception) { }             //Throw it away as it will just redirect to Index

            return(RedirectToAction("Index"));
        }
        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));
        }
示例#6
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ApplicationUser     user         = null;
            List <IdentityRole> userRoles    = null;
            List <School>       UserSchools  = null;
            List <Student>      UserStudents = null;
            List <ClassRoom>    UserClasses  = null;
            IndexViewModel      model        = null;
            string userId = "";

            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                                        : message == ManageMessageId.EmailConfirmationSent ? "Email Confirmation Sent. Please check your email to confirm change"
                                        : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                                        : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                                        : message == ManageMessageId.Error ? "An error has occurred."
                                        : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                                        : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                                        : message == ManageMessageId.AddStudentSuccess ? "Student was successfully added"
                                        : message == ManageMessageId.RemoveStudentSuccess ? "Student was successfully removed"
                                        : message == ManageMessageId.AddClassSuccess ? "Class was successfully added"
                                        : message == ManageMessageId.RemoveClassSuccess ? "Class was successfully removed"
                                        : message == ManageMessageId.RemoveClassSuccess ? "Class was successfully removed"
                                        : "";

            userId = User.Identity.GetUserId();
            user   = UserManager.FindById(userId);

            userRoles = null;
            userRoles = RoleManager.Roles.Where(r => r.Users.Any(ru => ru.UserId == userId)).ToList();

            if (User.IsInRole("Guardian"))
            {
                UserStudents = EntityDB.Students.Where(s => s.Guardians.Any(g => g.Id == userId)).ToList();
                UserSchools  = UserStudents.Select(us => us.School).Distinct().ToList();
                UserClasses  = new List <ClassRoom>();
            }
            else if (User.IsInRole("Teacher"))
            {
                UserClasses  = EntityDB.ClassRooms.Where(c => c.TeacherUserID == userId).ToList();
                UserStudents = new List <Student>();
                UserSchools  = UserClasses.Select(uc => uc.School).Distinct().ToList();
            }
            else if (User.IsInRole("School Admin"))
            {
                AspNetUser aspNetUser = EntityDB.AspNetUsers.Where(a => a.Id == userId).FirstOrDefault();
                if (aspNetUser == null)
                {
                    throw new Exception("Unable to locate user account by ID");
                }
                UserSchools  = aspNetUser.Schools.ToList();
                UserStudents = new List <Student>();
                UserClasses  = new List <ClassRoom>();
            }
            else if (User.IsInRole("System Admin"))
            {
                UserSchools  = new List <School>();
                UserStudents = new List <Student>();
                UserClasses  = new List <ClassRoom>();
            }
            else
            {
                throw new Exception("User Security Misconfigured");
            }

            model = new IndexViewModel
            {
                EmailConfirmed    = user.EmailConfirmed,
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId),
                IsSubscribed      = MailGunUtility.IsSubscribed(user.Email),
                Email             = user.Email,
                FirstName         = user.FirstName,
                LastName          = user.LastName,
                MiddleName        = user.MiddleName,
                Schools           = UserSchools,
                Students          = UserStudents,
                Classes           = UserClasses,
                Roles             = userRoles
            };

            return(View(model));
        }