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 modified .vs/AdvancedWebAPI/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions AWA.MinApi/AWA.MinApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

Expand Down
22 changes: 20 additions & 2 deletions AWA.MinApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
using AWA.Repository;
using AWA.Services;
using AWA.Services.Interfaces;
using Azure;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;


var builder = WebApplication.CreateBuilder(args);

Expand All @@ -25,8 +29,22 @@
app.MapGet("/getAllPeople", async (IPersonService personService) =>
{
return await personService.GetAllPeople();
});

});
app.MapGet("/getPagedPeople", (HttpContext http, IPersonService personService, [AsParameters] PersonParameters personParameters) =>
{
var pagedPeople= personService.GetPagedPeople(personParameters);
var metadata = new
{
pagedPeople.TotalCount,
pagedPeople.PageSize,
pagedPeople.CurrentPage,
pagedPeople.TotalPages,
pagedPeople.HasNext,
pagedPeople.HasPrevious
};
http.Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata));
return pagedPeople;
});


app.Run();
Expand Down
16 changes: 16 additions & 0 deletions AWA.MinApi/bin/Debug/net7.0/AWA.MinApi.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"AWA.Repository": "1.0.0",
"AWA.Services": "1.0.0",
"Microsoft.AspNetCore.OpenApi": "7.0.0",
"Newtonsoft.Json": "13.0.2",
"Swashbuckle.AspNetCore": "6.4.0"
},
"runtime": {
Expand Down Expand Up @@ -359,6 +360,14 @@
}
}
},
"Newtonsoft.Json/13.0.2": {
"runtime": {
"lib/net6.0/Newtonsoft.Json.dll": {
"assemblyVersion": "13.0.0.0",
"fileVersion": "13.0.2.27524"
}
}
},
"Swashbuckle.AspNetCore/6.4.0": {
"dependencies": {
"Microsoft.Extensions.ApiDescription.Server": "6.0.5",
Expand Down Expand Up @@ -910,6 +919,13 @@
"path": "microsoft.win32.systemevents/5.0.0",
"hashPath": "microsoft.win32.systemevents.5.0.0.nupkg.sha512"
},
"Newtonsoft.Json/13.0.2": {
"type": "package",
"serviceable": true,
"sha512": "sha512-R2pZ3B0UjeyHShm9vG+Tu0EBb2lC8b0dFzV9gVn50ofHXh9Smjk6kTn7A/FdAsC8B5cKib1OnGYOXxRBz5XQDg==",
"path": "newtonsoft.json/13.0.2",
"hashPath": "newtonsoft.json.13.0.2.nupkg.sha512"
},
"Swashbuckle.AspNetCore/6.4.0": {
"type": "package",
"serviceable": true,
Expand Down
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.Services.dll
Binary file not shown.
Binary file modified AWA.MinApi/bin/Debug/net7.0/AWA.Services.pdb
Binary file not shown.
Binary file added AWA.MinApi/bin/Debug/net7.0/Newtonsoft.Json.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions AWA.MinApi/obj/AWA.MinApi.csproj.nuget.dgspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@
"target": "Package",
"version": "[7.0.0, )"
},
"Newtonsoft.Json": {
"target": "Package",
"version": "[13.0.2, )"
},
"Swashbuckle.AspNetCore": {
"target": "Package",
"version": "[6.4.0, )"
Expand Down
Binary file modified AWA.MinApi/obj/Debug/net7.0/AWA.MinApi.assets.cache
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
c02755da57ca0743993d14a76a621370a73c5c11
4cefa2fe1ba7fb32a5c6f60d3749b057d7a0059f
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ C:\Elio\Development\Projects\AdvancedWebAPI\AWA.MinApi\bin\Debug\net7.0\AWA.Serv
C:\Elio\Development\Projects\AdvancedWebAPI\AWA.MinApi\bin\Debug\net7.0\AWA.DataAccess.pdb
C:\Elio\Development\Projects\AdvancedWebAPI\AWA.MinApi\bin\Debug\net7.0\AWA.Domain.pdb
C:\Elio\Development\Projects\AdvancedWebAPI\AWA.MinApi\bin\Debug\net7.0\AWA.Models.pdb
C:\Elio\Development\Projects\AdvancedWebAPI\AWA.MinApi\bin\Debug\net7.0\Newtonsoft.Json.dll
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.
Binary file modified AWA.MinApi/obj/Debug/net7.0/ref/AWA.MinApi.dll
Binary file not shown.
Binary file modified AWA.MinApi/obj/Debug/net7.0/refint/AWA.MinApi.dll
Binary file not shown.
48 changes: 48 additions & 0 deletions AWA.MinApi/obj/project.assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,19 @@
}
}
},
"Newtonsoft.Json/13.0.2": {
"type": "package",
"compile": {
"lib/net6.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
},
"runtime": {
"lib/net6.0/Newtonsoft.Json.dll": {
"related": ".xml"
}
}
},
"Swashbuckle.AspNetCore/6.4.0": {
"type": "package",
"dependencies": {
Expand Down Expand Up @@ -2333,6 +2346,36 @@
"version.txt"
]
},
"Newtonsoft.Json/13.0.2": {
"sha512": "R2pZ3B0UjeyHShm9vG+Tu0EBb2lC8b0dFzV9gVn50ofHXh9Smjk6kTn7A/FdAsC8B5cKib1OnGYOXxRBz5XQDg==",
"type": "package",
"path": "newtonsoft.json/13.0.2",
"files": [
".nupkg.metadata",
".signature.p7s",
"LICENSE.md",
"README.md",
"lib/net20/Newtonsoft.Json.dll",
"lib/net20/Newtonsoft.Json.xml",
"lib/net35/Newtonsoft.Json.dll",
"lib/net35/Newtonsoft.Json.xml",
"lib/net40/Newtonsoft.Json.dll",
"lib/net40/Newtonsoft.Json.xml",
"lib/net45/Newtonsoft.Json.dll",
"lib/net45/Newtonsoft.Json.xml",
"lib/net6.0/Newtonsoft.Json.dll",
"lib/net6.0/Newtonsoft.Json.xml",
"lib/netstandard1.0/Newtonsoft.Json.dll",
"lib/netstandard1.0/Newtonsoft.Json.xml",
"lib/netstandard1.3/Newtonsoft.Json.dll",
"lib/netstandard1.3/Newtonsoft.Json.xml",
"lib/netstandard2.0/Newtonsoft.Json.dll",
"lib/netstandard2.0/Newtonsoft.Json.xml",
"newtonsoft.json.13.0.2.nupkg.sha512",
"newtonsoft.json.nuspec",
"packageIcon.png"
]
},
"Swashbuckle.AspNetCore/6.4.0": {
"sha512": "eUBr4TW0up6oKDA5Xwkul289uqSMgY0xGN4pnbOIBqCcN9VKGGaPvHX3vWaG/hvocfGDP+MGzMA0bBBKz2fkmQ==",
"type": "package",
Expand Down Expand Up @@ -3714,6 +3757,7 @@
"AWA.Repository >= 1.0.0",
"AWA.Services >= 1.0.0",
"Microsoft.AspNetCore.OpenApi >= 7.0.0",
"Newtonsoft.Json >= 13.0.2",
"Swashbuckle.AspNetCore >= 6.4.0"
]
},
Expand Down Expand Up @@ -3771,6 +3815,10 @@
"target": "Package",
"version": "[7.0.0, )"
},
"Newtonsoft.Json": {
"target": "Package",
"version": "[13.0.2, )"
},
"Swashbuckle.AspNetCore": {
"target": "Package",
"version": "[6.4.0, )"
Expand Down
3 changes: 2 additions & 1 deletion AWA.MinApi/obj/project.nuget.cache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 2,
"dgSpecHash": "KED/6VYa5wPx5QJ0iqVsfBy1vPeXGeP/IobTX7LXK4f7fHw5whyDU+ATVF5t3Su6s0zkSeECQ28njeT/uRC2kA==",
"dgSpecHash": "gXDyhBHdpkkkvy1fulFi8ktoI2yTEitcpynKUaIn9nHa/P4X6uhenWfKzx9Q20/MnB0t5MMJ0/IriiP90k4PmQ==",
"success": true,
"projectFilePath": "C:\\Elio\\Development\\Projects\\AdvancedWebAPI\\AWA.MinApi\\AWA.MinApi.csproj",
"expectedPackageFiles": [
Expand Down Expand Up @@ -40,6 +40,7 @@
"C:\\Users\\elio_\\.nuget\\packages\\microsoft.sqlserver.server\\1.0.0\\microsoft.sqlserver.server.1.0.0.nupkg.sha512",
"C:\\Users\\elio_\\.nuget\\packages\\microsoft.win32.registry\\5.0.0\\microsoft.win32.registry.5.0.0.nupkg.sha512",
"C:\\Users\\elio_\\.nuget\\packages\\microsoft.win32.systemevents\\5.0.0\\microsoft.win32.systemevents.5.0.0.nupkg.sha512",
"C:\\Users\\elio_\\.nuget\\packages\\newtonsoft.json\\13.0.2\\newtonsoft.json.13.0.2.nupkg.sha512",
"C:\\Users\\elio_\\.nuget\\packages\\swashbuckle.aspnetcore\\6.4.0\\swashbuckle.aspnetcore.6.4.0.nupkg.sha512",
"C:\\Users\\elio_\\.nuget\\packages\\swashbuckle.aspnetcore.swagger\\6.4.0\\swashbuckle.aspnetcore.swagger.6.4.0.nupkg.sha512",
"C:\\Users\\elio_\\.nuget\\packages\\swashbuckle.aspnetcore.swaggergen\\6.4.0\\swashbuckle.aspnetcore.swaggergen.6.4.0.nupkg.sha512",
Expand Down
Binary file not shown.
10 changes: 3 additions & 7 deletions AWA.Services/Interfaces/IPersonService.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AWA.Services.Interfaces
namespace AWA.Services.Interfaces
{
public interface IPersonService
{
Task<IEnumerable<DTOPeople>> GetAllPeople();

PagedList<DTOPeople> GetPagedPeople(PersonParameters personParameters);
}

}
31 changes: 31 additions & 0 deletions AWA.Services/PagedList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace AWA.Services
{
public class PagedList<T> : List<T>
{
public int CurrentPage { get; private set; }
public int TotalPages { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }

public bool HasPrevious => CurrentPage > 1;
public bool HasNext => CurrentPage < TotalPages;

public PagedList(List<T> items, int count, int pageNumber, int pageSize)
{
TotalCount = count;
PageSize = pageSize;
CurrentPage = pageNumber;
TotalPages = (int)Math.Ceiling(count / (double)pageSize);

AddRange(items);
}

public static PagedList<T> ToPagedList(IQueryable<T> source, int pageNumber, int pageSize)
{
var count = source.Count();
var items = source.Skip((pageNumber - 1) * pageSize).Take(pageSize).ToList();

return new PagedList<T>(items, count, pageNumber, pageSize);
}
}
}
12 changes: 12 additions & 0 deletions AWA.Services/PersonParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AWA.Services
{
public class PersonParameters:QueryStringParameters
{
}
}
27 changes: 21 additions & 6 deletions AWA.Services/PersonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,32 @@ public PersonService(IUnitOfWork unitOfWork)
}
public async Task<IEnumerable<DTOPeople>> GetAllPeople()
{
var businessEntityContact =await _unitOfWork.BusinessEntityContacts.GetAll();
var contactType=await _unitOfWork.ContactTypes.GetAll();
var people=await _unitOfWork.People.GetAll();
var emailAddress =await _unitOfWork.EmailAddresses.GetAll();
var businessEntityContact = await _unitOfWork.BusinessEntityContacts.GetAll();
var contactType = await _unitOfWork.ContactTypes.GetAll();
var people = await _unitOfWork.People.GetAll();
var emailAddress = await _unitOfWork.EmailAddresses.GetAll();
var result = (from b in businessEntityContact
join c in contactType on b.ContactTypeId equals c.ContactTypeId
join p in people on b.PersonId equals p.BusinessEntityId
join e in emailAddress on p.BusinessEntityId equals e.BusinessEntityId
select new DTOPeople {BusinessEntityId= b.BusinessEntityId,Name= c.Name,Title= p.Title,FirstName= p.FirstName,LastName= p.LastName,EmailAddress= e.EmailAddress1 }
select new DTOPeople { BusinessEntityId = b.BusinessEntityId, Name = c.Name, Title = p.Title, FirstName = p.FirstName, LastName = p.LastName, EmailAddress = e.EmailAddress1 }
);
return result;
}
}

