Ejemplo n.º 1
0
 public IActionResult Post([FromBody] Producto value)
 {
     if (value.Tienda != null)
     {
         var tienda = context.Tienda.Find(value.Tienda.Id);
         if (tienda != null)
         {
             value.Tienda = tienda;
         }
         else
         {
             value.Tienda = new Tienda()
             {
                 Nombre    = value.Tienda.Nombre,
                 Direccion = value.Tienda.Direccion
             };
         }
     }
     context.Add(value);
     try
     {
         context.SaveChanges();
         value.Tienda = null;
         return(Created("", value));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }
Ejemplo n.º 2
0
 public IActionResult Post([FromBody] Tienda value)
 {
     context.Add(value);
     try
     {
         context.SaveChanges();
         return(Created("", value));
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
 }