public async Task <IEnumerable <TicketDealLogEntry> > GetLogsAsync(DealLogFilter filter) { var dbModels = await Context .TicketDealLogEntries .Where(ComposeFilter(filter)) .ToListAsync() .ConfigureAwait(false); return(Mapper.Map <IEnumerable <TicketDealLogEntry> >(dbModels)); }
private Expression <Func <TicketDealLogEntryDbModel, bool> > ComposeFilter(DealLogFilter filter) { var exp = base.ComposeBaseFilter <TicketDealLogEntryDbModel>(filter); if (!string.IsNullOrWhiteSpace(filter.TicketId)) { exp = PredicateExtensions.And(exp, entry => entry.TicketId.ToLower().Contains(filter.TicketId.ToLower())); } if (!string.IsNullOrWhiteSpace(filter.OwnerId)) { exp = PredicateExtensions.And(exp, entry => entry.OwnerId.ToLower().Contains(filter.OwnerId.ToLower())); } if (!string.IsNullOrWhiteSpace(filter.RecieverId)) { exp = PredicateExtensions.And(exp, entry => entry.RecieverId.ToLower().Contains(filter.RecieverId.ToLower())); } if (filter.MinPrice.HasValue) { exp = PredicateExtensions.And(exp, entry => entry.Price >= filter.MinPrice.Value); } if (filter.MaxPrice.HasValue) { exp = PredicateExtensions.And(exp, entry => entry.Price <= filter.MaxPrice.Value); } if (filter.Type != DealType.Unknown) { exp = PredicateExtensions.And(exp, entry => filter.Type.HasFlag((DealType)entry.Type)); } return(exp); }
public async Task <IActionResult> GetTicketDealLogs([FromQuery] DealLogFilter filter) { var result = await _loggingService.GetLogsAsync(filter); return(Ok(result)); }