Пример #1
0
        internal void SendMailPassword(User currentUser)
        {
            KeyValue kvActiveStatus = new KeyValueBL().GetKeyValueByIntCode("UserStatus", "Active");
            KeyValue kvTemporarilyInactiveStatus = new KeyValueBL().GetKeyValueByIntCode("UserStatus", "TemporarilyInactive");

            Person person   = null;
            string password = string.Empty;

            if (currentUser.idStatus == kvActiveStatus.idKeyValue)
            {
                person   = new PersonBL().GetPersonByPersonID(currentUser.idPerson.ToString());
                password = ETEMModel.Helpers.BaseHelper.Decrypt(System.Web.HttpUtility.UrlDecode(currentUser.Password));
            }
            else if (currentUser.idStatus == kvTemporarilyInactiveStatus.idKeyValue)
            {
                person   = new PersonBL().GetPersonByPersonID(currentUser.idAltPerson.ToString());
                password = ETEMModel.Helpers.BaseHelper.Decrypt(System.Web.HttpUtility.UrlDecode(currentUser.AltPassword));
            }
            else
            {
                return;
            }



            CommonBL commonBL = new CommonBL();

            CallContext callContext = new CallContext();

            if (callContext.ListKvParams.Where(w => w.Key == ETEMEnums.AppSettings.MailServer.ToString()).Count() == 0)
            {
                callContext.ListKvParams.Add(new KeyValuePair <string, object>(ETEMEnums.AppSettings.MailServer.ToString(),
                                                                               commonBL.GetSettingByCode(ETEMEnums.AppSettings.MailServer).SettingValue));
            }
            if (callContext.ListKvParams.Where(w => w.Key == ETEMEnums.AppSettings.MailServerPort.ToString()).Count() == 0)
            {
                callContext.ListKvParams.Add(new KeyValuePair <string, object>(ETEMEnums.AppSettings.MailServerPort.ToString(),
                                                                               commonBL.GetSettingByCode(ETEMEnums.AppSettings.MailServerPort).SettingValue));
            }
            if (callContext.ListKvParams.Where(w => w.Key == ETEMEnums.AppSettings.MailFromPassword.ToString()).Count() == 0)
            {
                callContext.ListKvParams.Add(new KeyValuePair <string, object>(ETEMEnums.AppSettings.MailFromPassword.ToString(),
                                                                               commonBL.GetSettingByCode(ETEMEnums.AppSettings.MailFromPassword).SettingValue));
            }



            string body = string.Format(BaseHelper.GetCaptionString("Entity_User_Send_Password_Body"),
                                        person.TwoNamesPlusTitle,
                                        currentUser.UserName,
                                        password
                                        );

            commonBL.SendMailAction(
                commonBL.GetSettingByCode(ETEMEnums.AppSettings.DefaultEmail).SettingValue,
                person.EMail,
                BaseHelper.GetCaptionString("Entity_User_Send_Password_Subject"),
                body,
                "Системен e-mail", new List <string>(), callContext);
        }