public IHttpActionResult sendEmailForgotPassword(string email, long hosID)
        {
            try
            {
                MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
                string code         = DateTime.Now.ToString("yyyyMMddhhmmsstt");
                string code_encrypt = LVCrypto.GetMd5Hash(md5, code);
                // Luu thong tin lai:
                UserAccount account = this.Repository.GetQuery <UserAccount>().FirstOrDefault(m => m.AccountNameEmailAddress == email);
                if (account != null)
                {
                    account.isBlocked         = true;
                    account.RequestDateForPWD = DateTime.Now;
                    account.ForgotPwdCode     = code_encrypt;
                    this.Repository.Update <UserAccount>(account);
                    this.Repository.UnitOfWork.SaveChanges();
                }


                RegisterMailController mailCtrl = new RegisterMailController();
                string report = GetMailTemplate();
                //Dictionary<long, string> appStatusDic = GetAppStatusDic();
                string Body    = "";
                var    hosInfo = (from h in this.Repository.GetQuery <HCProvider>()
                                  where h.HosID == hosID
                                  select new
                {
                    hospital = h.HCPrvProviderName,
                    slogan = h.Slogan,
                    addressHos = h.HCPractAddressText,
                    logo = h.HosLogoImgPath
                }).FirstOrDefault();

                Body = report;
                var url = HttpContext.Current.Request.UrlReferrer.AbsoluteUri.Replace(HttpContext.Current.Request.UrlReferrer.AbsolutePath, "");

                Body = Body.Replace("@hospital", hosInfo.hospital);
                Body = Body.Replace("@addressHos", hosInfo.addressHos);


                //slogan
                Body = Body.Replace("@slogan", hosInfo.slogan);

                LV.Common.LVCrypto cry = new LVCrypto();
                Body = Body.Replace("@ForgotPassword", url + "/eportal/NewPassword/" + code_encrypt);

                List <LinkedResource> res = new List <LinkedResource>();

                LinkedResource pic1 = new LinkedResource(HttpContext.Current.Server.MapPath("~") + hosInfo.logo);
                pic1.ContentId = "logo";
                res.Add(pic1);

                mailCtrl._SendMail(email, "Cấp lại mật khẩu", Body, null, res);
                return(Ok(true));
            }
            catch (Exception exp)
            {
                return(Ok(false));
            }
        }
Beispiel #2
0
        public bool RegisterMailD(string to, string subject, long AccountID, string ActivationCode)
        {
            try
            {
                RegisterMailController mailCtrl = new RegisterMailController();
                int    hosID  = 11163;
                string report = GetMailTemplate();
                //Dictionary<long, string> appStatusDic = GetAppStatusDic();
                string Body    = "";
                var    hosInfo = (from h in this.Repository.GetQuery <HCProvider>()
                                  where h.HosID == hosID
                                  select
                                  new { hospital = h.HCPrvProviderName, slogan = h.Slogan, addressHos = h.HCPractAddressText, logo = h.HosLogoImgPath }).FirstOrDefault();

                Body = report;
                var url = HttpContext.Current.Request.UrlReferrer.AbsoluteUri.Replace(HttpContext.Current.Request.UrlReferrer.AbsolutePath, "");

                Body = Body.Replace("@hospital", hosInfo.hospital);
                Body = Body.Replace("@addressHos", hosInfo.addressHos);


                //slogan
                Body = Body.Replace("@slogan", hosInfo.slogan);

                LV.Common.LVCrypto cry = new LVCrypto();
                Body = Body.Replace("@linkActive", url + "/eportal/ActiveRegister/" + ActivationCode);
                List <LinkedResource> res = new List <LinkedResource>();

                LinkedResource pic1 = new LinkedResource(HttpContext.Current.Server.MapPath("~") + hosInfo.logo);
                pic1.ContentId = "logo";
                res.Add(pic1);

                mailCtrl._SendMail(to, subject, Body, null, res);
                return(true);
            }
            catch (Exception exp)
            {
                return(false);
            }
        }