Merge branch 'react-version' of https://github.com/MarcEricMartel/420-5DW-HY-TP into react-version
This commit is contained in:
commit
fe5d00264d
@ -105,14 +105,16 @@ public class InventoryController : Controller {
|
|||||||
// Inventory/Delete => Décrémenter un produit.
|
// Inventory/Delete => Décrémenter un produit.
|
||||||
[EnableCors("_myAllowSpecificOrigins")]
|
[EnableCors("_myAllowSpecificOrigins")]
|
||||||
[HttpDelete(Name = "Inventory")]
|
[HttpDelete(Name = "Inventory")]
|
||||||
public void Delete(int? id) {
|
public ActionResult<int> Delete(int? id) {
|
||||||
|
int rid = 0;
|
||||||
if (!id.HasValue) {
|
if (!id.HasValue) {
|
||||||
_logger.LogError(8, "Delete sans Id.");
|
_logger.LogError(8, "Delete sans Id.");
|
||||||
return;
|
return BadRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Product prod = _context.Products.First(x => x.Id == id);
|
Product prod = _context.Products.First(x => x.Id == id);
|
||||||
|
rid = prod.Id;
|
||||||
if (prod.Quantity > 0) {
|
if (prod.Quantity > 0) {
|
||||||
prod.Quantity = prod.Quantity - 1;
|
prod.Quantity = prod.Quantity - 1;
|
||||||
if (prod.Quantity == 0)
|
if (prod.Quantity == 0)
|
||||||
@ -122,13 +124,15 @@ public class InventoryController : Controller {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_logger.LogError(8, "Vente de produit pas en stock.");
|
_logger.LogError(8, "Vente de produit pas en stock.");
|
||||||
return;
|
return BadRequest();
|
||||||
}
|
}
|
||||||
_context.Products.Update(prod);
|
_context.Products.Update(prod);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
_logger.LogError(8, e.Message);
|
_logger.LogError(8, e.Message);
|
||||||
|
return BadRequest();
|
||||||
}
|
}
|
||||||
|
return rid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,19 +1,23 @@
|
|||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
|
import { Dropdown } from "react-bootstrap";
|
||||||
|
|
||||||
const Ajouter = ({ onCreation }) => {
|
const Ajouter = ({ onCreation }) => {
|
||||||
|
|
||||||
|
const [currentStatus, setStatus] = useState("Disponible");
|
||||||
|
|
||||||
const [title, setTitle] = useState("");
|
const [title, setTitle] = useState("");
|
||||||
const [description, setDescription] = useState("");
|
const [description, setDescription] = useState("");
|
||||||
const [category, setCategory] = useState("");
|
const [category, setCategory] = useState("");
|
||||||
const [price, setPrice] = useState("");
|
const [price, setPrice] = useState("");
|
||||||
const [quantity, setQuantity] = useState("");
|
const [quantity, setQuantity] = useState("");
|
||||||
const [imageName, setImageName] = useState("sqdc.jpg");
|
const [imageName, setImageName] = useState("sqdc.jpg");
|
||||||
|
const [statusValue, setStatusValue] = useState(0)
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
e.preventDefault(); // Empêcher de reloader la page au submit.
|
e.preventDefault(); // Empêcher de reloader la page au submit.
|
||||||
|
|
||||||
// Appeler le comportement onCreation
|
// Appeler le comportement onCreation
|
||||||
onCreation({ title, description, category, price, quantity, imageName })
|
onCreation({ title, description, category, price, quantity, imageName, statusValue })
|
||||||
|
|
||||||
// Reset les états du formulaire.
|
// Reset les états du formulaire.
|
||||||
setTitle("")
|
setTitle("")
|
||||||
@ -71,6 +75,50 @@ const Ajouter = ({ onCreation }) => {
|
|||||||
value={imageName}
|
value={imageName}
|
||||||
onChange={(e) => setImageName(e.target.value)} />
|
onChange={(e) => setImageName(e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
|
<Dropdown className='status-dropdown'>
|
||||||
|
<Dropdown.Toggle id="dropdown-status">
|
||||||
|
{currentStatus}
|
||||||
|
</Dropdown.Toggle>
|
||||||
|
|
||||||
|
<Dropdown.Menu className='sorting-menu'>
|
||||||
|
<Dropdown.Item key="0" onClick={() => {
|
||||||
|
setStatus("Disponible"); // Mets le nom afficher quand le dropdown est fermé
|
||||||
|
setStatusValue(0);
|
||||||
|
}}>
|
||||||
|
Disponible {/*Le nom de l'option*/}
|
||||||
|
</Dropdown.Item>
|
||||||
|
<Dropdown.Item key="1" onClick={() => {
|
||||||
|
setStatus("Indisponible");
|
||||||
|
setStatusValue(1);
|
||||||
|
}}>
|
||||||
|
Indisponible
|
||||||
|
</Dropdown.Item>
|
||||||
|
<Dropdown.Item key="2" onClick={() => {
|
||||||
|
setStatus("En Commande");
|
||||||
|
setStatusValue(2);
|
||||||
|
}}>
|
||||||
|
En Commande
|
||||||
|
</Dropdown.Item>
|
||||||
|
<Dropdown.Item key="3" onClick={() => {
|
||||||
|
setStatus("Liquidation");
|
||||||
|
setStatusValue(3);
|
||||||
|
}}>
|
||||||
|
Liquidation
|
||||||
|
</Dropdown.Item>
|
||||||
|
<Dropdown.Item key="4" onClick={() => {
|
||||||
|
setStatus("Promotion");
|
||||||
|
setStatusValue(4);
|
||||||
|
}}>
|
||||||
|
Promotion
|
||||||
|
</Dropdown.Item>
|
||||||
|
<Dropdown.Item key="5" onClick={() => {
|
||||||
|
setStatus("Discontinué");
|
||||||
|
setStatusValue(5);
|
||||||
|
}}>
|
||||||
|
Discontinué
|
||||||
|
</Dropdown.Item>
|
||||||
|
</Dropdown.Menu>
|
||||||
|
</Dropdown>
|
||||||
|
|
||||||
<input className="btn-primary ajouter" type="submit" value="Ajouter Morceau"></input>
|
<input className="btn-primary ajouter" type="submit" value="Ajouter Morceau"></input>
|
||||||
</form>
|
</form>
|
||||||
|
@ -36,7 +36,7 @@ const Home = () => {
|
|||||||
<div className="home-text">
|
<div className="home-text">
|
||||||
<h1 className="home-title">Les Grosses Mitaines</h1>
|
<h1 className="home-title">Les Grosses Mitaines</h1>
|
||||||
<h4 className="home-subtitle">(à Ginette et Monique)</h4>
|
<h4 className="home-subtitle">(à Ginette et Monique)</h4>
|
||||||
<img src="/images/LesGrossesMitaines.png" className="home-img"/>
|
<img src="/images/LesGrossesMitaines.png" className="home-img" alt="home"/>
|
||||||
<br/>
|
<br/>
|
||||||
<h2 className="home-description">Des produits bien commodes faits par des aînées d'expérience.</h2>
|
<h2 className="home-description">Des produits bien commodes faits par des aînées d'expérience.</h2>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { json, useParams } from "react-router-dom";
|
import { useParams } from "react-router-dom";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
const MorceauDetail = () => {
|
const MorceauDetail = () => {
|
||||||
@ -18,11 +18,11 @@ const MorceauDetail = () => {
|
|||||||
}
|
}
|
||||||
fetchData();
|
fetchData();
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
},[]);
|
});
|
||||||
|
|
||||||
function renderPrice(price, newPrice, status) {
|
function renderPrice(price, newPrice, status) {
|
||||||
if (price !== undefined) {
|
if (price !== undefined) {
|
||||||
if (status != 3 && status != 4) {
|
if (status !== 3 && status !== 4) {
|
||||||
return (
|
return (
|
||||||
<h3 className="detail-price">
|
<h3 className="detail-price">
|
||||||
{price.toFixed(2).toString().replace(".", ",")} $ CA
|
{price.toFixed(2).toString().replace(".", ",")} $ CA
|
||||||
@ -99,7 +99,7 @@ const MorceauDetail = () => {
|
|||||||
|
|
||||||
<div className="detail-container">
|
<div className="detail-container">
|
||||||
<div className="detail-container-left">
|
<div className="detail-container-left">
|
||||||
<img className="detail-image" src={`/images/${item.imageName}.jpg`} />
|
<img className="detail-image" alt="" src={`/images/${item.imageName}.jpg`} />
|
||||||
<p className="detail-description">{item.description}</p>
|
<p className="detail-description">{item.description}</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="detail-container-right">
|
<div className="detail-container-right">
|
||||||
|
Loading…
Reference in New Issue
Block a user