From 94567c2395c05f49c3666b6e2851fbfff2e2b148 Mon Sep 17 00:00:00 2001 From: MarcEricMartel <74071476+MarcEricMartel@users.noreply.github.com> Date: Sun, 13 Nov 2022 17:54:56 -0800 Subject: [PATCH] Update InvoiceController.cs --- .../Controllers/InvoiceController.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs b/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs index 39152b0..e35881a 100644 --- a/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs +++ b/GrossesMitaines/GrossesMitainesAPI/Controllers/InvoiceController.cs @@ -103,8 +103,8 @@ public class InvoiceController : Controller { } [HttpPost, AllowAnonymous] - public async Task> Post(SendInvoiceModel sinv) { - var user = await _userMan.GetUserAsync(_signInMan.Context.User); + public ActionResult Post(SendInvoiceModel sinv) { + var user = _userMan.GetUserAsync(_signInMan.Context.User); var prodcom = sinv.ProdQuant; Dictionary badprods = new(); List prods; @@ -116,9 +116,10 @@ public class InvoiceController : Controller { PurchaseDate = DateTime.Now }; AddressModel ad; + user.Wait(); - if (user is not null) { - inv.LinkedAccount = user; + if (user.Result is not null) { + inv.LinkedAccount = user.Result; ad = _context.Addresses.FirstOrDefault(x => x.CivicNumber == sinv.CivicNumber && x.Appartment == sinv.Appartment && x.Street == sinv.Street && @@ -175,7 +176,8 @@ public class InvoiceController : Controller { return BadRequest(badprods.ToArray()); try { // Faire les updates dans la BD. - _context.Addresses.Add(ad); + if (ad.Id == 0) + _context.Addresses.Add(ad); _context.Invoices.Add(inv); _context.Products.UpdateRange(prods); _context.SaveChanges();