//public PagedList<DTOPeople> GetPagedPeople(PersonParameters personParameters)
//{
// var allPeople = GetAllPeople().Result.ToList<DTOPeople>();
// int totalRecords = allPeople.Count();
// //var items = allPeople.Skip((personParameters.PageNumber - 1) * personParameters.PageSize).Take(personParameters.PageSize).ToList();
// var result = new PagedList<DTOPeople>(allPeople, totalRecords, personParameters.PageNumber, personParameters.PageSize);
// return result.top;

//}
public PagedList<DTOPeople> GetPagedPeople(PersonParameters personParameters)
{
var allPeople = GetAllPeople().Result.AsQueryable<DTOPeople>();
return PagedList<DTOPeople>.ToPagedList(allPeople, personParameters.PageNumber, personParameters.PageSize);
}
}
}
20 changes: 20 additions & 0 deletions AWA.Services/QueryStringParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace AWA.Services
{
public abstract class QueryStringParameters
{
const int maxPageSize = 50;
public int PageNumber { get; set; } = 1;
private int _pageSize = 10;
public int PageSize
{
get
{
return _pageSize;
}
set
{
_pageSize = (value > maxPageSize) ? maxPageSize : value;
}
}
}
}
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.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9aa7e5066d30174c20b36dcfa1994a2fd00afcfb
3745da8ae68b57e8032a03c066d03fba8564a786
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.