Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@


using CleanArchitecture.Blazor.Application.Features.Customers.DTOs;
using CleanArchitecture.Blazor.Application.Features.Customers.Queries.Pagination;

namespace CleanArchitecture.Blazor.Application.Features.Customers.Queries.Export;

Expand All @@ -11,6 +12,8 @@ public class ExportCustomersQuery : OrderableFilterBase, IRequest<Result<byte[]>
[CompareTo("Name", "Description")] // <-- This filter will be applied to Name or Description.
[StringFilterOptions(StringFilterOption.Contains)]
public string? Keyword { get; set; }
[CompareTo(typeof(SearchCustomersWithListView), "Id")]
public CustomerListView ListView { get; set; } = CustomerListView.All;
}

public class ExportCustomersQueryHandler :
Expand Down Expand Up @@ -53,17 +56,3 @@ public async Task<Result<byte[]>> Handle(ExportCustomersQuery request, Cancellat
return await Result<byte[]>.SuccessAsync(result);;
}
}


public class CustomersExportSpecification : Specification<Customer>
{
public CustomersExportSpecification(ExportCustomersQuery request)
{
Criteria = q => q.Name != null;
if (!string.IsNullOrEmpty(request.Keyword))
{
And(x => x.Name.Contains(request.Keyword));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ public class CustomersWithPaginationQuery : PaginationFilterBase, ICacheableRequ
[CompareTo("Name", "Description")] // <-- This filter will be applied to Name or Description.
[StringFilterOptions(StringFilterOption.Contains)]
public string? Keyword { get; set; }
[CompareTo(typeof(SearchCustomersWithListView), "Id")]
public CustomerListView ListView { get; set; } = CustomerListView.All; //<-- When the user selects a different ListView,
// a custom query expression is executed on the filter.
public override string ToString()
{
return $"Search:{Keyword},Sort:{Sort},SortBy:{SortBy},{Page},{PerPage}";
return $"Listview:{ListView},Search:{Keyword},Sort:{Sort},SortBy:{SortBy},{Page},{PerPage}";
}
public string CacheKey => CustomerCacheKey.GetPaginationCacheKey($"{this}");
public MemoryCacheEntryOptions? Options => CustomerCacheKey.MemoryCacheEntryOptions;
Expand Down Expand Up @@ -58,4 +61,30 @@ public CustomersPaginationSpecification(CustomersWithPaginationQuery query)
}

}
}
public class SearchCustomersWithListView : FilteringOptionsBaseAttribute
{
public override Expression BuildExpression(Expression expressionBody, PropertyInfo targetProperty, PropertyInfo filterProperty, object value)
{
var today = DateTime.Now.Date;
var start = Convert.ToDateTime(today.ToString("yyyy-MM-dd",CultureInfo.CurrentCulture) + " 00:00:00", CultureInfo.CurrentCulture);
var end = Convert.ToDateTime(today.ToString("yyyy-MM-dd",CultureInfo.CurrentCulture) + " 23:59:59", CultureInfo.CurrentCulture);
var listview = (CustomerListView)value;
return listview switch {
CustomerListView.All => expressionBody,
CustomerListView.CreatedToday => Expression.GreaterThanOrEqual(Expression.Property(expressionBody, "Created"),
Expression.Constant(start, typeof(DateTime?)))
.Combine(Expression.LessThanOrEqual(Expression.Property(expressionBody, "Created"),
Expression.Constant(end, typeof(DateTime?))),
CombineType.And),
_=> expressionBody
};
}
}
public enum CustomerListView
{
[Description("All")]
All,
[Description("Created Toady")]
CreatedToday,
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ namespace CleanArchitecture.Blazor.Application.Logs.Queries.PaginationQuery;

public class LogsWithPaginationQuery : PaginationFilterBase, ICacheableRequest<PaginatedData<LogDto>>
{
[CompareTo("Message", "Exception", "UserName", "ClientIP")]
[CompareTo("Message", "Exception", "UserName", "ClientIP")]
[StringFilterOptions(StringFilterOption.Contains)]
public string? Keyword { get; set; }

[IgnoreFilter]
public LogLevel? Level { get; set; }
[CompareTo("Level")]
[StringFilterOptions(StringFilterOption.Equals)]
public string? LevelString => Level?.ToString();
[CompareTo(typeof(SearchLogsWithListView), "Id")]
public LogListView ListView { get; set; } = LogListView.All;
public override string ToString()
{
return $"Listview:{ListView},Search:{Keyword},Sort:{Sort},SortBy:{SortBy},{Page},{PerPage}";
return $"Listview:{ListView},{LevelString},Search:{Keyword},Sort:{Sort},SortBy:{SortBy},{Page},{PerPage}";
}
public string CacheKey => LogsCacheKey.GetPaginationCacheKey($"{this}");
public MemoryCacheEntryOptions? Options => LogsCacheKey.MemoryCacheEntryOptions;
Expand Down Expand Up @@ -60,10 +64,6 @@ public override Expression BuildExpression(Expression expressionBody, PropertyIn
return listview switch
{
LogListView.All => expressionBody,
LogListView.Information => Expression.Equal(Expression.Property(expressionBody, "Level"),Expression.Constant("Information")),
LogListView.Warning => Expression.Equal(Expression.Property(expressionBody, "Level"), Expression.Constant("Warning")),
LogListView.Fatal => Expression.Equal(Expression.Property(expressionBody, "Level"), Expression.Constant("Fatal")),
LogListView.Error => Expression.Equal(Expression.Property(expressionBody, "Level"), Expression.Constant("Error")),
LogListView.Last30days => Expression.GreaterThanOrEqual(Expression.Property(expressionBody, "TimeStamp"),
Expression.Constant(last30days, typeof(DateTime)))
.Combine(Expression.LessThanOrEqual(Expression.Property(expressionBody, "TimeStamp"),
Expand All @@ -85,13 +85,5 @@ public enum LogListView
[Description("Created Toady")]
CreatedToday,
[Description("View of the last 30 days")]
Last30days,
[Description("View of Information")]
Information,
[Description("View of Warning")]
Warning,
[Description("View of Error")]
Error,
[Description("View of Fatal")]
Fatal,
Last30days
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.


using System.Reflection.Metadata;
using AutoFilterer.Extensions;
using CleanArchitecture.Blazor.Application.Features.Products.DTOs;

namespace CleanArchitecture.Blazor.Application.Features.Products.Queries.Export;
Expand All @@ -17,9 +15,11 @@ public class ExportProductsQuery : OrderableFilterBase, IRequest<Result<byte[]>>
public string? Brand { get; set; }
public string? Unit { get; set; }
public Range<decimal> Price { get; set; } = new();
[CompareTo("Name", "Brand", "Description")] // <-- This filter will be applied to Name or Brand or Description.
[CompareTo("Name", "Brand", "Description")]
[StringFilterOptions(StringFilterOption.Contains)]
public string? Keyword { get; set; }
[CompareTo(typeof(SearchProductsWithListView), "Name")]
public ProductListView ListView { get; set; } = ProductListView.All;
public ExportType ExportType { get; set; }
}

Expand Down
3 changes: 3 additions & 0 deletions src/Application/_Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
global using Microsoft.EntityFrameworkCore;
global using System.Data;
global using System.ComponentModel;
global using System.Linq.Expressions;
global using System.Globalization;
global using System.Reflection;
global using System.Linq.Dynamic.Core;
global using Microsoft.Extensions.Logging;
global using Microsoft.Extensions.Primitives;
Expand Down
Loading