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 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 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)); } }