private Expression <Func <TicketActionLogEntryDbModel, bool> > ComposeFilter(TicketLogsFilter filter) { var exp = base.ComposeBaseFilter <TicketActionLogEntryDbModel>(filter); if (!string.IsNullOrWhiteSpace(filter.UserId)) { exp = PredicateExtensions.And(exp, entry => entry.UserId.ToLower().Contains(filter.UserId.ToLower())); } if (!string.IsNullOrWhiteSpace(filter.TicketId)) { exp = PredicateExtensions.And(exp, entry => entry.TicketId.ToLower().Contains(filter.TicketId.ToLower())); } if (!string.IsNullOrWhiteSpace(filter.TicketName)) { exp = PredicateExtensions.And(exp, entry => entry.TicketName.ToLower().Contains(filter.TicketName.ToLower())); } if (filter.ActionType != TicketActionType.Unknown) { exp = PredicateExtensions.And(exp, entry => filter.ActionType.HasFlag((TicketActionType)entry.Type)); } if (!string.IsNullOrWhiteSpace(filter.Description)) { exp = PredicateExtensions.And(exp, entry => entry.Description.ToLower().Contains(filter.Description.ToLower())); } return(exp); }
public async Task <IEnumerable <TicketActionLogEntry> > GetLogsAsync(TicketLogsFilter filter) { var dbModels = await Context .TicketActionLogEntries .Where(ComposeFilter(filter)) .ToListAsync() .ConfigureAwait(false); return(Mapper.Map <IEnumerable <TicketActionLogEntry> >(dbModels)); }
public async Task ShouldGetFilteredEntries(string userId, string ticketId, string ticketName, TicketActionType type, string description, DateTime?dateFrom = null, DateTime?dateTo = null) { // Arrange Context.TicketActionLogEntries.AddRange(TicketActionLogEntryFaker.Generate(10)); Context.TicketActionLogEntries.Add(new TicketActionLogEntryDbModel { UserId = "alexpvt", TicketId = "ticket", TicketName = "opera aida", Type = (int)TicketActionType.Add, Description = "TicketDescription", EventDate = DateTimeNow }); await Context.SaveChangesAsync(); var filter = new TicketLogsFilter { UserId = userId, TicketId = ticketId, TicketName = ticketName, Description = description, ActionType = type, DateFrom = dateFrom, DateTo = dateTo }; // Act var entries = await _ticketLogService.GetLogsAsync(filter); // Assert entries.Count().ShouldBeEqualTo(1); var entry = entries.Single(); entry.UserId.ShouldBeEqualTo("alexpvt"); entry.TicketId.ShouldBeEqualTo("ticket"); entry.TicketName.ShouldBeEqualTo("opera aida"); entry.ActionType.ShouldBeEqualTo(TicketActionType.Add); entry.Description.ShouldBeEqualTo("TicketDescription"); entry.EventDate.ShouldBeEqualTo(DateTimeNow); }
public async Task <IActionResult> GetTicketActionLogs([FromQuery] TicketLogsFilter filter) { var result = await _loggingService.GetLogsAsync(filter); return(Ok(result)); }