Skip to content

Commit c4401c5

Browse files
committed
Addressing build errors
1 parent fa21906 commit c4401c5

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

NorthwindCRUD/Controllers/ProductsController.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NorthwindCRUD.Controllers
22
{
3+
using System.Globalization;
34
using System.Reflection;
45
using AutoMapper;
56
using Microsoft.AspNetCore.Authorization;
@@ -50,9 +51,9 @@ public ActionResult<ProductDto[]> GetAll()
5051
/// <param name="skip">Previously called pageNumber. The number of the page to fetch. If this parameter is not provided, all products are fetched.</param>
5152
/// <param name="top">Previously called pageSize. The size of the page to fetch. If this parameter is not provided, all products are fetched.</param>
5253
/// <param name="orderBy">The fields to order by, in the format "field1 asc, field2 desc". If not provided, defaults to no specific order.</param>
53-
/// <returns>A ProductDtoCollection object containing the fetched products and the total record count.</returns>
54+
/// <returns>A PagedProductsDto object containing the fetched products and the total record count.</returns>
5455
[HttpGet("GetAllPagedProducts")]
55-
public ActionResult<ProductDtoCollection> GetAllProducts(int? skip, int? top, string? orderBy)
56+
public ActionResult<PagedProductsDto> GetAllProducts(int? skip, int? top, string? orderBy)
5657
{
5758
try
5859
{
@@ -75,7 +76,7 @@ public ActionResult<ProductDtoCollection> GetAllProducts(int? skip, int? top, st
7576
var propertyInfo = products.First().GetType().GetProperty(field, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
7677

7778
// Use dynamic LINQ to sort based on field and order
78-
products = order.ToUpper() == "DESC"
79+
products = order.ToUpper(CultureInfo.InvariantCulture) == "DESC"
7980
? products.OrderByDescending(e => propertyInfo?.GetValue(e, null)).ToArray()
8081
: products.OrderBy(e => propertyInfo?.GetValue(e, null)).ToArray();
8182
}
@@ -90,15 +91,14 @@ public ActionResult<ProductDtoCollection> GetAllProducts(int? skip, int? top, st
9091
int totalPages = (int)Math.Ceiling(totalRecords / (double)currentSize);
9192

9293
// Create and return the product collection
93-
var productCollection = new ProductDtoCollection
94+
var productCollection = new PagedProductsDto
9495
{
9596
// Check if both pageNumber and pageSize are null, if so, return all products
9697
Products = this.mapper.Map<ProductDb[], ProductDto[]>(pagedProducts),
9798
TotalRecordsCount = totalRecords,
9899
PageSize = currentSize,
99100
PageNumber = (skipRecordsAmount / currentSize) + 1,
100101
TotalPages = totalPages,
101-
102102
};
103103

104104
return Ok(productCollection);

NorthwindCRUD/Models/Dtos/ProductDtoCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace NorthwindCRUD.Models.Dtos
44
{
5-
public class ProductDtoCollection
5+
public class PagedProductsDto
66
{
77
//public List<ProductDto> Products { get; set; }
88
public ICollection<ProductDto> Products { get; set; } = new List<ProductDto>();

0 commit comments

Comments
 (0)