예제 #1
0
        public async Task ListMyInvite(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.Normal);

            if (userSession == null)
            {
                return;
            }

            //读取基础数据
            var groupDb       = DbFactory.Get <UserGroup>();
            var groupNameDict = (await groupDb.SelectAllFromCache()).ToDictionary(it => it.gid, it => it.groupname);

            //读取仍然为有效状态的邀请
            var inviteDb = DbFactory.Get <Invite>();
            var result   = await inviteDb.SimpleDb.AsQueryable().Where(it => it.to_uid == userSession.uid && it.valid == 1).ToListAsync();

            var res = result.Select(it =>
            {
                var r = new ListSentResponse.InviteView(it);
                if (groupNameDict.ContainsKey(r.from_gid))
                {
                    r.from_groupname = groupNameDict[r.from_gid];
                }
                return(r);
            }).ToList();

            await response.JsonResponse(200, new ListSentResponse
            {
                status = 1,
                result = res
            });
        }
예제 #2
0
        public async Task ListSentInvites(Request request, Response response)
        {
            var userSession = await CheckAuth.Check(request, response, AuthLevel.TeamLeader);

            if (userSession == null)
            {
                return;
            }

            //取得该用户GID
            var groupBindDb   = DbFactory.Get <UserGroupBind>();
            var groupBindList = await groupBindDb.SelectAllFromCache();

            var groupBindItem = groupBindList.FirstOrDefault(it => it.uid == userSession.uid);

            if (groupBindItem == null)
            {
                await response.BadRequest("未确定组队?");

                return;
            }

            var gid = groupBindItem.gid;

            //读取基础数据
            var userDb       = DbFactory.Get <User>();
            var userNameDict = (await userDb.SelectAllFromCache()).ToDictionary(it => it.uid, it => it.username);

            //读取仍然为有效状态的邀请
            var inviteDb = DbFactory.Get <Invite>();
            var result   = await inviteDb.SimpleDb.AsQueryable().Where(it => it.from_gid == gid && it.valid == 1).ToListAsync();

            var res = result.Select(it =>
            {
                var r = new ListSentResponse.InviteView(it);
                if (userNameDict.ContainsKey(r.to_uid))
                {
                    r.to_username = userNameDict[r.to_uid];
                }
                return(r);
            }).ToList();

            await response.JsonResponse(200, new ListSentResponse
            {
                status = 1,
                result = res
            });
        }