react-version #1
@ -30,15 +30,20 @@ public class ProductController : Controller {
|
||||
}
|
||||
|
||||
[HttpPost(Name = "Product")]
|
||||
public void Post(int id, string title, string category, string description, decimal? price, uint? quantity, bool? disc, string imagename) {
|
||||
public void Post(string title, string category, string description, decimal? price, decimal? promoprice, uint? quantity, bool? disc, string imagename) {
|
||||
Product prod = new() {
|
||||
Title = title,
|
||||
Category = category,
|
||||
Description = description,
|
||||
Price = price.HasValue? (decimal)price: 0.01M,
|
||||
PromoPrice = promoprice.HasValue ? (decimal)promoprice : 0.01M,
|
||||
Quantity = quantity.HasValue ? (uint)quantity : 0,
|
||||
ImageName = imagename
|
||||
};
|
||||
|
||||
if (prod.Price <= prod.PromoPrice)
|
||||
prod.PromoPrice = prod.Price - 0.01M;
|
||||
|
||||
try {
|
||||
_context.Products.Add(prod);
|
||||
_context.SaveChanges();
|
||||
@ -48,7 +53,7 @@ public class ProductController : Controller {
|
||||
}
|
||||
|
||||
[HttpPut(Name = "Product")]
|
||||
public void Put(int id, string title, string category, string description, decimal? price, uint? quantity, string? status, string imagename) {
|
||||
public void Put(int id, string title, string category, string description, decimal? price, decimal? promoprice, uint? quantity, string? status, string imagename) {
|
||||
try {
|
||||
Product prod = _context.Products.Where(x => x.Id == id).First();
|
||||
|
||||
@ -64,6 +69,9 @@ public class ProductController : Controller {
|
||||
if (price.HasValue || price > 0)
|
||||
prod.Price = (decimal)price;
|
||||
|
||||
if (promoprice.HasValue || promoprice > prod.Price)
|
||||
prod.PromoPrice = (decimal)promoprice;
|
||||
|
||||
if (quantity.HasValue)
|
||||
prod.Quantity = (uint)quantity;
|
||||
|
||||
@ -80,6 +88,9 @@ public class ProductController : Controller {
|
||||
case "isClearance":
|
||||
prod.Status = Product.States.Clearance;
|
||||
break;
|
||||
case "isPromotion":
|
||||
prod.Status = Product.States.Promotion;
|
||||
break;
|
||||
case "isDiscontinued":
|
||||
prod.Status = Product.States.Discontinued;
|
||||
break;
|
||||
@ -97,7 +108,7 @@ public class ProductController : Controller {
|
||||
}
|
||||
|
||||
[HttpPatch(Name = "Product")]
|
||||
public void Patch(int id, string title, string category, string description, decimal? price, uint? quantity, string? status, string imagename) {
|
||||
public void Patch(int id, string title, string category, string description, decimal? price, decimal? promoprice, uint? quantity, string? status, string imagename) {
|
||||
try {
|
||||
Product prod = _context.Products.Where(x => x.Id == id).First();
|
||||
|
||||
@ -113,9 +124,9 @@ public class ProductController : Controller {
|
||||
prod.Description = description;
|
||||
else prod.Description = "";
|
||||
|
||||
if (price.HasValue || price > 0)
|
||||
prod.Price = (decimal)price;
|
||||
else prod.Price = 0.01M;
|
||||
if (promoprice.HasValue || promoprice < prod.Price)
|
||||
prod.PromoPrice = (decimal)promoprice;
|
||||
else prod.PromoPrice = prod.Price - 0.01M;
|
||||
|
||||
if (quantity.HasValue)
|
||||
prod.Quantity = (uint)quantity;
|
||||
@ -134,6 +145,9 @@ public class ProductController : Controller {
|
||||
case "isClearance":
|
||||
prod.Status = Product.States.Clearance;
|
||||
break;
|
||||
case "isPromotion":
|
||||
prod.Status = Product.States.Promotion;
|
||||
break;
|
||||
case "isDiscontinued":
|
||||
prod.Status = Product.States.Discontinued;
|
||||
break;
|
||||
|
@ -18,15 +18,19 @@ public class SearchController : Controller {
|
||||
}
|
||||
|
||||
[HttpPost(Name = "Search")]
|
||||
public IEnumerable<Product> Post(string query) {
|
||||
public IEnumerable<Product> Post(string query, bool? preview) {
|
||||
HashSet<Product> products = new();
|
||||
|
||||
query = query.Trim();
|
||||
|
||||
try { // Pour faire une liste priorisée.
|
||||
if (preview.HasValue && preview == true)
|
||||
products = _context.Products.Where(x => x.Title.Contains(query)).Take(3).ToHashSet();
|
||||
else {
|
||||
products.Concat(_context.Products.Where(x => x.Title.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Category.Contains(query)).ToHashSet());
|
||||
products.Concat(_context.Products.Where(x => x.Description.Contains(query)).ToHashSet());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_logger.LogError(8, e.Message);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace GrossesMitainesAPI.Migrations
|
||||
{
|
||||
[DbContext(typeof(InventoryContext))]
|
||||
[Migration("20221016150710_Initial-Db")]
|
||||
[Migration("20221017003248_Initial-Db")]
|
||||
partial class InitialDb
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -45,6 +45,9 @@ namespace GrossesMitainesAPI.Migrations
|
||||
b.Property<decimal>("Price")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<decimal>("PromoPrice")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<long>("Quantity")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
@ -68,6 +71,7 @@ namespace GrossesMitainesAPI.Migrations
|
||||
Description = "Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.",
|
||||
ImageName = "ceintureflechee",
|
||||
Price = 85.86m,
|
||||
PromoPrice = 0m,
|
||||
Quantity = 1L,
|
||||
Status = 4,
|
||||
Title = "Ceinture flèchée"
|
||||
@ -79,6 +83,7 @@ namespace GrossesMitainesAPI.Migrations
|
||||
Description = "Parce que ça sent la coupe!",
|
||||
ImageName = "pantouflesCH",
|
||||
Price = 15.64m,
|
||||
PromoPrice = 0m,
|
||||
Quantity = 54L,
|
||||
Status = 0,
|
||||
Title = "Pantoufles du Canadien en Phentex"
|
||||
@ -90,6 +95,7 @@ namespace GrossesMitainesAPI.Migrations
|
||||
Description = "On ne lui ferait pas mal, en tout cas!!",
|
||||
ImageName = "jeanlucmongrain",
|
||||
Price = 1453.12m,
|
||||
PromoPrice = 0m,
|
||||
Quantity = 1L,
|
||||
Status = 3,
|
||||
Title = "Jean-Luc Mongrain"
|
@ -18,6 +18,7 @@ namespace GrossesMitainesAPI.Migrations
|
||||
Category = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
PromoPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
|
||||
Quantity = table.Column<long>(type: "bigint", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
ImageName = table.Column<string>(type: "nvarchar(max)", nullable: true)
|
||||
@ -29,18 +30,18 @@ namespace GrossesMitainesAPI.Migrations
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "Products",
|
||||
columns: new[] { "Id", "Category", "Description", "ImageName", "Price", "Quantity", "Status", "Title" },
|
||||
values: new object[] { 1, "Linge", "Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.", "ceintureflechee", 85.86m, 1L, 4, "Ceinture flèchée" });
|
||||
columns: new[] { "Id", "Category", "Description", "ImageName", "Price", "PromoPrice", "Quantity", "Status", "Title" },
|
||||
values: new object[] { 1, "Linge", "Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.", "ceintureflechee", 85.86m, 0m, 1L, 4, "Ceinture flèchée" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "Products",
|
||||
columns: new[] { "Id", "Category", "Description", "ImageName", "Price", "Quantity", "Status", "Title" },
|
||||
values: new object[] { 2, "Linge", "Parce que ça sent la coupe!", "pantouflesCH", 15.64m, 54L, 0, "Pantoufles du Canadien en Phentex" });
|
||||
columns: new[] { "Id", "Category", "Description", "ImageName", "Price", "PromoPrice", "Quantity", "Status", "Title" },
|
||||
values: new object[] { 2, "Linge", "Parce que ça sent la coupe!", "pantouflesCH", 15.64m, 0m, 54L, 0, "Pantoufles du Canadien en Phentex" });
|
||||
|
||||
migrationBuilder.InsertData(
|
||||
table: "Products",
|
||||
columns: new[] { "Id", "Category", "Description", "ImageName", "Price", "Quantity", "Status", "Title" },
|
||||
values: new object[] { 3, "Homme", "On ne lui ferait pas mal, en tout cas!!", "jeanlucmongrain", 1453.12m, 1L, 3, "Jean-Luc Mongrain" });
|
||||
columns: new[] { "Id", "Category", "Description", "ImageName", "Price", "PromoPrice", "Quantity", "Status", "Title" },
|
||||
values: new object[] { 3, "Homme", "On ne lui ferait pas mal, en tout cas!!", "jeanlucmongrain", 1453.12m, 0m, 1L, 3, "Jean-Luc Mongrain" });
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
@ -43,6 +43,9 @@ namespace GrossesMitainesAPI.Migrations
|
||||
b.Property<decimal>("Price")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<decimal>("PromoPrice")
|
||||
.HasColumnType("decimal(18,2)");
|
||||
|
||||
b.Property<long>("Quantity")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
@ -66,6 +69,7 @@ namespace GrossesMitainesAPI.Migrations
|
||||
Description = "Pour faire votre propre bonhomme de 1837, comme dans le bon vieux temps.",
|
||||
ImageName = "ceintureflechee",
|
||||
Price = 85.86m,
|
||||
PromoPrice = 0m,
|
||||
Quantity = 1L,
|
||||
Status = 4,
|
||||
Title = "Ceinture flèchée"
|
||||
@ -77,6 +81,7 @@ namespace GrossesMitainesAPI.Migrations
|
||||
Description = "Parce que ça sent la coupe!",
|
||||
ImageName = "pantouflesCH",
|
||||
Price = 15.64m,
|
||||
PromoPrice = 0m,
|
||||
Quantity = 54L,
|
||||
Status = 0,
|
||||
Title = "Pantoufles du Canadien en Phentex"
|
||||
@ -88,6 +93,7 @@ namespace GrossesMitainesAPI.Migrations
|
||||
Description = "On ne lui ferait pas mal, en tout cas!!",
|
||||
ImageName = "jeanlucmongrain",
|
||||
Price = 1453.12m,
|
||||
PromoPrice = 0m,
|
||||
Quantity = 1L,
|
||||
Status = 3,
|
||||
Title = "Jean-Luc Mongrain"
|
||||
|
@ -24,6 +24,8 @@ public class Product {
|
||||
public string Description { get; set; } = "Lorem Ipsum.";
|
||||
[Required, Range(0.01, (double)decimal.MaxValue)] // Range qui prend pas les decimals!
|
||||
public decimal Price { get; set; } = 0;
|
||||
[Required, Range(0.00, (double)decimal.MaxValue)]
|
||||
public decimal PromoPrice { get; set; } = 0;
|
||||
public uint Quantity { get; set; } = 0;
|
||||
public States Status { get; set; } = States.Available;
|
||||
public string? ImageName { get; set; } // Base pour sortir les images ({ImageName}.jpg , {ImageName}_thumbnail.jpg, etc...)
|
||||
|
@ -7,6 +7,6 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=GrossesMitainesDB0; Trusted_Connection=True; MultipleActiveResultSets=true"
|
||||
"DefaultConnection": "Server=(localdb)\\mssqllocaldb; Database=GrossesMitainesDB1; Trusted_Connection=True; MultipleActiveResultSets=true"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user