public IActionResult Create(OffreEntite nouveau) { //if (ModelState.IsValid) //{ // var chaineConnexion = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename = D:\Program .NET\Foofood-master\ExempleCours\ExempleCours\Data\Data.mdf; Integrated Security = True; Connect Timeout = 30"; // try // { // using (var connection = new SqlConnection(chaineConnexion)) // { // connection.Execute("INSERT INTO Offre (Titre,Description,Url,Prix,UserId) VALUES (@Titre,@Description,@Url,@Prix,1)",nouveau); // return RedirectToAction(nameof(Index)); // } // } // catch (SqlException e) // { // return RedirectToAction(e.Message, "Home"); // } //} //return View(); if (ModelState.IsValid) { repo.Save(nouveau); return(RedirectToAction(nameof(Index))); } return(View()); }
public IActionResult Post([FromBody] OffreEntite value) { repo.Save(value); //TODO : corriger Save pour qu'il intitialise Id return(Created($"api/OffresAPI/{value.Id}", value)); }