public static IQueryable <TShirt> Filter(this IQueryable <TShirt> tshirts, TshirtParameters tshirtParameters) { return(tshirts.Where(c => (string.IsNullOrWhiteSpace(tshirtParameters.Gender) || c.Gender.Name == tshirtParameters.Gender) && (string.IsNullOrWhiteSpace(tshirtParameters.Category) || c.Category.Name == tshirtParameters.Category) && (string.IsNullOrWhiteSpace(tshirtParameters.Author) || c.User.Email == tshirtParameters.Author))); }
public async Task <IActionResult> GetByAuthorName(string name, [FromQuery] TshirtParameters tshirtParameters) { if (string.IsNullOrEmpty(name)) { _logger.LogError("User name send from client is null or empty."); return(BadRequest("User name is null or empty.")); } var author = _userManager.Users.FirstOrDefault(c => c.DisplayName.Equals(name)); if (author is null) { _logger.LogError($"User with name {name} not found."); return(BadRequest($"User with name {name} not found.")); } tshirtParameters.Author = author.Email; var tshirtsWithMetadata = await _tshirtService.GetTShirtsAsync(tshirtParameters); SetResponseHeaders(tshirtsWithMetadata.MetaData); var tshirts = _mapper.Map <IEnumerable <TShirtToReturnDTO> >(tshirtsWithMetadata); _logger.LogInfo($"T-shirts received from the author with the name: {name}."); return(Ok(tshirts)); }
public async Task <PagedList <TShirt> > GetTShirtListAsync(TshirtParameters tshirtParameters, bool trackChanges) => PagedList <TShirt> .ToPagedList(await FindAll(trackChanges) .Filter(tshirtParameters) .Sort(tshirtParameters.OrderBy) .Search(tshirtParameters.SearchTerm) .Include(c => c.Category) .Include(g => g.Gender) .Include(u => u.User) .ToListAsync(), tshirtParameters.PageNumber, tshirtParameters.PageSize);
public async Task <IActionResult> GetTShirts([FromQuery] TshirtParameters tshirtParameters) { var tshirtsWithMetadata = await _tshirtService.GetTShirtsAsync(tshirtParameters); SetResponseHeaders(tshirtsWithMetadata.MetaData); var tshirtsPage = _mapper.Map <IEnumerable <TShirtToReturnDTO> >(tshirtsWithMetadata); if (tshirtsPage is null) { _logger.LogError($"T-Shirts not found."); return(NoContent()); } _logger.LogInfo($"Get T-Shirts successes."); return(Ok(tshirtsPage)); }
public async Task <IActionResult> GetByCurrentUser([FromQuery] TshirtParameters tshirtParameters) { var email = GetEmailFromHttpContextAsync(); tshirtParameters.Author = email; var tshirtsWithMetadata = await _tshirtService.GetTShirtsAsync(tshirtParameters); SetResponseHeaders(tshirtsWithMetadata.MetaData); var tshirts = _mapper.Map <IEnumerable <TShirtToReturnDTO> >(tshirtsWithMetadata); if (tshirts is null) { _logger.LogError($"T-Shirts not found."); return(NoContent()); } _logger.LogInfo($"Received a t-shirt for user with email: {email}."); return(Ok(tshirts)); }
public async Task <PagedList <TShirt> > GetTShirtsAsync(TshirtParameters tshirtParameters) => await _repositoryManager.Tshirt .GetTShirtListAsync(tshirtParameters, false);