public object PostAddEdit(DepartmentDTO departmentDTO) { using (DepartmentService departmentService = new DepartmentService()) { sysBpmsDepartment department = departmentDTO.ID != Guid.Empty ? departmentService.GetInfo(departmentDTO.ID) : new sysBpmsDepartment(); department.Update(departmentDTO.DepartmentID, departmentDTO.Name); sysBpmsEmailAccount emailAccount = new sysBpmsEmailAccount(); ResultOperation resultOperation = emailAccount.Update((int)sysBpmsEmailAccount.e_ObjectTypeLU.Department, department.ID, departmentDTO.SMTP, departmentDTO.Port, departmentDTO.MailPassword, departmentDTO.WorkEmail); if (!resultOperation.IsSuccess) { return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error)); } if (departmentDTO.ID != Guid.Empty) { resultOperation = departmentService.Update(department, emailAccount); } else { resultOperation = departmentService.Add(department, emailAccount); } if (resultOperation.IsSuccess) { return(new PostMethodMessage(SharedLang.Get("Success.Text"), DisplayMessageType.success)); } else { return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error)); } } }
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 AddOverwrite(sysBpmsEmailAccount emailAccount) { sysBpmsEmailAccount current = emailAccount.ObjectID == null ? null : this.GetList(emailAccount.ObjectTypeLU, emailAccount.ObjectID, null).LastOrDefault(); if (!string.IsNullOrWhiteSpace(emailAccount.Email + emailAccount.MailPassword + emailAccount.SMTP)) { if (current == null) { return(this.Add(emailAccount)); } else { emailAccount.ID = current.ID; return(this.Update(emailAccount)); } } else { if (emailAccount != null && current != null) { return(this.Delete(current.ID)); } else { return(new ResultOperation()); } } }
public object GetAddEdit(Guid?ID = null) { using (EmailAccountService emailAccountService = new EmailAccountService()) { sysBpmsEmailAccount emailAccount = !ID.HasValue ? null : emailAccountService.GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, ID, null).LastOrDefault(); using (UserService userService = new UserService()) return(new UserDTO((ID.HasValue ? userService.GetInfo(ID.Value) : new sysBpmsUser()), emailAccount)); } }
public void Delete(Guid emailAccountId) { sysBpmsEmailAccount emailAccount = this.Context.sysBpmsEmailAccounts.FirstOrDefault(d => d.ID == emailAccountId); if (emailAccount != null) { this.Context.sysBpmsEmailAccounts.Remove(emailAccount); } }
public ResultOperation Update(sysBpmsEmailAccount emailAccount) { ResultOperation resultOperation = new ResultOperation(); if (resultOperation.IsSuccess) { this.UnitOfWork.Repository <IEmailAccountRepository>().Update(emailAccount); this.UnitOfWork.Save(); } return(resultOperation); }
public EmailAccountDTO(sysBpmsEmailAccount emailAccount) { if (emailAccount != null) { this.ID = emailAccount.ID; this.ObjectID = emailAccount.ObjectID; this.ObjectTypeLU = emailAccount.ObjectTypeLU; this.Email = emailAccount.Email; this.SMTP = emailAccount.SMTP; this.Port = emailAccount.Port; this.MailPassword = emailAccount.MailPassword; } }
public UserDTO(sysBpmsUser user, sysBpmsEmailAccount emailAccount = null) { if (user != null) { this.ID = user.ID; this.Username = user.Username; this.FirstName = user.FirstName; this.LastName = user.LastName; this.Email = user.Email; this.Tel = user.Tel; this.Mobile = user.Mobile; this.EmailAccountDTO = new EmailAccountDTO(emailAccount); } }
public DepartmentDTO(sysBpmsDepartment department, sysBpmsEmailAccount emailAccount = null) { if (department != null) { this.ID = department.ID; this.DepartmentID = department.DepartmentID; this.Name = department.Name; this.IsActive = department.IsActive; this.SMTP = emailAccount?.SMTP; this.Port = emailAccount?.Port; this.MailPassword = emailAccount?.MailPassword; this.WorkEmail = emailAccount?.Email; } }
public object PostAddEdit(EmailAccountDTO EmailAccountDTO) { if (ModelState.IsValid) { sysBpmsEmailAccount emailAccount = new sysBpmsEmailAccount(); ResultOperation resultOperation = emailAccount.Update((int)sysBpmsEmailAccount.e_ObjectTypeLU.Systemic, null, EmailAccountDTO.SMTP, EmailAccountDTO.Port, EmailAccountDTO.MailPassword, EmailAccountDTO.Email); if (!resultOperation.IsSuccess) { return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error)); } emailAccount.ID = EmailAccountDTO.ID; using (EmailAccountService EmailAccountService = new EmailAccountService()) { if (emailAccount.ID != Guid.Empty) { resultOperation = EmailAccountService.Update(emailAccount); } else { resultOperation = EmailAccountService.Add(emailAccount); } } if (resultOperation.IsSuccess) { return(new PostMethodMessage(SharedLang.Get("Success.Text"), DisplayMessageType.success)); } else { return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error)); } } else { return(new PostMethodMessage(SharedLang.Get("NotFound.Text"), DisplayMessageType.error)); } }
public object GetAddEdit(Guid?ID = null, Guid?ParentID = null) { if (ParentID.HasValue) { return(new DepartmentDTO() { DepartmentID = ParentID }); } else { using (EmailAccountService emailAccountService = new EmailAccountService()) { using (DepartmentService departmentService = new DepartmentService()) { sysBpmsEmailAccount emailAccount = !ID.HasValue || ID == Guid.Empty ? null : emailAccountService.GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.Department, ID, null).LastOrDefault(); return(new DepartmentDTO(ID.ToGuidObj() != Guid.Empty ? departmentService.GetInfo(ID.Value) : null, emailAccount)); } } } }
public object PostAddEdit(UserDTO UserDTO) { sysBpmsUser user = new sysBpmsUser(UserDTO.ID, UserDTO.Username, UserDTO.FirstName, UserDTO.LastName, UserDTO.Email, UserDTO.Tel, UserDTO.Mobile); ResultOperation resultOperation = new ResultOperation(); sysBpmsEmailAccount emailAccount = null; if (!string.IsNullOrWhiteSpace(UserDTO.EmailAccountDTO?.Email) || !string.IsNullOrWhiteSpace(UserDTO.EmailAccountDTO?.SMTP)) { emailAccount = new sysBpmsEmailAccount(); resultOperation = emailAccount.Update((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, UserDTO.EmailAccountDTO?.SMTP, UserDTO.EmailAccountDTO?.Port, UserDTO.EmailAccountDTO?.MailPassword, UserDTO.EmailAccountDTO?.Email); if (!resultOperation.IsSuccess) { return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error)); } } if (!string.IsNullOrWhiteSpace(user.Username)) { UserCodeHelper userCodeHelper = new UserCodeHelper(null, null); UserInfo userInfo = userCodeHelper.GetSiteUser(user.Username); if (userInfo == null) { bool createResult = userCodeHelper.CreateSiteUser(user.Username, user.FirstName, user.LastName, user.Email, (string.IsNullOrWhiteSpace(UserDTO.Password) ? UserController.GeneratePassword() : UserDTO.Password), false, createBpms: false); if (!createResult) { return(new PostMethodMessage(SharedLang.Get("CreateUserError.Text"), DisplayMessageType.error)); } } else { //if user exists and some inputs are null, it fills those with userInfo. if (string.IsNullOrWhiteSpace(user.FirstName)) { user.FirstName = userInfo.FirstName.ToStringObj().Trim(); } if (string.IsNullOrWhiteSpace(user.LastName)) { user.LastName = userInfo.LastName.ToStringObj().Trim(); } if (string.IsNullOrWhiteSpace(user.Tel)) { user.Tel = userInfo.Profile.Telephone.ToStringObj().Trim(); } if (string.IsNullOrWhiteSpace(user.Mobile)) { user.Mobile = userInfo.Profile.Cell.ToStringObj().Trim(); } if (string.IsNullOrWhiteSpace(user.Email)) { user.Email = userInfo.Email.ToStringObj().Trim(); } } } using (UserService userService = new UserService()) { if (user.ID != Guid.Empty) { resultOperation = userService.Update(user, emailAccount); //It deletes EmailAccount's record from database if user sends all emailAccount's inputs null. if (resultOperation.IsSuccess && emailAccount == null) { using (EmailAccountService emailAccountService = new EmailAccountService()) { emailAccount = emailAccountService.GetList((int)sysBpmsEmailAccount.e_ObjectTypeLU.User, user.ID, null).LastOrDefault(); if (emailAccount != null) { resultOperation = emailAccountService.Delete(emailAccount.ID); } } } } else { resultOperation = userService.Add(user, emailAccount); } } if (resultOperation.IsSuccess) { return(new PostMethodMessage(SharedLang.Get("Success.Text"), DisplayMessageType.success)); } else { return(new PostMethodMessage(resultOperation.GetErrors(), DisplayMessageType.error)); } }
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); }
public void Update(sysBpmsEmailAccount emailAccount) { this.Context.Entry(emailAccount).State = EntityState.Modified; }
public void Add(sysBpmsEmailAccount emailAccount) { emailAccount.ID = Guid.NewGuid(); this.Context.sysBpmsEmailAccounts.Add(emailAccount); }