Beispiel #1
0
        /// <summary>
        /// Gets all users from the database.
        /// </summary>
        /// <returns>List of users, DTOs</returns>
        public async Task <IEnumerable <UserDTO> > GetAllAsync(string page, string itemsOnPage, string search)
        {
            try
            {
                var p     = int.Parse(page);
                var item  = int.Parse(itemsOnPage);
                var users = _context.Users
                            .Include(u => u.BarRatings)
                            .Include(u => u.CocktailRatings)
                            .Include(u => u.BarComments)
                            .Include(u => u.CocktailComments).AsQueryable();

                if (!string.IsNullOrEmpty(search))
                {
                    users = users.Where(u => u.UserName.Contains(search));
                }

                users = users.Skip(p * item)
                        .Take(item);

                var result = await users.ToListAsync();

                var usersDTO = result.Select(u => _mapper.MapEntityToDTO(u));

                return(usersDTO);
            }
            catch (Exception)
            {
                throw new ArgumentException("Fail to get list");
            }
        }