public ActionResult Register()
        {
            //Only allow people to view register page if they have a valid link
            NameValueCollection query = Request.QueryString;

            string[] qresult = query.GetValues("rqst");
            if (qresult == null || qresult.Length < 1)
            {
                return(new HttpNotFoundResult());
            }

            UrlEncryption EncryptionResult = UrlEncryption.Decrypt(qresult[0]);

            if (EncryptionResult == null || EncryptionResult.timeStamp > DateTime.UtcNow.AddHours(3)) // if null or url was created more than 3 hours ago dont accept
            {
                return(new HttpNotFoundResult());
            }

            FM_Datastore_Entities_EF db_manager = new FM_Datastore_Entities_EF();
            Role     RoleResult     = db_manager.Roles.FirstOrDefault(m => m.Id == EncryptionResult.role);
            Address  AddressResult  = db_manager.Addresses.FirstOrDefault(m => m.Id == EncryptionResult.address);
            Division DivisionResult = db_manager.Divisions.FirstOrDefault(m => m.Id == EncryptionResult.division);

            db_manager.Dispose();

            // store ids in session
            Session.Add("RoleResult", RoleResult.Id);
            Session.Add("AddressResult", AddressResult.Id);
            Session.Add("DivisionResult", DivisionResult.Id);
            return(View(new RegisterViewModel()
            {
                Email = EncryptionResult.email,
                Role = RoleResult.Name,
                Address = AddressResult.country + ": "
                          + AddressResult.addressLine1
                          + AddressResult.addressLine2
                          + ", " + AddressResult.city
                          + ", " + AddressResult.state
                          + ", " + AddressResult.postalCode,
                Division = DivisionResult.name
            }));
        }
        public ActionResult Notify(NotifyViewModel model, string submitButton, string id, long?Role)
        {
            if (User.IsInRole(AppSettings.Roles.APPROVEDUSER) || User.IsInRole(AppSettings.Roles.AUDITORS))
            {
                return(new HttpNotFoundResult());
            }

            if (model.Role == null)
            {
                return(View(model)); // redisplay the view if error
            }

            long role = (long)model.Role;

            if (Role != null)
            {
                role = (long)Role;
            }

            model.notifyList = (List <Notification>)Session["notifyListDB"];
            model.Role       = (long)Session["roleResult"];
            model.Roles      = (List <SelectListItem>)Session["RolesList"];
            long result;

            if (!long.TryParse(id, out result))
            {
                return(View(model));
            }

            FM_Datastore_Entities_EF db_manager = new FM_Datastore_Entities_EF();

            // get notification
            Notification oldNotify = db_manager.Notifications.FirstOrDefault(m => m.Id == result);

            switch (submitButton)
            {
            case "Resend Notification":
                //send email to new user
                Mail.send(
                    oldNotify.Email,
                    "Access Approved",
                    "here is the link to sign up this link will only be available for so long - "
                    + "https://"
                    + HttpContext.Request.Url.Authority
                    + Url.Action("Register", "Account")
                    + "?rqst="
                    + UrlEncryption.Encrypt(
                        DateTime.UtcNow,
                        oldNotify.Email,
                        oldNotify.AddressId,
                        oldNotify.DivisionId,
                        role));
                ViewBagHelper.setMessage(ViewBag, ViewBagHelper.MessageType.SuccessMsgBox, "New user request resent to \"" + oldNotify.Email + "\"");
                return(NotifyView());

            case "Accept":
                if (oldNotify.notifyType.Equals(AppSettings.Notify.newUser))
                {
                    //send email to new user
                    Mail.send(
                        oldNotify.Email,
                        "Access Approved",
                        "here is the link to sign up this link will only be available for so long - "
                        + "https://"
                        + HttpContext.Request.Url.Authority
                        + Url.Action("Register", "Account")
                        + "?rqst="
                        + UrlEncryption.Encrypt(
                            DateTime.UtcNow,
                            oldNotify.Email,
                            oldNotify.AddressId,
                            oldNotify.DivisionId,
                            role));
                    oldNotify.notifyType = AppSettings.Notify.pendingUser;
                    oldNotify.Role       = db_manager.Roles.FirstOrDefault(m => m.Id == role).Name;
                    db_manager.Entry(oldNotify);
                    db_manager.SaveChanges();
                    db_manager.Dispose();
                }
                return(NotifyView());

            case "Deny":
                // send denial email to user
                Mail.send(oldNotify.Email, "Denied Access", "Appologies user you have been denied access by administration to the application.");

                model.notifyList.Remove(model.notifyList.First(m => m.Id == result));     // remove from current model
                db_manager.Notifications.Remove(oldNotify);
                break;

            default:
                break;
            }

            db_manager.SaveChanges();
            db_manager.Dispose();
            return(View(model));
        }