Ejemplo n.º 1
0
        public async Task <PagedList <Visitor> > GetAll(VisitorParams visitorParams)
        {
            var visitors = _context.Visitors.Include(x => x.Photos).OrderByDescending(x => x.LastActive).AsQueryable();

            //Removing the loggedIn visitor from list:
            visitors = visitors.Where(x => x.Id != visitorParams.UserId);

            if (!string.IsNullOrEmpty(visitorParams.EmailText))
            {
                visitors = visitors.Where(x => x.Email.Contains(visitorParams.EmailText));
            }

            if (!string.IsNullOrEmpty(visitorParams.NameText))
            {
                visitors = visitors.Where(x => x.Email.Contains(visitorParams.NameText));
            }

            if (!string.IsNullOrEmpty(visitorParams.OrderBy))
            {
                switch (visitorParams.OrderBy)
                {
                case "asc":
                    visitors = visitors.OrderBy(x => x.LastActive);
                    break;

                default:
                    visitors = visitors.OrderByDescending(x => x.LastActive);
                    break;
                }
            }

            return(await PagedList <Visitor> .CreateAsync(visitors, visitorParams.PageNumber, visitorParams.PageSize));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetAll([FromQuery] VisitorParams visitorParams)
        {
            //Get loggedin Id
            var currentVisitorId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value);
            var currentVisitor   = await _repo.GetVisitor(currentVisitorId);

            visitorParams.UserId = currentVisitorId;

            var visitors = await _repo.GetAll(visitorParams);

            var listToReturn = _mapper.Map <IEnumerable <VisitorForListDto> >(visitors);

            Response.AddPagination(visitors.CurrentPage, visitors.PageSize, visitors.TotalCount, visitors.TotalPages);

            return(Ok(listToReturn));
        }