public ActionResult RequestResource(RequestResourceModel model)
        {
            if (ModelState.IsValid && Request.IsAjaxRequest())
            {
                // Identify User
                MembershipUser currentUser = Membership.GetUser();
                try
                {
                    // Find Resource
                    Resource request = (from r in repository.Resources
                                               where r.ResourceId == model.ResourceId
                                               select r).FirstOrDefault();

                    // Build Message
                    StringBuilder mBody = new StringBuilder();
                    mBody.AppendLine("Description: NovoPayerLink - New Resource Request from " + HttpContext.Profile["FirstName"] + " " + HttpContext.Profile["LastName"]);
                    mBody.AppendLine("-- Message Details --");
                    mBody.AppendLine("First Name:      " + HttpContext.Profile["FirstName"]);
                    mBody.AppendLine("Last Name:       " + HttpContext.Profile["LastName"]);
                    mBody.AppendLine("Order Resource:  " + model.OrderResource);
                    mBody.AppendLine("Request Meeting: " + model.RequestMeeting);
                    mBody.AppendLine("Use Email:       " + model.UseEmail);
                    mBody.AppendLine("Email:           " + model.Email);
                    mBody.AppendLine("Use Phone        " + model.UsePhone);
                    mBody.AppendLine("Phone:           " + model.Phone);
                    mBody.AppendLine("Contact Time:    " + model.ContactTime);
                    mBody.AppendLine("Requested On:    " + DateTime.Now.ToShortDateString());
                    mBody.AppendLine("-- Resource Details --");
                    mBody.AppendLine("Category:        " + request.Category);
                    mBody.AppendLine("Title:           " + request.Title);
                    mBody.AppendLine("Description:     " + request.Description);

                    // Email resource request to the administrators
                    EmailMessage message = new EmailMessage
                    {
                        MailToAddress = SystemSettings.EmailNotificationsTo,
                        MailFromAddress = SystemSettings.EmailNotificationsFrom,
                        MessageSubject = "NovoPayerLink - New Resource Request from " + HttpContext.Profile["FirstName"] + " " + HttpContext.Profile["LastName"],
                        MessageBody = mBody.ToString()
                    };

                    SendMail sendMail = new SendMail(message);
                    sendMail.Send();

                    model.Error = "";
                }
                catch
                {
                    model.Error = "The information you entered is incorrect. Please try again.";
                }

                return Json(model, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return View();
            }
        }
        public ActionResult RequestAccess(RequestAccessModel model)
        {
            if (ModelState.IsValid && Request.IsAjaxRequest())
            {
                try
                {
                    StringBuilder mBody = new StringBuilder();
                    mBody.AppendLine("Description: NovoPayerLink - New User Access Request for " + model.FirstName + " " + model.LastName);
                    mBody.AppendLine("-- User Details --");
                    mBody.AppendLine("First Name:   " + model.FirstName);
                    mBody.AppendLine("Last Name:    " + model.LastName);
                    mBody.AppendLine("Email:        " + model.Email);
                    mBody.AppendLine("Phone:        " + model.Phone);
                    mBody.AppendLine("Organization: " + model.Organization);
                    mBody.AppendLine("Requested On: " + DateTime.Now.ToShortDateString());
                    // Email user access request to the administrators
                    EmailMessage message = new EmailMessage
                    {
                        MailToAddress = SystemSettings.EmailNotificationsTo,
                        MailFromAddress = SystemSettings.EmailNotificationsFrom,
                        MessageSubject = "NovoPayerLink: New User Access Request for " + model.FirstName + " " + model.LastName,
                        MessageBody = mBody.ToString()
                    };

                    SendMail sendMail = new SendMail(message);
                    sendMail.Send();

                    model.Error = "";
                }
                catch
                {
                    model.Error = "The information you entered is incorrect. Please try again.";
                }
                return Json(model, JsonRequestBehavior.AllowGet);
            }
            else
            {
                // redisplay form
                return View();
            }
        }
        public ActionResult RequestTemporaryPassword(RequestTemporaryPasswordModel model)
        {
            if (ModelState.IsValid && Request.IsAjaxRequest())
            {
                string userName = Membership.GetUserNameByEmail(model.Email);
                // Verify that user is valid
                if (userName != null)
                {
                    try
                    {
                        // Step 1: If user exists Reset their Password
                        MembershipUser currentUser = Membership.GetUser(userName);
                        model.TemporaryPassword = currentUser.ResetPassword();
                        // Step 2: Temporarily Disable the User
                        currentUser.ChangePasswordQuestionAndAnswer(model.TemporaryPassword, model.TemporaryPassword, model.TemporaryPassword);
                        // Step 3: Email user their newly generated password
                        EmailMessage message = new EmailMessage
                        {
                            MailToAddress = model.Email,
                            MailFromAddress = SystemSettings.EmailNotificationsFrom,
                            MessageSubject = "NovoPayerLink: New Temporary Password",
                            MessageBody = model.TemporaryPassword
                        };

                        SendMail sendMail = new SendMail(message);
                        sendMail.Send();

                        model.Error = "";
                        model.ChangePassword = "******";
                    }
                    catch
                    {
                        model.Error = "We do not have this email address on file. Please enter a valid email.";
                        model.ChangePassword = "******";
                    }
                }
                else
                {
                    model.Error = "We do not have this email address on file. Please enter a valid email.";
                    model.ChangePassword = "******";
                }
                return Json(model, JsonRequestBehavior.AllowGet);
            }
            else
            {
                // redisplay form
                return View();
            }
        }
Beispiel #4
0
 public SendMail(EmailMessage message)
 {
     emailMessage = message;
 }