public async Task <UserInfo> AddOrModifyUserInfoAsync(AddOrModifyUserInfo model, string sOperator)
        {
            UserInfo entityUserInfo;

            if (model.Id == 0)
            {
                entityUserInfo = _mapper.Map <UserInfo>(model);
                //加密  使用默认密码
                entityUserInfo.SloginPwd = EncryptHelper.EncryptPasswordMd5(EncryptHelper.Encode(entityUserInfo.SloginPwd, EncryptHelper.AesEncryptKeys));
                await _userInfoRepository.AppendAsync(entityUserInfo, sOperator);
            }
            else
            {
                entityUserInfo = await _userInfoRepository.SelectAsync(model.Id);

                if (entityUserInfo != null)
                {
                    model.SloginPwd = entityUserInfo.SloginPwd;
                    _mapper.Map(model, entityUserInfo);
                    _userInfoRepository.Update(entityUserInfo, sOperator);
                }
            }
            await _userRoleService.AddOrDeleteUserRoleAsync(entityUserInfo.Id, model.lstRoleId, sOperator);

            return(entityUserInfo);
        }
Beispiel #2
0
        public async Task <string> AddOrModifyAsync([FromForm] AddOrModifyUserInfo model)
        {
            BaseResult baseResult = new BaseResult();

            try
            {
                if (model != null)
                {
                    AddOrModifyUserInfoValidation validationRules = new AddOrModifyUserInfoValidation();
                    ValidationResult validationResilt             = await validationRules.ValidateAsync(model);

                    if (validationResilt.IsValid)
                    {
                        string sDefaultUserPwd = GetJsonValue("DefaultUserPwd");
                        model.SloginPwd = sDefaultUserPwd;
                        UserInfo resultUserInfo = await _userInfoService.AddOrModifyUserInfoAsync(model, User.Identity.Name);

                        if (resultUserInfo != null)
                        {
                            baseResult.Code = 0;
                            baseResult.Msg  = "操作成功!";
                        }
                        else
                        {
                            baseResult.Code = 1;
                            baseResult.Msg  = "操作失败!";
                        }
                    }
                    else
                    {
                        baseResult.Code = 3;
                        baseResult.Msg  = validationResilt.ToString("<br>");
                    }
                }
            }
            catch (System.Exception ex)
            {
                baseResult.Code = 4;
                baseResult.Msg  = ex.Message;
            }
            return(JsonHelper.ObjectToJSON(baseResult));
        }