public ActionResult Support(User user, FormCollection form)
        {
            if (Session["UserId"] == null)
            {
                return(Redirect("/admin"));
            }

            Utility.Utilities utilities = new Utility.Utilities();

            //string UserId = Session["UserId"].ToString();

            string msg = form["txtmessage"];

            //send email link
            var success = utilities.SendSupportEmail(System.Configuration.ConfigurationManager.AppSettings["supportemail"], user.Email, user.FullName, user.UserName, msg);

            success = utilities.SendSupportUserEmail(System.Configuration.ConfigurationManager.AppSettings["supportemail"], user.Email, user.FullName, user.UserName, msg);

            if (success)
            {
                ViewBag.IsSuccess = true;
            }

            return(View(user));
        }
        public ActionResult ChangePassword(FormCollection form)
        {
            Utility.Utilities utilities = new Utility.Utilities();

            ViewBag.IsSuccess = null;

            var newpassword = form["New password"].ToString();

            var userid = int.Parse(Session["UserId"].ToString());
            var user   = _context.Users.SingleOrDefault(x => x.UserId == userid);
            var error_ = false;

            if (newpassword != Request["ConfirmPassword"].ToString())
            {
                ViewBag.ErrorMessage += "Password and Confirm Password did not match!<br/>"; error_ = true;
            }
            if (newpassword.Length < 8)
            {
                ViewBag.ErrorMessage += "Minimum of 8 characters is required!<br/>"; error_ = true;
            }
            if (!newpassword.Any(char.IsUpper))
            {
                ViewBag.ErrorMessage += "Password must have at least 1 uppercase!<br/>"; error_ = true;
            }
            if (!newpassword.Any(char.IsLower))
            {
                ViewBag.ErrorMessage += "Password must have at least 1 lowercase!<br/>"; error_ = true;
            }
            if (!newpassword.Any(ch => !Char.IsLetterOrDigit(ch)))
            {
                ViewBag.ErrorMessage += "Password must have at least 1 special character!<br/>"; error_ = true;
            }
            if (!newpassword.Any(char.IsNumber))
            {
                ViewBag.ErrorMessage += "Password must have at least 1 numeric character!<br/>"; error_ = true;
            }
            if (!error_)
            {
                ViewBag.IsFirstLog    = Session["IsFirstLog"];
                Session["IsFirstLog"] = "false";

                user.Password = util.Encrypt(newpassword, EncryptionKey);

                user.IsFirstLog            = false;
                _context.Entry(user).State = EntityState.Modified;
                _context.SaveChanges();

                ViewBag.IsSuccess = "Success";

                //send email link
                var success = utilities.SendChangePasswordEmail(System.Configuration.ConfigurationManager.AppSettings["supportemail"], user.Email, user.UserName);
            }

            return(View("../ChangePassword"));
        }
        public ActionResult ForgotPassword(FormCollection form)
        {
            Utility.Utilities utilities = new Utility.Utilities();

            ViewBag.IsSuccess    = null;
            ViewBag.ErrorMessage = null;

            //get new guid
            Guid guid = Guid.NewGuid();

            var username_parameter = form["txtusername"].ToString();

            var user = _context.Users.Include(x => x.Role).SingleOrDefault(x => x.UserName == username_parameter || x.Email == username_parameter);

            //var error_ = false;

            if (user != null)
            {
                //if (user.Password != Request["ConfirmPassword"])
                //{
                //    ViewBag.ErrorMessage += "Password and Confirm Password did not match!"; error_ = true;
                //}
                //if (!error_)
                //{
                //add new forgotpassword token
                var forgotpassword = new ForgotPasswordToken
                {
                    Unique_Guid = guid.ToString(),
                    Email       = user.Email,
                    CreatedDate = System.DateTime.Now
                };
                _context.ForgotPasswordTokens.Add(forgotpassword);
                _context.SaveChanges();

                //send email link
                var success = utilities.SendForgotPasswordEmail(guid.ToString(), System.Configuration.ConfigurationManager.AppSettings["supportemail"], user.Email, user.UserName);

                ViewBag.IsSuccess = "Success";
                //}
            }
            else
            {
                ViewBag.ErrorMessage = "User not found.";
            }

            return(View("../ForgotPassword"));
        }
        public ActionResult Approve(FormCollection form)
        {
            ViewBag.IsView       = null;
            ViewBag.ErrorMessage = null;

            Utility.Utilities utilities = new Utility.Utilities();

            //email variable
            var TransactionID = string.Empty;
            var FromCSNValue  = string.Empty;
            var ToCSNValue    = string.Empty;
            var ISINValue     = string.Empty;
            var AmountValue   = string.Empty;
            var Timestamp     = System.DateTime.Now.ToShortDateString();
            var FormName      = string.Empty;
            var UserName      = Session["UserName"].ToString();
            var FullName      = Session["UserFullName"].ToString();
            var ApprovalEmail = Session["UserEmail"].ToString();
            var fromEmail     = System.Configuration.ConfigurationManager.AppSettings["supportemail"];

            var id             = int.Parse(form["Id"]);
            var source         = form["Source"];
            var csnsource      = "";
            var sourceval      = "";
            var csndestination = "";
            var destinationval = "";
            var destination    = form["To"];

            var submitUserEmail    = string.Empty;
            var computershareEmail = string.Empty;

            if (UserName != form["SubmittedBy"].ToString())
            {
                switch (source)
                {
                case "DRP":
                    var drp = _context.DRPs.Include(a => a.User).Include(a => a.ReviewedUser).Include(a => a.CreatedByUser)
                              .SingleOrDefault(x => x.DRPId == id);

                    var drp_val = _context.CSNLookUps.SingleOrDefault(a => a.CSNName == drp.CSN);
                    sourceval = drp_val.CSNAccount;
                    csnsource = drp.CSN;


                    drp.ReviewedById = int.Parse(Session["UserId"].ToString());
                    drp.ReviewedDate = System.DateTime.Now;

                    _context.Entry(drp).State = EntityState.Modified;
                    _context.SaveChanges();

                    //email variables
                    FormName           = source;
                    TransactionID      = FormName + "-" + drp.DRPId.ToString();
                    FromCSNValue       = drp.CSN;
                    ISINValue          = drp.ISIN;
                    AmountValue        = drp.DRPAmount.ToString();
                    computershareEmail = System.Configuration.ConfigurationManager.AppSettings["DRPEmailRecipients"];     // "*****@*****.**";
                    submitUserEmail    = drp.CreatedByUser.Email;

                    break;

                case "AIL":
                    var ail = _context.AILs.Include(a => a.User).Include(a => a.ReviewedUser).Include(a => a.CreatedByUser)
                              .SingleOrDefault(x => x.AILId == id);

                    var ail_val = _context.CSNLookUps.SingleOrDefault(a => a.CSNName == ail.FromCSN);
                    sourceval = ail_val.CSNAccount;
                    csnsource = ail.FromCSN;

                    ail_val        = _context.CSNLookUps.SingleOrDefault(a => a.CSNName == ail.ToCSN);
                    destinationval = ail_val.CSNAccount;
                    csndestination = ail.ToCSN;

                    ail.ReviewedById = int.Parse(Session["UserId"].ToString());
                    ail.ReviewedDate = System.DateTime.Now;

                    _context.Entry(ail).State = EntityState.Modified;
                    _context.SaveChanges();

                    //email variables
                    FormName           = source;
                    TransactionID      = FormName + "-" + ail.AILId.ToString();
                    FromCSNValue       = ail.FromCSN;
                    ToCSNValue         = ail.ToCSN;
                    ISINValue          = ail.ISIN;
                    AmountValue        = ail.TransferAmount.ToString();
                    fromEmail          = System.Configuration.ConfigurationManager.AppSettings["supportemail"];
                    computershareEmail = System.Configuration.ConfigurationManager.AppSettings["AILEmailRecipients"];     // "*****@*****.**";
                    submitUserEmail    = ail.CreatedByUser.Email;

                    break;

                case "Supplementary Dividend":
                    var sP = _context.SupplementaryDividends.Include(a => a.User).Include(a => a.ReviewedUser).Include(a => a.CreatedByUser)
                             .SingleOrDefault(x => x.SDId == id);

                    var sp_val = _context.CSNLookUps.SingleOrDefault(a => a.CSNName == sP.FromCSN);
                    sourceval = sp_val.CSNAccount;
                    csnsource = sP.FromCSN;

                    sp_val         = _context.CSNLookUps.SingleOrDefault(a => a.CSNName == sP.ToCSN);
                    destinationval = sp_val.CSNAccount;
                    csndestination = sP.ToCSN;

                    //csnsource = sP.ToCSN;
                    sP.ReviewedById = int.Parse(Session["UserId"].ToString());
                    sP.ReviewedDate = System.DateTime.Now;

                    _context.Entry(sP).State = EntityState.Modified;
                    _context.SaveChanges();

                    //email variables
                    FormName           = source;
                    TransactionID      = FormName + "-" + sP.CreatedById.ToString();
                    FromCSNValue       = sP.FromCSN;
                    ToCSNValue         = sP.ToCSN;
                    ISINValue          = sP.ISIN;
                    AmountValue        = sP.TransferAmount.ToString();
                    computershareEmail = System.Configuration.ConfigurationManager.AppSettings["SPDEmailRecipients"];     //"*****@*****.**";
                    submitUserEmail    = sP.CreatedByUser.Email;

                    break;
                }

                ViewBag.IsView = "Approve";

                //Email
                var success = utilities.SendFormEmails(TransactionID,
                                                       FromCSNValue, ToCSNValue,
                                                       ISINValue,
                                                       AmountValue,
                                                       Timestamp,
                                                       FullName, UserName,
                                                       FormName,
                                                       fromEmail,
                                                       ApprovalEmail,
                                                       computershareEmail,
                                                       submitUserEmail,
                                                       csnsource,
                                                       csndestination,
                                                       sourceval,
                                                       destinationval);
            }
            else
            {
                var review = new ReviewModel();
                ViewBag.NotAllowed = true;
                review             = GetApproveData(review, source, int.Parse(id.ToString()));

                ViewBag.ErrorMessage = @"You are not able to review your own submission. Please request another user to approve this request.";

                return(View(review));
            }

            return(View());

            //return Redirect("/ra/review");
        }
        public ActionResult ForgotPasswordChange(FormCollection form)
        {
            Utility.Utilities utilities = new Utility.Utilities();

            ViewBag.IsSuccess = null;
            var email = form["email"];

            ViewBag.Email = email;
            var newpassword = form["New Password"];

            var user   = _context.Users.SingleOrDefault(x => x.Email == email);
            var error_ = false;

            if (user != null)
            {
                if (newpassword != Request["ConfirmPassword"].ToString())
                {
                    ViewBag.ErrorMessage += "Password and Confirm Password did not match.<br/>"; error_ = true;
                }
                if (newpassword.Length < 8)
                {
                    ViewBag.ErrorMessage += "Minimum of 8 characters is required.<br/>"; error_ = true;
                }
                if (!newpassword.Any(char.IsUpper))
                {
                    ViewBag.ErrorMessage += "Password must have at least 1 uppercase.<br/>"; error_ = true;
                }
                if (!newpassword.Any(char.IsLower))
                {
                    ViewBag.ErrorMessage += "Password must have at least 1 lowercase.<br/>"; error_ = true;
                }
                if (!newpassword.Any(ch => !Char.IsLetterOrDigit(ch)))
                {
                    ViewBag.ErrorMessage += "Password must have at least 1 special character.<br/>"; error_ = true;
                }
                if (!newpassword.Any(char.IsNumber))
                {
                    ViewBag.ErrorMessage += "Password must have at least 1 numeric character!<br/>"; error_ = true;
                }
                if (!error_)
                {
                    //update password
                    user.Password = util.Encrypt(newpassword, EncryptionKey);

                    _context.Entry(user).State = EntityState.Modified;
                    _context.SaveChanges();

                    //delete all token of user forgot password
                    var forgotpasswordtoken = _context.ForgotPasswordTokens.Where(x => x.Email == email).ToList();
                    if (forgotpasswordtoken.Any())
                    {
                        _context.ForgotPasswordTokens.RemoveRange(forgotpasswordtoken);
                        _context.SaveChanges();
                    }

                    ViewBag.IsSuccess = "Success";
                }
            }

            return(View("../ForgotPasswordChange"));
        }