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
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/CategoriesController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -50,8 +51,8 @@ public ActionResult<CategoryDto[]> GetAll()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetCategoriesWithSkip")]
public ActionResult<PagedResultDto<CategoryDto>> GetCategoriesWithSkip(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/CustomersController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -50,8 +51,8 @@ public ActionResult<CustomerDto[]> GetAll()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetCustomersWithSkip")]
public ActionResult<PagedResultDto<CustomerDto>> GetCustomersWithSkip(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/EmployeesController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -68,8 +69,8 @@ public ActionResult<OrderDto[]> GetAllAuthorized()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetEmployeesWithSkip")]
public ActionResult<PagedResultDto<EmployeeDto>> GetPagedEmployees(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/OrdersController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -56,8 +57,8 @@ public ActionResult<OrderDto[]> GetAll()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetPagedOrders")]
public ActionResult<PagedResultDto<OrderDto>> GetAllOrders(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
7 changes: 4 additions & 3 deletions NorthwindCRUD/Controllers/ProductsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -70,8 +71,8 @@ public ActionResult<OrderDto[]> GetAllAuthorized()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetPagedProducts")]
public ActionResult<PagedResultDto<ProductDto>> GetAllProducts(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down Expand Up @@ -267,7 +268,7 @@ public ActionResult<ProductDto> Create(ProductDto model)
}
catch (InvalidOperationException exception)
{
return StatusCode(400, exception.Message);
return StatusCode(400, exception.Message);
}
catch (Exception error)
{
Expand Down
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/RegionsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -50,8 +51,8 @@ public ActionResult<RegionDto[]> GetAll()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetPagedRegions")]
public ActionResult<PagedResultDto<RegionDto>> GetAllRegions(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/ShippersController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -50,8 +51,8 @@ public ActionResult<ShipperDto[]> GetAll()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetPagedShippersWithSkip")]
public ActionResult<PagedResultDto<ShipperDto>> GetPagedShippersWithSkip(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/SuppliersController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -50,8 +51,8 @@ public ActionResult<SupplierDto[]> GetAll()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetPagedSuppliers")]
public ActionResult<PagedResultDto<SupplierDto>> GetAllSuppliers(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
5 changes: 3 additions & 2 deletions NorthwindCRUD/Controllers/TerritoriesController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace NorthwindCRUD.Controllers
{
using System.ComponentModel.DataAnnotations;
using AutoMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -52,8 +53,8 @@ public ActionResult<TerritoryDto[]> GetAll()
/// <returns>A PagedResultDto object containing the fetched T and the total record count.</returns>
[HttpGet("GetPagedTerritories")]
public ActionResult<PagedResultDto<TerritoryDto>> GetAllTerritories(
[FromQuery][Attributes.SwaggerSkipParameter] int? skip,
[FromQuery][Attributes.SwaggerTopParameter] int? top,
[FromQuery][Attributes.SwaggerSkipParameter][Range(0, int.MaxValue)] int? skip,
[FromQuery][Attributes.SwaggerTopParameter][Range(0, int.MaxValue)] int? top,
[FromQuery][Attributes.SwaggerOrderByParameter] string? orderBy)
{
try
Expand Down
6 changes: 6 additions & 0 deletions NorthwindCRUD/Models/Dtos/AddressDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@ namespace NorthwindCRUD.Models.Dtos
{
public class AddressDto : IAddress
{
[StringLength(100, ErrorMessage = "Street cannot exceed 100 characters.")]
public string Street { get; set; }

[StringLength(50, ErrorMessage = "City cannot exceed 50 characters.")]
public string City { get; set; }

[StringLength(50, ErrorMessage = "Region cannot exceed 50 characters.")]
public string Region { get; set; }

[StringLength(20, ErrorMessage = "Postal code cannot exceed 20 characters.")]
public string PostalCode { get; set; }

[Required(ErrorMessage = "Country is required.")]
[StringLength(50, ErrorMessage = "Country cannot exceed 50 characters.")]
public string Country { get; set; }

[RegularExpression(@"^\+?[1-9]\d{1,14}$", ErrorMessage = "Phone number is not valid.")]
public string? Phone { get; set; }
}
}
1 change: 1 addition & 0 deletions NorthwindCRUD/Models/Dtos/CategoryDetailsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace NorthwindCRUD.Models.Dtos
{
public class CategoryDetailsDto : CategoryDto, ICategoryDetail
{
[RegularExpression(@"^(http[s]?://.*\.(?:jpg|jpeg|png|gif))$", ErrorMessage = "Picture URL must start with http/s and end with .jpg, .jpeg, .png, or .gif.")]
public string Picture { get; set; }
}
}
2 changes: 2 additions & 0 deletions NorthwindCRUD/Models/Dtos/CategoryDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ public class CategoryDto : ICategory
{
public int CategoryId { get; set; }

[StringLength(500, ErrorMessage = "Description cannot exceed 500 characters.")]
public string Description { get; set; }

[Required(ErrorMessage = "Name is required.")]
[StringLength(50, MinimumLength = 3, ErrorMessage = "Name must be between 3 and 50 characters.")]
public string Name { get; set; }
}
}
3 changes: 3 additions & 0 deletions NorthwindCRUD/Models/Dtos/CustomerDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ public class CustomerDto : ICustomer
public string CustomerId { get; set; }

[Required(ErrorMessage = "Company Name is required.")]
[StringLength(100, ErrorMessage = "Company Name cannot exceed 100 characters.")]
public string CompanyName { get; set; }

[StringLength(50, ErrorMessage = "Contact Name cannot exceed 50 characters.")]
public string ContactName { get; set; }

[StringLength(50, ErrorMessage = "Contact Title cannot exceed 50 characters.")]
public string ContactTitle { get; set; }

public AddressDto Address { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions NorthwindCRUD/Models/Dtos/EmployeeDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,45 @@ public class EmployeeDto : IEmployee
public int EmployeeId { get; set; }

[Required(ErrorMessage = "Last name is required.")]
[StringLength(50, ErrorMessage = "Last name cannot exceed 50 characters.")]
[SwaggerSchema("Employee's last name.")]
public string LastName { get; set; }

[StringLength(50, ErrorMessage = "First name cannot exceed 50 characters.")]
[SwaggerSchema("Employee's first name.")]
public string FirstName { get; set; }

[StringLength(50, ErrorMessage = "Title cannot exceed 50 characters.")]
[SwaggerSchema("Employee's title")]
public string Title { get; set; }

[StringLength(50, ErrorMessage = "Title of courtesy cannot exceed 50 characters.")]
[SwaggerSchema("Title used in salutations")]
public string TitleOfCourtesy { get; set; }

[DataType(DataType.Date, ErrorMessage = "BirthDate must be a valid date.")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
[SwaggerSchema("Employee's birth date")]
public string BirthDate { get; set; }

[DataType(DataType.Date, ErrorMessage = "HireDate must be a valid date.")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
[SwaggerSchema("Employee's hire date")]
public string HireDate { get; set; }

public string AddressId { get; set; }

public AddressDto Address { get; set; }

[StringLength(1000, ErrorMessage = "Notes cannot exceed 1000 characters.")]
[SwaggerSchema("General information about employee's background.")]
public string Notes { get; set; }

[RegularExpression(@"^https?:\/\/.+\..+", ErrorMessage = "Avatar URL is not valid.")]
[SwaggerSchema("Employee's avatar url.")]
public string AvatarUrl { get; set; }

[Range(1, int.MaxValue, ErrorMessage = "ReportsTo must be a valid employee ID.")]
[SwaggerSchema("Employee's supervisor.")]
public int ReportsTo { get; set; }
}
Expand Down
2 changes: 2 additions & 0 deletions NorthwindCRUD/Models/Dtos/OrderDetailDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public class OrderDetailDto

public int ProductId { get; set; }

[Range(0.01, double.MaxValue, ErrorMessage = "Unit price must be greater than 0.")]
public double UnitPrice { get; set; }

[Range(1, int.MaxValue, ErrorMessage = "Quantity must be at least 1.")]
public int Quantity { get; set; }

public float Discount { get; set; }
Expand Down
6 changes: 6 additions & 0 deletions NorthwindCRUD/Models/Dtos/OrderDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,26 @@ public class OrderDto : IOrder
[Required(ErrorMessage = "CustomerId is required.")]
public string? CustomerId { get; set; }

[Range(1, int.MaxValue, ErrorMessage = "EmployeeId must be a valid employee ID.")]
public int EmployeeId { get; set; }

[Range(1, int.MaxValue, ErrorMessage = "ShipperId must be a valid shipper ID.")]
public int? ShipperId { get; set; }

[DataType(DataType.Date, ErrorMessage = "OrderDate must be a valid date.")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public string OrderDate { get; set; }

[DataType(DataType.Date, ErrorMessage = "RequiredDate must be a valid date.")]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy-MM-dd}")]
public string RequiredDate { get; set; }

public Shipping? ShipVia { get; set; }

[Range(0, double.MaxValue, ErrorMessage = "Freight must be a non-negative value.")]
public double Freight { get; set; }

[StringLength(100, ErrorMessage = "ShipName cannot exceed 100 characters.")]
public string ShipName { get; set; }

public bool Completed { get; set; }
Expand Down
10 changes: 9 additions & 1 deletion NorthwindCRUD/Models/Dtos/ProductDto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NorthwindCRUD.Models.Contracts;
using System.ComponentModel.DataAnnotations;
using NorthwindCRUD.Models.Contracts;

namespace NorthwindCRUD.Models.Dtos
{
Expand All @@ -8,18 +9,25 @@ public class ProductDto : IProduct

public string ProductName { get; set; }

[Range(1, int.MaxValue, ErrorMessage = "SupplierId must be a valid supplier ID.")]
public int? SupplierId { get; set; }

[Range(1, int.MaxValue, ErrorMessage = "CategoryId must be a valid category ID.")]
public int? CategoryId { get; set; }

[StringLength(100, ErrorMessage = "QuantityPerUnit cannot exceed 100 characters.")]
public string QuantityPerUnit { get; set; }

[Range(0, double.MaxValue, ErrorMessage = "UnitPrice must be a non-negative value.")]
public double? UnitPrice { get; set; }

[Range(0, 1000000000, ErrorMessage = "UnitsInStock must be a non-negative value.")]
public int? UnitsInStock { get; set; }

[Range(0, 1000000, ErrorMessage = "UnitsOnOrder must be a non-negative value.")]
public int? UnitsOnOrder { get; set; }

[Range(0, int.MaxValue, ErrorMessage = "ReorderLevel must be a non-negative value.")]
public int? ReorderLevel { get; set; }

public bool Discontinued { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions NorthwindCRUD/Models/Dtos/SalesDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ public class SalesDto
[Required(ErrorMessage = "ProductId is required.")]
public int ProductId { get; set; }

[Range(1, int.MaxValue, ErrorMessage = "QuantitySold must be at least 1.")]
public int QuantitySold { get; set; }

[Range(0.01, 1000000, ErrorMessage = "SaleAmount must be greater than 0.")]
public double SaleAmount { get; set; }
}
}
2 changes: 2 additions & 0 deletions NorthwindCRUD/Models/Dtos/ShipperDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ public class ShipperDto : IShipper
public int ShipperId { get; set; }

[Required(ErrorMessage = "Company Name is required.")]
[StringLength(100, ErrorMessage = "Company Name cannot exceed 100 characters.")]
public string CompanyName { get; set; }

[RegularExpression(@"^\+?[1-9]\d{1,14}$", ErrorMessage = "Phone number is not valid.")]
public string Phone { get; set; }
}
}
Loading