Пример #1
0
        public async Task <string> DeleteClientAsync(string client_uid, string user_uid)
        {
            var client = await this._AuthClientRepository.GetFirstAsync(x => x.UID == client_uid && x.UserUID == user_uid);

            Com.Assert(client, x => x != null, $"找不到client[client_uid={client_uid},user_uid={user_uid}]");
            var ok = await this._AuthClientRepository.DeleteAsync(client) > 0;

            if (ok)
            {
                await this._AuthClientRepository.PrepareSessionAsync(async db =>
                {
                    var token_set = db.Set <AuthToken>();
                    var code_set  = db.Set <AuthCode>();
                    var scope_set = db.Set <AuthTokenScope>();

                    var token_to_delete = token_set.Where(x => x.ClientUID == client_uid);
                    token_set.RemoveRange(token_to_delete);

                    var code_to_delete = code_set.Where(x => x.ClientUID == client_uid);
                    code_set.RemoveRange(code_to_delete);

                    var scope_to_delete = scope_set.Where(x => token_to_delete.Select(m => m.UID).Contains(x.TokenUID));
                    scope_set.RemoveRange(scope_to_delete);

                    await db.SaveChangesAsync();
                    return(true);
                });

                return(SUCCESS);
            }
            throw new Exception("删除client异常");
        }
Пример #2
0
        /// <summary>
        /// 删除节点和子节点
        /// </summary>
        /// <param name="nodeID"></param>
        /// <returns></returns>
        public string DeleteNodesAndChildren(string nodeID)
        {
            var root = _CategoryDal.GetFirst(x => x.UID == nodeID);

            Com.Assert(root, x => x != null, "您要删除的节点不存在");

            //获取这棵树下的所有节点
            var allNodesStore = _CategoryDal.GetList(x => x.CategoryType == root.CategoryType);

            if (!ValidateHelper.IsPlumpList(allNodesStore))
            {
                return("读取数据出现错误,请联系管理员");
            }

            //需要删除的id
            var DeletedIDS = new List <string>();

            //通过递归获取所有id
            FindAllNodes(allNodesStore, new List <CategoryModel>()
            {
                root
            }, (node) =>
            {
                //如果已经遍历过这个节点就终止递归,防止死循环
                if (DeletedIDS.Contains(node.UID))
                {
                    return(false);
                }

                DeletedIDS.Add(node.UID);
                return(true);
            });
            DeletedIDS = DeletedIDS.Where(x => ValidateHelper.IsPlumpString(x)).ToList();
            if (!ValidateHelper.IsPlumpList(DeletedIDS))
            {
                return("没有获取到要删除的ID");
            }
            return(DeleteSingleNodeByIDS(DeletedIDS.ToArray()));
        }
Пример #3
0
        public async Task <string> UpdateClientAsync(AuthClient updatemodel)
        {
            var client = await this._AuthClientRepository.GetFirstAsync(x => x.UID == updatemodel.UID && x.UserUID == updatemodel.UserUID);

            Com.Assert(client, x => x != null, $"client不存在:{updatemodel.ToJson()}");

            client.ClientName = updatemodel.ClientName;
            client.ClientUrl  = updatemodel.ClientUrl;
            client.LogoUrl    = updatemodel.LogoUrl;
            client.UpdateTime = DateTime.Now;

            if (!this.CheckModel(client, out var msg))
            {
                return(msg);
            }

            var ok = await this._AuthClientRepository.UpdateAsync(client) > 0;

            if (ok)
            {
                return(SUCCESS);
            }
            throw new MsgException("更新client异常");
        }