public ActionResult ChangePassword()
        {
            Session["PageName"] = "ChangePassword";
               // string Login = "******";

            if (Session["GBAdminBizContext"] == null)
            {
              //  Response.Redirect(Login + "?Page=" + Server.UrlEncode(BizUtil.GetPageName(Request.RawUrl, true)));
                return  RedirectToAction("LogOn", "Account");
            }
            //string user = Convert.ToString(Session["username"]);
            //string Pass = Convert.ToString(Session["password"]);

            //if (user == "" && Pass == "")
            //{
            //   return  RedirectToAction("LogOn", "Account");
            //}
            else
            {
                try
                {
                    List<ChangePasswordExt> list = new List<ChangePasswordExt>();
                    ChangePasswordRepository obj = new ChangePasswordRepository();
                    list = obj.GetCode();
                    ViewBag.Valid = list;
                    //SecurityUtils.SetGlobalViewbags(this, ActiveMenu);
                    AssignBizContext();
                    SecurityUtils.SetGlobalViewbags(this, ActiveMenu, BizContext.UserContext.IsAdmin(), BizContext.UserContext.IsHotelAdmin(), BizContext.HotelID);
                }
                catch (Exception ex)
                {
                    string hostName1 = Dns.GetHostName();
                    string GetUserIPAddress = Dns.GetHostByName(hostName1).AddressList[0].ToString();
                    string PageName = Convert.ToString(Session["PageName"]);
                    //string GetUserIPAddress = GetUserIPAddress1();
                    using (BaseRepository baseRepo = new BaseRepository())
                    {
                        //BizContext BizContext1 = new BizContext();
                        BizApplication.AddError(baseRepo.BizDB, PageName, ex.Message, ex.StackTrace, DateTime.Now, GetUserIPAddress);
                    }
                    Session["PageName"] = "";
                    string error = ErrorHandling.HandleException(ex);
                    return this.Json(new DataSourceResult { Errors = error });
                }

                return View();
            }
        }
        public JsonResult Mail(string CultureCode, string username)
        {
            string Username = "";
            string Email = "";
            string mailTemplateID = "";
            string mailFrom = "";
            string mailSubject = "";
            string mailBody = "";
            string status = "";

            List<ChangePasswordExt> objList = new List<ChangePasswordExt>();
            DataTable MailTemplate = new DataTable();
            DataTable dt = new DataTable();
            ChangePasswordRepository homemail = new ChangePasswordRepository();

            MailTemplate = homemail.GetMailTemplates("SendRemindPasswordEmail", CultureCode);

            List<ChangePasswordExt> values = homemail.GetUserDetails(this, Username, mailFrom, status);

            foreach (var items in values)
            {
                Username = items.Username;
                Email = items.EmailID;
            }

            if (MailTemplate != null)
            {
                if (MailTemplate.Rows.Count > 0)
                {
                    foreach (DataRow dr in MailTemplate.Rows)
                    {
                        mailTemplateID = dr["ID"].ToString();
                        mailFrom = dr["MailFrom"].ToString();
                        mailSubject = dr["MailSubject"].ToString();
                        mailBody = dr["MailBody"].ToString();
                        mailBody = mailBody.Replace("#UserFullName#", Username);
                        System.Net.Mail.MailAddress from = new MailAddress(SMTP_TempEmailTo, SMTP_SenderName);
                        System.Net.Mail.MailAddress to = new MailAddress(username);
                        System.Net.Mail.MailMessage m = new MailMessage(from, to);
                        m.IsBodyHtml = true;
                        m.Subject = mailSubject;
                        m.Priority = System.Net.Mail.MailPriority.High;
                        SmtpClient smtp = new SmtpClient(Smtp_Mail, Smtp_PortNo);
                        smtp.UseDefaultCredentials = false;
                        // smtp.EnableSsl = true;
                        // m.Body = sb.ToString();
                        m.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
                        System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString
                        (System.Text.RegularExpressions.Regex.Replace(mailBody, @"<(.|\n)*?>", string.Empty), null, "text/plain");
                        System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailBody, null, "text/html");
                        m.AlternateViews.Add(plainView);
                        m.AlternateViews.Add(htmlView);
                        smtp.Credentials = new NetworkCredential(Smtp_Username, Smtp_Password);

                        try
                        {
                            smtp.Send(m);
                            status = "Success";
                        }
                        catch
                        {
                            status = "Failure";
                        }
                    }
                }

            }

            return Json(status, JsonRequestBehavior.AllowGet);
        }
        public JsonResult Mail(string Culturecode, string Email, string Username)
        {
            //string Username = "";
            //string Email = "";
            string mailTemplateID = "";
            string mailFrom = "";
            string mailSubject = "";
            string mailBody = "";
            string status = "";

            List<ChangePasswordExt> objList = new List<ChangePasswordExt>();
            DataTable MailTemplate = new DataTable();
            DataTable dt = new DataTable();
            ChangePasswordRepository homemail = new ChangePasswordRepository();

            MailTemplate = homemail.GetMailTemplates("SendUserPasswordChangedEmail", Culturecode);

            // List<ChangePasswordExt> values = homemail.GetUser(this, Username, mailFrom, status);

            //foreach (var items in values)
            //{
            //    Username = items.Username;
            //    Email = items.EmailID;
            //}
            int MailCount = 1;
            if (MailTemplate != null)
            {
                if (MailTemplate.Rows.Count > 0)
                {
                    foreach (DataRow dr in MailTemplate.Rows)
                    {
                        try
                        {
                            mailTemplateID = dr["ID"].ToString();
                            mailFrom = dr["MailFrom"].ToString();
                            mailSubject = dr["MailSubject"].ToString();
                            mailBody = dr["MailBody"].ToString();
                            mailBody = mailBody.Replace("#UserFullName#", Username);
                            if (MailCount == 1)
                            {
                                string MailTemplateID1 = dr["ID"].ToString();
                                string MailFrom1 = dr["MailFrom"].ToString();
                                string MailTo1 = Email;
                                // string MailCC1="";
                                string Subject1 = dr["MailSubject"].ToString();
                                //string Body1 = dr["MailBody"].ToString();
                                DateTime SendingDateTime1 = DateTime.Now;
                                DateTime OpDateTime1 = DateTime.Now;
                                long OpUserID1 = 0;

                                using (BaseRepository baseRepo = new BaseRepository())
                                {
                                    string Status = Convert.ToString(BizMail.AddMailForSending(baseRepo.BizDB, MailTemplateID1, MailFrom1, MailTo1, string.Empty, Subject1,
            mailBody, DateTime.Now, OpUserID1));
                                }
                            }
                            MailCount = MailCount + 1;
                            System.Net.Mail.MailAddress from = new MailAddress(SMTP_TempEmailTo, SMTP_SenderName);
                            System.Net.Mail.MailAddress to = new MailAddress(Email);
                            System.Net.Mail.MailMessage m = new MailMessage(from, to);
                            m.IsBodyHtml = true;
                            m.Subject = mailSubject;
                            m.Priority = System.Net.Mail.MailPriority.High;
                            SmtpClient smtp = new SmtpClient(Smtp_Mail, Smtp_PortNo);
                            smtp.UseDefaultCredentials = false;
                           // smtp.EnableSsl = true;
                            // m.Body = sb.ToString();
                            m.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
                            System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString
                            (System.Text.RegularExpressions.Regex.Replace(mailBody, @"<(.|\n)*?>", string.Empty), null, "text/plain");
                            System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailBody, null, "text/html");
                            m.AlternateViews.Add(plainView);
                            m.AlternateViews.Add(htmlView);
                            smtp.Credentials = new NetworkCredential(Smtp_Username, Smtp_Password);

                            try
                            {
                                smtp.Send(m);
                                status = "Success";
                            }
                            catch
                            {
                                status = "Failure";
                            }
                        }
                        catch
                        {

                        }

                    }
                }

            }

            return Json(status, JsonRequestBehavior.AllowGet);
        }
        public string GetUserinfo(string username)
        {
            string status = "false";
              int ID=0;
                string name = "";
                 string Surname = "";
                string Email = "";
                string mailTemplateID = "";
                string mailFrom = "";
                string mailSubject = "";
                string mailBody = "";
                string UserName="";
            {
                PropertyOperationsRepository objupdate = new PropertyOperationsRepository();
                var userinfo = objupdate.GetUserinfo(username);
                foreach (var items in userinfo)
                {
                    ID=items.ID;
                    name = items.Name;
                    Surname = items.Surname;
                    UserName=items.UserName;
                   // DateTime date = DateTime.Now;
                    if (userinfo != null && (items.FirmID != null ))
                      {
               // Mail(CultureCode, username);

                List<ChangePasswordExt> objList = new List<ChangePasswordExt>();
                DataTable MailTemplate = new DataTable();
                DataTable dt = new DataTable();
                ChangePasswordRepository homemail = new ChangePasswordRepository();

                MailTemplate = homemail.GetMailTemplates("SendRemindPasswordEmail", CultureCode);

                if (MailTemplate != null)
                {
                    if (MailTemplate.Rows.Count > 0)
                    {
                        foreach (DataRow dr in MailTemplate.Rows)
                        {
                            mailTemplateID = dr["ID"].ToString();
                            mailFrom = dr["MailFrom"].ToString();
                            mailSubject = dr["MailSubject"].ToString();
                            mailBody = dr["MailBody"].ToString();

                            mailBody = mailBody.Replace("#UserFullName#", items.Name +  items.Surname);
                            mailBody = mailBody.Replace("#RemindLink#", homemail.GetParameter("AdminUserRemindLink"));
                            mailBody = mailBody.Replace("#RemindCode#", BizUtil.EncryptQueryStringParam(items.ID  + ";"  + items.UserName + ";" + DateTime.Now));
                            System.Net.Mail.MailAddress from = new MailAddress(SMTP_TempEmailTo, SMTP_SenderName);
                            System.Net.Mail.MailAddress to = new MailAddress(username);
                            System.Net.Mail.MailMessage m = new MailMessage(from, to);
                            m.IsBodyHtml = true;
                            m.Subject = mailSubject;
                            m.Priority = System.Net.Mail.MailPriority.High;
                            SmtpClient smtp = new SmtpClient(Smtp_Mail, Smtp_PortNo);
                            smtp.UseDefaultCredentials = false;
                            // smtp.EnableSsl = true;
                            // m.Body = sb.ToString();
                            m.BodyEncoding = System.Text.Encoding.GetEncoding("utf-8");
                            System.Net.Mail.AlternateView plainView = System.Net.Mail.AlternateView.CreateAlternateViewFromString
                            (System.Text.RegularExpressions.Regex.Replace(mailBody, @"<(.|\n)*?>", string.Empty), null, "text/plain");
                            System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(mailBody, null, "text/html");
                            m.AlternateViews.Add(plainView);
                            m.AlternateViews.Add(htmlView);
                            smtp.Credentials = new NetworkCredential(Smtp_Username, Smtp_Password);

                            try
                            {
                                smtp.Send(m);
                                status = "Success";

                            }
                            catch
                            {
                                status = "Failure";
                            }
                        }
                    }

                }
            }
            }
            }

                return status;
        }