/// <summary>
        /// It is used to send an email using emailAccountID.
        /// </summary>
        public bool SendEmail(Guid emailAccountID,
                              List <string> to, string bcc, string cc, string subject, string body)
        {
            sysBpmsEmailAccount account = new EmailAccountService(this.UnitOfWork).GetInfo(emailAccountID);

            return(new EmailService().SendEmailAsync(account.Email, account.MailPassword, account.SMTP, account.Port.ToIntObj(), to, bcc, cc, subject, body).IsSuccess);
        }
        public ResultOperation Update(sysBpmsDepartment Department, sysBpmsEmailAccount emailAccount)
        {
            ResultOperation resultOperation = new ResultOperation();

            try
            {
                this.BeginTransaction();
                if (resultOperation.IsSuccess)
                {
                    this.UnitOfWork.Repository <IDepartmentRepository>().Update(Department);
                    this.UnitOfWork.Save();

                    if (emailAccount != null)
                    {
                        emailAccount.ObjectID = Department.ID;
                        resultOperation       = new EmailAccountService(base.UnitOfWork).AddOverwrite(emailAccount);
                    }
                }
            }
            catch (Exception ex)
            {
                return(base.ExceptionHandler(ex));
            }
            base.FinalizeService(resultOperation);
            return(resultOperation);
        }
        public ResultOperation Delete(Guid userId)
        {
            ResultOperation resultOperation = new ResultOperation();

            if (resultOperation.IsSuccess)
            {
                try
                {
                    this.BeginTransaction();
                    //delete email accounts
                    EmailAccountService emailAccountService = new EmailAccountService(base.UnitOfWork);
                    var emailList = emailAccountService.GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, userId, null);
                    foreach (var item in emailList)
                    {
                        emailAccountService.Delete(item.ID);
                    }

                    //delete department member.
                    DepartmentMemberService departmentMemberService = new DepartmentMemberService(base.UnitOfWork);
                    var members = departmentMemberService.GetList(null, null, userId);
                    foreach (var item in members)
                    {
                        departmentMemberService.Delete(item.ID);
                    }

                    this.UnitOfWork.Repository <IUserRepository>().Delete(userId);
                    this.UnitOfWork.Save();
                }
                catch (Exception ex)
                {
                    resultOperation.AddError(LangUtility.Get("UserUsedError.Text", nameof(sysBpmsUser)));
                    return(base.ExceptionHandler(new Exception(LangUtility.Get("UserUsedError.Text", nameof(sysBpmsUser)))));
                }
            }
            base.FinalizeService(resultOperation);
            return(resultOperation);
        }
Exemplo n.º 4
0
        public ResultOperation SendEmail(sysBpmsEvent _event)
        {
            ResultOperation        resultOperation  = new ResultOperation();
            SubTypeEmailEventModel email            = _event.SubTypeMessageEventModel.Email;
            sysBpmsEmailAccount    fromEmailAccount = new sysBpmsEmailAccount();
            DataManageEngine       dataManageEngine = new DataManageEngine(base.EngineSharedModel, base.UnitOfWork);

            List <string> toEmailList = new List <string>();

            switch (email.From.ToIntObj())
            {
            case (int)SubTypeEmailEventModel.e_FromType.CurrentUser:
                sysBpmsUser user = new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentUserName);
                if (user != null)
                {
                    fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, null).LastOrDefault();
                }
                break;

            case (int)SubTypeEmailEventModel.e_FromType.CurrentThreadUser:
                user = base.EngineSharedModel.CurrentThread != null && base.EngineSharedModel.CurrentThread.UserID.HasValue ? new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentThread.UserID.Value) : null;
                if (user != null)
                {
                    fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, null).LastOrDefault();
                }
                break;

            default:
                fromEmailAccount = new EmailAccountService(base.UnitOfWork).GetInfo(email.From.ToGuidObj());
                break;
            }

            switch ((SubTypeEmailEventModel.e_ToType)email.ToType)
            {
            case SubTypeEmailEventModel.e_ToType.Static:
                toEmailList = email.To.Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
                break;

            case SubTypeEmailEventModel.e_ToType.Systemic:
                switch ((SubTypeEmailEventModel.e_ToSystemicType)email.To.ToIntObj())
                {
                case SubTypeEmailEventModel.e_ToSystemicType.CurrentUser:
                    sysBpmsUser user = new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentUserName);
                    if (user != null)
                    {
                        toEmailList.Add(user.Email);
                    }
                    break;

                case SubTypeEmailEventModel.e_ToSystemicType.CurrentThreadUser:
                    user = base.EngineSharedModel.CurrentThread != null && base.EngineSharedModel.CurrentThread.UserID.HasValue ? new UserService(base.UnitOfWork).GetInfo(base.EngineSharedModel.CurrentThread.UserID.Value) : null;
                    if (user != null)
                    {
                        toEmailList.Add(user.Email);
                    }
                    break;
                }
                break;

            case SubTypeEmailEventModel.e_ToType.Variable:
                toEmailList = dataManageEngine.GetValueByBinding(email.To).ToStringObj().Split(',').Where(c => !string.IsNullOrWhiteSpace(c)).ToList();
                break;
            }

            string subject = email.Subject;
            string content = email.Content;

            if (!string.IsNullOrWhiteSpace(subject))
            {
                foreach (string item in DomainUtility.GetRegularValue("[", "]", subject).Distinct())
                {
                    subject = subject.Replace("[" + item + "]", dataManageEngine.GetValueByBinding(item.Trim()).ToStringObj());
                }
            }

            if (!string.IsNullOrWhiteSpace(content))
            {
                foreach (string item in DomainUtility.GetRegularValue("[", "]", content).Distinct())
                {
                    content = content.Replace("[" + item + "]", dataManageEngine.GetValueByBinding(item.Trim()).ToStringObj());
                }
            }

            new EmailService().SendEmailAsync(fromEmailAccount.Email, fromEmailAccount.MailPassword, fromEmailAccount.SMTP, fromEmailAccount.Port.ToIntObj(), toEmailList, "", "", subject, content);
            return(resultOperation);
        }