예제 #1
0
        public async Task <IActionResult> GetUnhandledRequests(string topicId, int page, bool newest)
        {
            const int pageSize = 20;

            var tid = XUtils.ParseId(topicId);

            var query = from p in Context.AdminRequests
                        where p.TopicId == tid && p.Status == RequestStatus.Unhandled
                        join q in Context.Users
                        on p.SenderId equals q.Id
                        select new { request = p, user = q };

            if (newest)
            {
                query = query.OrderByDescending(p => p.request.CreatedAt);
            }
            else
            {
                query = query.OrderBy(p => p.request.CreatedAt);
            }

            query = query.Skip(page * pageSize).Take(pageSize);

            var requests = await query.ToListAsync();

            var data = requests.Select(p => QAdminRequest.NormalView(p.request, QUser.NormalView(p.user))).ToList();

            return(Ok(data));
        }
예제 #2
0
        public async Task <IActionResult> GetRequestById(string id)
        {
            var requestId = XUtils.ParseId(id);

            var query = from p in Context.AdminRequests
                        where p.Id == requestId
                        join q in Context.Users
                        on p.SenderId equals q.Id
                        select new { request = p, user = q };

            var data = await query.FirstOrDefaultAsync();

            var requestV = QAdminRequest.NormalView(data.request, QUser.NormalView(data.user));

            return(Ok(requestV));
        }