This commit is contained in:
MarcEricMartel 2022-11-05 09:01:05 -07:00
parent 4608cb5de8
commit 0ffa974bd3
5 changed files with 53 additions and 28 deletions

View File

@ -38,7 +38,7 @@ public class AddressController : Controller {
#endregion #endregion
#region API Methods #region API Methods
[EnableCors("_myAllowSpecificOrigins"), HttpGet(Name = "Addresses"), Route("ListAddresses")] [EnableCors("_myAllowSpecificOrigins"), HttpGet]
public async Task<ActionResult<List<AddressModel>>> GetList(bool? all) { public async Task<ActionResult<List<AddressModel>>> GetList(bool? all) {
IList<string> roles; IList<string> roles;
InventoryUser user; InventoryUser user;
@ -69,7 +69,7 @@ public class AddressController : Controller {
} }
} }
[EnableCors("_myAllowSpecificOrigins"), HttpGet(Name = "Address")] [EnableCors("_myAllowSpecificOrigins"), HttpGet("{id}")]
public async Task<ActionResult<AddressModel>> Get(int id) { public async Task<ActionResult<AddressModel>> Get(int id) {
IList<string> roles; IList<string> roles;
string userId; string userId;
@ -103,7 +103,7 @@ public class AddressController : Controller {
else return Unauthorized(); else return Unauthorized();
} }
[EnableCors("_myAllowSpecificOrigins"), HttpPost(Name = "Address")] [EnableCors("_myAllowSpecificOrigins"), HttpPost]
public async Task<ActionResult<AddressModel>> Post(AddressModel ad) { public async Task<ActionResult<AddressModel>> Post(AddressModel ad) {
try { try {
var user = await _userMan.GetUserAsync(_signInMan.Context.User); var user = await _userMan.GetUserAsync(_signInMan.Context.User);
@ -117,7 +117,7 @@ public class AddressController : Controller {
return ad; return ad;
} }
[EnableCors("_myAllowSpecificOrigins"), HttpPatch(Name = "Address")] [EnableCors("_myAllowSpecificOrigins"), HttpPatch]
public async Task<ActionResult<AddressModel>> Patch(AddressModel ad) { public async Task<ActionResult<AddressModel>> Patch(AddressModel ad) {
IList<string> roles; IList<string> roles;
InventoryUser user; InventoryUser user;
@ -149,7 +149,7 @@ public class AddressController : Controller {
return ad; return ad;
} }
[EnableCors("_myAllowSpecificOrigins"), HttpDelete(Name = "Address")] [EnableCors("_myAllowSpecificOrigins"), HttpDelete]
public async Task<ActionResult<int>> Delete(int id) { public async Task<ActionResult<int>> Delete(int id) {
IList<string> roles; IList<string> roles;
AddressModel ad; AddressModel ad;

View File

@ -43,7 +43,7 @@ public class InvoiceController : Controller {
#endregion #endregion
#region API Methods #region API Methods
[HttpGet, Route("GetList"), Authorize(Roles = "Client, Administrateur")] [HttpGet, Authorize(Roles = "Client, Administrateur")]
public async Task<ActionResult<List<InvoiceModel>>> Get(bool? all = false) { public async Task<ActionResult<List<InvoiceModel>>> Get(bool? all = false) {
IList<string> roles; IList<string> roles;
string id; string id;
@ -67,7 +67,7 @@ public class InvoiceController : Controller {
} }
} }
[HttpGet, Route("Get"), Authorize(Roles = "Client, Administrateur")] [HttpGet("{id}"), Authorize(Roles = "Client, Administrateur")]
public async Task<ActionResult<InvoiceModel>> Get(int id) { public async Task<ActionResult<InvoiceModel>> Get(int id) {
IList<string> roles; IList<string> roles;
InvoiceModel inv; InvoiceModel inv;
@ -166,7 +166,7 @@ public class InvoiceController : Controller {
return Ok(inv); return Ok(inv);
} }
[HttpPost, Route("CancelInvoice"), Authorize(Roles = "Client, Administrateur")] [HttpPost("Cancel/{id}"), Authorize(Roles = "Client, Administrateur")]
public async Task<ActionResult<InvoiceModel>> Cancel(int id) { public async Task<ActionResult<InvoiceModel>> Cancel(int id) {
InvoiceModel inv; InvoiceModel inv;
IList<string> roles; IList<string> roles;

View File

@ -13,6 +13,7 @@ using GrossesMitainesAPI.Services;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.AspNetCore.Routing;
#endregion #endregion
/// <summary> /// <summary>
@ -44,12 +45,12 @@ public class ProductController : ControllerBase {
#endregion #endregion
#region API Methods #region API Methods
[EnableCors("_myAllowSpecificOrigins"), Route("Quantity"), HttpGet(Name = "Product"), AllowAnonymous] [EnableCors("_myAllowSpecificOrigins"), HttpGet("Quantity"), AllowAnonymous]
public ActionResult<uint> ProdCount(int id) { public ActionResult<uint> ProdCount(int id) {
return _context.Products.FirstOrDefault(x => x.Id == id).Quantity; return _context.Products.FirstOrDefault(x => x.Id == id).Quantity;
} }
[EnableCors("_myAllowSpecificOrigins"), HttpGet(Name = "Product"), AllowAnonymous] [EnableCors("_myAllowSpecificOrigins"), HttpGet(), AllowAnonymous]
public ActionResult<ProductViewModel> Get(int id) { public ActionResult<ProductViewModel> Get(int id) {
ProductModel prod; ProductModel prod;
try { try {
@ -63,7 +64,7 @@ public class ProductController : ControllerBase {
return new ProductViewModel(prod); return new ProductViewModel(prod);
} }
[EnableCors("_myAllowSpecificOrigins"), HttpPost(Name = "Product")] [EnableCors("_myAllowSpecificOrigins"), HttpPost()]
public async Task<ActionResult<ProductModel>> Post([FromForm] ProductModel prod) { public async Task<ActionResult<ProductModel>> Post([FromForm] ProductModel prod) {
if (prod.Price <= prod.PromoPrice) if (prod.Price <= prod.PromoPrice)
prod.PromoPrice = prod.Price - 0.01M; prod.PromoPrice = prod.Price - 0.01M;
@ -82,7 +83,7 @@ public class ProductController : ControllerBase {
return prod; return prod;
} }
[EnableCors("_myAllowSpecificOrigins"), HttpPatch(Name = "Product")] [EnableCors("_myAllowSpecificOrigins"), HttpPatch()]
public async Task<ActionResult<ProductModel>> Patch([FromForm] ProductModel prod) { public async Task<ActionResult<ProductModel>> Patch([FromForm] ProductModel prod) {
string? oldImage = ""; string? oldImage = "";
try { try {
@ -106,7 +107,7 @@ public class ProductController : ControllerBase {
return prod; return prod;
} }
[EnableCors("_myAllowSpecificOrigins"), HttpDelete(Name = "Product")] [EnableCors("_myAllowSpecificOrigins"), HttpDelete()]
public ActionResult<int> Delete(int id) { public ActionResult<int> Delete(int id) {
try { try {
var prod = _context.Products.Where(x => x.Id == id).First(); var prod = _context.Products.Where(x => x.Id == id).First();

View File

@ -11,6 +11,7 @@
<PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.9" /> <PackageReference Include="Microsoft.AspNet.WebApi.Core" Version="5.2.9" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" /> <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10"> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10">
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>

View File

@ -11,24 +11,47 @@ import Login from "../pages/Login";
import Logout from "../pages/Logout"; import Logout from "../pages/Logout";
import Register from "../pages/Register"; import Register from "../pages/Register";
import Formulaire from "../pages/Formulaire"; import Formulaire from "../pages/Formulaire";
import { useState, useEffect } from "react";
import React from 'react';
const UserContext = React.createContext();
const App = () => { const App = () => {
const [user, setUser] = useState(null);
useEffect(() => {
async function FetchUser() {
const response = await fetch(`https://localhost:7292/api/WhoAmI`, { credentials: 'include'});
if (response.status === 200) {
setUser(await response.json());
}
else setUser({hasCookie: false})
console.log(user)
}
if (user === null) {
FetchUser();
}
});
return ( return (
<BrowserRouter> <BrowserRouter>
<Routes> <UserContext.Provider value={user}>
<Route path="/" element={<Layout />}> <Routes>
<Route index element={<Home />} /> <Route path="/" element={<Layout />}>
<Route path="morceaux" element={<Morceaux/>} /> <Route index element={<Home />} />
<Route path="aboutUs" element={<AboutUs/>} /> <Route path="morceaux" element={<Morceaux/>} />
<Route path="contactUs" element={<ContactUs/>}/> <Route path="aboutUs" element={<AboutUs/>} />
<Route path="privacy" element={<Privacy/>}/> <Route path="contactUs" element={<ContactUs/>}/>
<Route path="morceaux/:id" element={<MorceauDetail/>}/> <Route path="privacy" element={<Privacy/>}/>
<Route path="inventaire" element={<Inventaire/>}/> <Route path="morceaux/:id" element={<MorceauDetail/>}/>
<Route path="login" element={<Login/>}/> <Route path="inventaire" element={<Inventaire/>}/>
<Route path="logout" element={<Logout/>}/> <Route path="login" element={<Login/>}/>
<Route path="register" element={<Register/>}/> <Route path="logout" element={<Logout/>}/>
<Route path="formulaire" element={<Formulaire/>}/> <Route path="register" element={<Register/>}/>
</Route> <Route path="formulaire" element={<Formulaire/>}/>
</Routes> </Route>
</Routes>
</UserContext.Provider>
</BrowserRouter> </BrowserRouter>
); );
}; };