private void UpdateModelErrorCount(object property, UserAssistantState view) { int errors = 0; if (AssistantItems.Count > 0) { errors += ((ModelBase)property).GetErrorCount > 0 ? ((ModelBase)property).GetErrorCount : 0; // Base ViewModel Errors Check add to first View if (view == UserAssistantState.General) errors += this.GetErrorCount > 0 ? this.GetErrorCount : 0; AssistantItems[(int)view].ErrorCount = errors > 0 ? errors.ToString() : String.Empty; } }
public IEnumerable<IResult> Save() { if (IsLocked()) { BusyOn("Validating Lock..."); GetIsLockValidRequest getIsLockValidRequest = new GetIsLockValidRequest(ModelNamesEnum.User, this.User.UserId.ToString()); yield return getIsLockValidRequest; if (getIsLockValidRequest.Error != null) { yield return new HandleExceptionResult(getIsLockValidRequest.Error); BusyOff(); yield break; } if (!getIsLockValidRequest.Result) { WindowManager.Value.Alert("Unable to continue", "The Record lock has expired."); BusyOff(); yield break; } } BusyOn("Validating User..."); UserAssistantState validatingState = UserAssistantState.General; if (!ValidateGeneral()) { this.state = validatingState; BusyOff(); yield break; } BusyOn("Saving User..."); //Build Save Object //this.User.Role = selectedRole; //this.User.RoleId = this.selectedRole.Id; //if (!string.IsNullOrWhiteSpace(User.Signature.Signature)) { // if (User.SignatureId == Guid.Empty) { // User.Signature.SignatureId = Guid.NewGuid(); // User.SignatureId = User.Signature.SignatureId; // } //} // If adding user record, hash password that was created if (!IsEditMode || ChangePassword) User.Password = Security.GetSha2Hash(this.Password.ToString().Trim(), this.User.Username.ToString().Trim()); // If user record is an admin, create admin key hash if (this.User.AdministratorYN) this.User.AdministratorKey = Security.GetSha2Hash(User.Username, Session.SessionInfo.Instance.CurrentUser.BaseKey); //Save SaveUserRequest saveUserRequest = new SaveUserRequest(this.User); yield return saveUserRequest; if (saveUserRequest.Error != null) { yield return new HandleExceptionResult(saveUserRequest.Error); BusyOff(); yield break; } if (AssistantMode == ViewMode.Add) { if (this.User.UserId == null) this.User.UserId = saveUserRequest.Result; // Clear All Related Data this.User.Signature = new UserSignature(); // Load any additional data this.User.Department = Lib.ListService.Instance.Departments.Where(x => x.DepartmentId == this.User.DepartmentId).SingleOrDefault(); } this.User.IsDirty = false; this.User.IsTrackChange = false; this.User.OriginalObject = null; Events.Value.Publish(new EventModifiedUser() { User = this.User }); IsDirty = false; BusyOff(); base.Close(); }