예제 #1
0
        public async Task <AjaxResponse> SaveUserModel(UserInput model)
        {
            if (model.ID == null)
            {
                UserInfo modelInput = ObjectMapper.Map <UserInfo>(model);
                //查询范围包含已经逻辑删除的数据
                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
                    //唯一键冲突必须要先进行验证
                    var res = await _userInfoManager.FindByNameAsync(modelInput.UserCode);

                    if (res != null)
                    {
                        throw new UserFriendlyException("账号重复", "您输入的账号:" + model.UserCode + "重复!");
                    }
                }
                //新增用户设置默认图标
                modelInput.ImageUrl = "m";
                if (modelInput.Sex == "0")
                {
                    modelInput.ImageUrl = "w";
                }
                //新增用户对象(新增前默认验证UserCode的账号是否存在如果存在不做新增)
                await _userInfoManager.CreateAsync(modelInput);

                //EF 保存当前用户数据对象
                _unitOfWorkManager.Current.SaveChanges();
                //获取新增后的主键id
                model.ID = modelInput.Id;
                // 新增用户默认订阅所有通知
                await _sysNotificationAppService.UserSubscriptionNotificationInfoAll(modelInput.Id);
            }
            else
            {
                long id = Convert.ToInt64(model.ID);
                //更新数据时不对数据是否逻辑删除做判断
                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
                    //获取需要更新的数据
                    UserInfo data = _userInfoRepository.Get(id);
                    //映射需要修改的数据对象
                    UserInfo modelInput = ObjectMapper.Map(model, data);
                    //提交修改
                    await _userInfoManager.UpdateAsync(modelInput);
                }
                //清除缓存
                _cacheManagerExtens.RemoveUserInfoCache(id);
            }
            //用户扩展信息,如有扩展字段需要重写该部分
            bool isFlag = await _userInfoExtens.UpdateUserInfo(model);

            if (!isFlag)
            {
                throw new UserFriendlyException("用户扩展信息", "用户扩展信息保存失败!");
            }
            return(new AjaxResponse {
                Success = true
            });
        }
예제 #2
0
        public AjaxResponse SaveRoleToUser(RoleToUser model)
        {
            //删除原有授权
            _sysRolesRepository.DelRoleToUser(model.RoleID);

            if (model.RoleToUserList == null || !model.RoleToUserList.Any())
            {
                //未设置授权用户直接返回
                return(new AjaxResponse {
                    Success = true
                });
            }
            //新增授权
            _sysRolesRepository.AddRoleToUser(ObjectMapper.Map <List <SysRoleToUser> >(model.RoleToUserList));
            //清空所设置用户的缓存
            foreach (var item in model.RoleToUserList)
            {
                _cacheManagerExtens.RemoveUserInfoCache(item.UserID);
            }
            return(new AjaxResponse {
                Success = true
            });
        }
예제 #3
0
        public async Task <AjaxResponse> SaveUserModel(UserInput model)
        {
            if (model.ID == null)
            {
                UserInfo modelInput = model.MapTo <UserInfo>();
                //查询范围包含已经逻辑删除的数据
                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
                    //唯一键冲突必须要先进行验证
                    var res = await _userInfoManager.FindByNameAsync(modelInput.UserCode);

                    if (res != null)
                    {
                        return(new AjaxResponse {
                            Success = false, Error = new ErrorInfo("账号重复")
                        });
                    }
                }
                //新增用户设置默认图标
                modelInput.ImageUrl = "m";
                if (modelInput.Sex == "0")
                {
                    modelInput.ImageUrl = "w";
                }
                //新增用户对象
                await _userInfoManager.CreateAsync(modelInput);

                //获取新增后的主键id
                model.ID = modelInput.Id;
                //新增订阅通知
                var notificationInfo = await _sysNotificationAppService.GetNotificationInfoAllAsync();

                foreach (var item in notificationInfo)
                {
                    await _sysNotificationAppService.InsertSubscriptionAsync(new List <long>() { modelInput.Id }, item.NotificationName);
                }
            }
            else
            {
                long id = Convert.ToInt64(model.ID);
                //更新数据时不对数据是否逻辑删除做判断
                using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
                    //获取需要更新的数据
                    UserInfo data = _userInfoRepository.Get(id);
                    //映射需要修改的数据对象
                    UserInfo modelInput = ObjectMapper.Map(model, data);

                    //提交修改
                    await _userInfoManager.UpdateAsync(modelInput);
                }
                //清除缓存
                _cacheManagerExtens.RemoveUserInfoCache(id);
            }

            bool isFlag = await _userInfoExtens.UpdateUserInfo(model);

            if (!isFlag)
            {
                return(new AjaxResponse {
                    Success = false, Error = new ErrorInfo("用户扩展信息保存失败!")
                });
            }
            return(new AjaxResponse {
                Success = true
            });
        }