コード例 #1
0
        public async Task <PagedResult <DocumentsVm> > GetPagings(GetDocumentsPagingRequest request)
        {
            var data = await GetAsync <PagedResult <DocumentsVm> >(
                $"/api/documents/paging?pageIndex={request.PageIndex}" +
                $"&pageSize={request.PageSize}" +
                $"&keyword={request.Keyword}&userName={request.UserName}");

            return(data);
        }
コード例 #2
0
        public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 10)
        {
            var request = new GetDocumentsPagingRequest()
            {
                Keyword   = keyword,
                PageIndex = pageIndex,
                PageSize  = pageSize,
            };
            var data = await _documentApiClient.GetByUserID(request);

            ViewBag.Keyword = keyword;
            if (TempData["result"] != null)
            {
                ViewBag.SuccessMsg = TempData["result"];
            }
            return(View(data));
        }
コード例 #3
0
        public async Task <PagedResult <DocumentsVm> > GetAllPaging(GetDocumentsPagingRequest request)
        {
            var query = from c in _context.Documents
                        join u in _context.Users on c.UserID equals u.Id
                        select new { c, u };

            if (request.UserIds != null && request.UserIds.Count > 0)
            {
                query = query.Where(c => request.UserName.Contains(c.c.User.UserName));
            }
            if (!string.IsNullOrEmpty(request.Keyword))
            {
                query = query.Where(x => x.c.User.UserName.Contains(request.Keyword));
            }
            int TotalRow = await query.CountAsync();

            var data = await query.Skip((request.PageIndex - 1) *request.PageSize)
                       .Take(request.PageSize)
                       .Select(x => new DocumentsVm()
            {
                ID         = x.c.ID,
                UserID     = x.c.UserID,
                UserName   = x.u.UserName,
                Caption    = x.c.Caption,
                FacultyID  = x.c.FacultyOfDocumentID,
                MagazineID = x.c.MagazineID,
                CreateOn   = x.c.CreateOn.Date
            }).ToListAsync();

            var pagedResult = new PagedResult <DocumentsVm>()
            {
                TotalRecord = TotalRow,
                Items       = data
            };

            return(pagedResult);
        }
コード例 #4
0
        public async Task <PagedResult <DocumentsVm> > GetAllByUserId(GetDocumentsPagingRequest request)
        {
            var claimsIdentity = _httpContextAccessor.HttpContext.User.Identity as ClaimsIdentity;
            var userId         = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier)?.Value.ToString();
            var query          = from c in _context.Documents
                                 join u in _context.Users on c.UserID equals u.Id
                                 where c.UserID.ToString() == userId
                                 select new { c, u };

            if (request.DocumentId.HasValue && request.DocumentId.Value > 0)
            {
                query = query.Where(c => c.u.UserName == request.UserName);
            }
            int TotalRow = await query.CountAsync();

            var data = await query.Skip((request.PageIndex - 1) *request.PageSize)
                       .Take(request.PageSize)
                       .Select(x => new DocumentsVm()
            {
                ID         = x.c.ID,
                UserID     = x.u.Id,
                UserName   = x.u.UserName,
                Caption    = x.c.Caption,
                FacultyID  = x.c.FacultyOfDocumentID,
                MagazineID = x.c.MagazineID,
                CreateOn   = x.c.CreateOn.Date
            }).ToListAsync();

            var pagedResult = new PagedResult <DocumentsVm>()
            {
                TotalRecord = TotalRow,
                Items       = data
            };

            return(pagedResult);
        }
コード例 #5
0
        public async Task <IActionResult> GetByUser([FromQuery] GetDocumentsPagingRequest request)
        {
            var documents = await _documentsService.GetAllByUserId(request);

            return(Ok(documents));
        }