/// <summary> /// <para> /// Updates the given user. /// </para> /// </summary> /// /// <param name="user">The given user.</param> /// /// <exception cref="ArgumentNullException">If <paramref name="user"/> is null /// or user.Username is null.</exception> /// <exception cref="ArgumentException"> If user.Username is empty or user.Role is null /// </exception> /// <exception cref="EntityNotFoundException">If the user to update doesn't exist.</exception> /// <exception cref="PersistenceException">If error occurred during access the persistence. /// </exception> /// <exception cref="ServiceException"> If any other error occurred. </exception> public void Update(User user) { ProcessWithDb(db => { CommonHelper.ValidateArgumentNotNull(user, "user"); CommonHelper.ValidateArgumentNotNullOrEmpty(user.Username, "user.Username"); if (user.Role == null && user.KPIRole == null) { throw new ArgumentException( $"The parameters user.Role and user.KPIRole cannot both be null.", "user"); } if (GetDirectoryEntryOfUser(user.Username) == null) { throw new EntityNotFoundException( "User does not exists with username :"******"updating user", parameters: user); }
/// <summary> /// Checks if the user can be updated without breaking the referenced assessments /// </summary> /// <param name="username">The username.</param> /// <param name="existing">The existing user detail.</param> /// <param name="updating">The user detail to be updated.</param> /// <param name="db">The db context</param> /// <exception cref="ServiceException">If user cannot be updated.</exception> /// <remarks>Any other exceptions will be propagated to the caller.</remarks> private void CheckReferenceForUpdate(string username, UserMappingInfo existing, UserMappingInfo updating, CustomDbContext db) { if ((existing.Role == Role.Owner || existing.Role == Role.BUFunctionalApprover) && (existing.Role != updating.Role || (existing.IsActive && !updating.IsActive))) { // don't check approved assessments, since user cannot be deleted, removing role // won't affect the assessments as approved assessments are only read only var query = db.AssessmentSet.Where(p => p.ApprovalStatus != ApprovalStatus.Approved); var message = "user is approver in"; var roleChangedFrom = ""; //if user role is BUFunctionalApprover check if he is assigned as approver // in any assessments in approval work-flow if (existing.Role == Role.BUFunctionalApprover && (updating.Role != Role.BUFunctionalApprover || (existing.IsActive && !updating.IsActive))) { query = query.Where(p => (p.DepartmentHead.Name == username || p.FunctionalAreaOwner.Name == username) && p.ApprovalStatus != ApprovalStatus.Draft && p.ApprovalStatus != ApprovalStatus.Rejected); roleChangedFrom = "BU Functional Approver"; } else if (existing.Role == Role.Owner && (updating.Role != Role.Owner || (existing.IsActive && !updating.IsActive))) { // for owner check if he has any assessments submitted query = query.Where(p => p.SubmitterUsername == username); message = "user is submitter of"; roleChangedFrom = "Owner"; } var referencedAssessmentIds = query.Select(p => p.Id).ToList(); if (referencedAssessmentIds.Count > 0) { var ids = string.Join(",", referencedAssessmentIds); if (existing.Role != updating.Role) { throw new ServiceException($"The role of user cannot be changed from {roleChangedFrom}" + $" because {message} in some active assessments with ids ({ids})"); } else { throw new ServiceException($"The status of user cannot be changed to inactive" + $" because {message} some active assessments with ids ({ids})"); } } } }
private void userMappingList1_UserFocusChanged(object sender, EventArgs e) { UserMappingInfo _umi = this.userMappingList1.FocusedUser; if (_umi != null) { this.te_CUPAA_USERID.Text = _umi.UserID; this.TE_CUPAA_USERNAME.Text = _umi.UserName; this.TE_TRD_NAME.Text = _umi.TRD_LoginName; this.TE_TRD_USERID.Text = _umi.TRD_YHID; this.TE_TRD_XM.Text = _umi.TRD_XM; } else { this.te_CUPAA_USERID.Text = ""; this.TE_CUPAA_USERNAME.Text = ""; this.TE_TRD_NAME.Text = ""; this.TE_TRD_USERID.Text = ""; this.TE_TRD_XM.Text = ""; } }
private void SaveMapping() { bool _ret = false; UserMappingInfo _umi = this.userMappingList1.FocusedUser; string _name = this.TE_TRD_NAME.Text.Trim(); string _yhid = this.TE_TRD_USERID.Text.Trim(); string _xm = this.TE_TRD_XM.Text.Trim(); using (SinoSZClientBase.UserManagerService.UserManagerServiceClient _umsc = new SinoSZClientBase.UserManagerService.UserManagerServiceClient()) { _ret = _umsc.SaveUserMapping(_yhid, _umi.UserID, _name, _xm, _umi.UserName); } if (_ret) { this.userMappingList1.BeginUpdate(); _umi.TRD_LoginName = _name; _umi.TRD_YHID = _yhid; _umi.TRD_XM = _xm; this.userMappingList1.EndUpdate(); XtraMessageBox.Show("保存映射成功!", "系统提示"); } }