Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
 public void Put(int id, [FromBody] OffreEntite value)
 {
     value.Id = id;
     repo.Save(value);
     // TODO : retourner 404 si inexistant
 }
Ejemplo n.º 3
0
 public IActionResult Post([FromBody] OffreEntite value)
 {
     repo.Save(value); //TODO : corriger Save pour qu'il intitialise Id
     return(Created($"api/OffresAPI/{value.Id}", value));
 }