Beispiel #1
0
        private List <UserAuthentication> GetAuthentications()
        {
            var result = new List <UserAuthentication>();

            UserDeviceAuthViewModels.ForEach(x =>
            {
                if (x.PasswordCredential.IsSelected)
                {
                    result.Add(Mapper.Map <UserAuthentication>(x.PasswordCredential));
                }

                if (x.IcCardCredential.IsSelected)
                {
                    result.Add(Mapper.Map <UserAuthentication>(x.IcCardCredential));
                }

                result.AddRange(x.FingerPrintCredentials.FindAll(xx => xx.IsSelected).Select(Mapper.Map <UserAuthentication>));
            });

            return(result);
        }
Beispiel #2
0
        private void Save()
        {
            string message = "";

            try
            {
                string errorMessage        = "";
                var    passwordCredentials = UserDeviceAuthViewModels.Select(x => x.PasswordCredential);
                var    validator           = NinjectBinder.GetValidator <PasswordAuthenticationViewModelValidator>();
                passwordCredentials.ForEach(x =>
                {
                    var results = validator.Validate(x);
                    if (!results.IsValid)
                    {
                        errorMessage = string.Join("\n", results.Errors);
                    }
                });
                var icCardCredentials = UserDeviceAuthViewModels.Select(x => x.IcCardCredential);
                var icCardValidator   = NinjectBinder.GetValidator <IcCardAuthenticationViewModelValidator>();
                icCardCredentials.ForEach(x =>
                {
                    var results = icCardValidator.Validate(x);
                    if (!results.IsValid)
                    {
                        errorMessage = string.Join("\n", results.Errors);
                    }
                });
                if (!string.IsNullOrWhiteSpace(errorMessage))
                {
                    SendMessage(errorMessage);
                    return;
                }

                CurrentUser.UserAuthentications = GetAuthentications();
                CurrentUser.UserAuthentications.FindAll(x => x.UserAuthenticationID == 0).ForEach(xx =>
                {
                    xx.CreateUserID = ApplicationManager.GetInstance().CurrentOperatorInfo.OperatorID;
                    xx.CreateDate   = DateTime.Now;
                });
                CurrentUser.UserAuthentications.FindAll(x => x.UserAuthenticationID != 0).ForEach(xx =>
                {
                    xx.UpdateUserID = ApplicationManager.GetInstance().CurrentOperatorInfo.OperatorID;
                    xx.UpdateDate   = DateTime.Now;
                });

                _userRepo.Update(CurrentUser);
                message = "更新凭证成功!";
            }
            catch (Exception ex)
            {
                Log.Error("Update user fails.", ex);
                message = "更新凭证失败";
                SendMessage(message);
                return;
            }

            ViewModelAttachment.CoreModel            = CurrentUser;
            ViewModelAttachment.LastOperationSuccess = true;
            RaisePropertyChanged(null);
            Close(message);
        }