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
Binary file modified .vs/AdvancedWebAPI/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/AdvancedWebAPI/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/AdvancedWebAPI/v17/.suo
Binary file not shown.
Binary file modified .vs/AdvancedWebAPI/v17/HierarchyCache.v1.txt
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/advancedwebapi.metadata.v5.2
Binary file not shown.
Binary file modified .vs/ProjectEvaluation/advancedwebapi.projects.v5.2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified AWA.MinApi/bin/Debug/net7.0/AWA.MinApi.dll
Binary file not shown.
Binary file modified AWA.MinApi/bin/Debug/net7.0/AWA.MinApi.pdb
Binary file not shown.
Binary file modified AWA.MinApi/bin/Debug/net7.0/AWA.Repository.dll
Binary file not shown.
Binary file modified AWA.MinApi/bin/Debug/net7.0/AWA.Repository.pdb
Binary file not shown.
Binary file modified AWA.MinApi/bin/Debug/net7.0/AWA.Services.dll
Binary file not shown.
Binary file modified AWA.MinApi/bin/Debug/net7.0/AWA.Services.pdb
Binary file not shown.
Binary file not shown.
Binary file modified AWA.MinApi/obj/Debug/net7.0/AWA.MinApi.dll
Binary file not shown.
Binary file modified AWA.MinApi/obj/Debug/net7.0/AWA.MinApi.pdb
Binary file not shown.
3 changes: 0 additions & 3 deletions AWA.Repository/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ public static IServiceCollection AddDIServices(this IServiceCollection services,
options.UseSqlServer(connectionString);
});
services.AddScoped<IUnitOfWork, UnitOfWork>();
//services.AddScoped<IProductRepository, ProductRepository>();
//services.AddTransient<IBusinessEntityContactRepository, BusinessEntityContactRepository>();
//services.AddTransient<IContactTypeRepository, ContactTypeRepository>();
services.AddTransient<IEmailAddressRepository, EmailAddressRepository>();
services.AddTransient<IPersonRepository, PersonRepository>();
services.AddTransient<IEmployeeRepository, EmployeeRepository>();
Expand Down
Binary file modified AWA.Repository/bin/Debug/net7.0/AWA.Repository.dll
Binary file not shown.
Binary file modified AWA.Repository/bin/Debug/net7.0/AWA.Repository.pdb
Binary file not shown.
Binary file not shown.
Binary file modified AWA.Repository/obj/Debug/net7.0/AWA.Repository.dll
Binary file not shown.
Binary file modified AWA.Repository/obj/Debug/net7.0/AWA.Repository.pdb
Binary file not shown.
5 changes: 5 additions & 0 deletions AWA.Services/PersonParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
{
public class PersonParameters : QueryStringParameters
{
public PersonParameters()
{
OrderBy= "FullName";
}
public uint? MinYearOfBirth { get; set; }
public uint? MaxYearOfBirth { get; set; } = (uint)DateTime.Now.Year;
public bool ValidYearRange => (MaxYearOfBirth == null & MinYearOfBirth == null) || (MaxYearOfBirth > MinYearOfBirth);
public string? Name { get; internal set; } = "";
public string? JobTitle { get; internal set; } = "";
public string OrderBy { get; set; }
}
}
45 changes: 41 additions & 4 deletions AWA.Services/PersonService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using AWA.Domain.Interfaces;
using AWA.Models;
using AWA.Services.Interfaces;
using System.Reflection;
using System.Text;

namespace AWA.Services
{
Expand Down Expand Up @@ -39,17 +41,52 @@ join e in emailAddress on p.BusinessEntityId equals e.BusinessEntityId

public PagedList<DTOPeople> GetPagedPeople(PersonParameters personParameters)
{
var allPeople = GetAllPeople().Result.AsQueryable<DTOPeople>().OrderBy(so => so.FullName);
var allPeople = GetAllPeople().Result.AsQueryable<DTOPeople>();
var allPeopleSorted = OrderPeople(allPeople, personParameters.OrderBy);
if (personParameters.MinYearOfBirth != null && personParameters.MaxYearOfBirth != null)
{
allPeople = (IOrderedQueryable<DTOPeople>)allPeople
allPeopleSorted = (IOrderedQueryable<DTOPeople>)allPeopleSorted
.Where(o => o.BirthDate.Year >= personParameters.MinYearOfBirth && o.BirthDate.Year <= personParameters.MaxYearOfBirth);
}
SearchPeople(ref allPeople, personParameters.Name, personParameters.JobTitle);
SearchPeople(allPeopleSorted, personParameters.Name, personParameters.JobTitle);
return PagedList<DTOPeople>.ToPagedList(allPeople, personParameters.PageNumber, personParameters.PageSize);
}

private void SearchPeople(ref IOrderedQueryable<DTOPeople> allPeople, string? name, string? jobTitle)
private IOrderedQueryable<DTOPeople> OrderPeople(IQueryable<DTOPeople> allPeople, string orderBy)
{
IOrderedQueryable < DTOPeople > allPeopleOrdered= (IOrderedQueryable<DTOPeople>)allPeople;
if (!allPeople.Any())
{
return allPeopleOrdered;
}
if (string.IsNullOrWhiteSpace(orderBy))
{
allPeopleOrdered.OrderBy(p => p.FullName);
return allPeopleOrdered;
}
var orderParameters = orderBy.Trim().Split(',');
var propertyInfos = typeof(DTOPeople).GetProperties(BindingFlags.Public | BindingFlags.Instance);
var orderQueryBuilder = new StringBuilder();
foreach (var orderParam in orderParameters)
{
if (string.IsNullOrWhiteSpace(orderParam)) continue;
var propertyQuery = orderParam.Split(' ')[0];
var objectProperty = propertyInfos.FirstOrDefault(pi => pi.Name.Equals(propertyQuery, StringComparison.InvariantCultureIgnoreCase));
if (objectProperty == null) continue;
var sortingOrder = orderParam.EndsWith(" desc") ? "descending" : "ascending";
var sortField = objectProperty.Name.ToString();
if (!string.IsNullOrWhiteSpace(sortField))
{
var sortFieldOrder = $"{sortField} {sortingOrder}";
allPeopleOrdered = allPeopleOrdered.OrderBy(p => sortFieldOrder);
}
}
return allPeopleOrdered;

}


private void SearchPeople(IOrderedQueryable<DTOPeople> allPeople, string? name, string? jobTitle)
{
if (allPeople.Any() == false) return;
if (string.IsNullOrWhiteSpace(name) && string.IsNullOrWhiteSpace(jobTitle)) return;
Expand Down
Binary file modified AWA.Services/bin/Debug/net7.0/AWA.Services.dll
Binary file not shown.
Binary file modified AWA.Services/bin/Debug/net7.0/AWA.Services.pdb
Binary file not shown.
Binary file not shown.
Binary file modified AWA.Services/obj/Debug/net7.0/AWA.Services.dll
Binary file not shown.
Binary file modified AWA.Services/obj/Debug/net7.0/AWA.Services.pdb
Binary file not shown.
Binary file modified AWA.Services/obj/Debug/net7.0/ref/AWA.Services.dll
Binary file not shown.
Binary file modified AWA.Services/obj/Debug/net7.0/refint/AWA.Services.dll
Binary file not shown.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,10 +296,6 @@ dotnet tool install --global dotnet-ef
dotnet tool update --global dotnet-ef


BusinessEntityContactRepository
ContactTypeRepository
PersonRepository
EmailAddressRepository

https://code-maze.com/paging-aspnet-core-webapi/
https://code-maze.com/filtering-aspnet-core-webapi/
Expand Down