public ActionResult Create(INVENTARIO_PDV inventario_pdv) { if (ModelState.IsValid) { db.INVENTARIO_PDV.Add(inventario_pdv); db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.ID_LIBRERIA = new SelectList(db.CATALOGO_LIBRERIA, "ID_LIBRERIA", "ID_LIBRERIA", inventario_pdv.ID_LIBRERIA); ViewBag.ID_PDV = new SelectList(db.PUNTO_VENTA, "ID_PDV", "NOMBRE", inventario_pdv.ID_PDV); return View(inventario_pdv); }
// POST api/InventarioPDVAPI public HttpResponseMessage PostINVENTARIO_PDV(int id_libreria, int id_pdv, int isbn, int cantidad_disponible) { INVENTARIO_PDV inventario_pdv = new INVENTARIO_PDV(); inventario_pdv.ID_LIBRERIA = id_libreria; inventario_pdv.ID_PDV = id_pdv; inventario_pdv.ISBN = isbn; inventario_pdv.CANTIDAD_DISPONIBLE = cantidad_disponible; if (ModelState.IsValid) { db.INVENTARIO_PDV.Add(inventario_pdv); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, inventario_pdv); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = inventario_pdv.ID_LIBRERIA })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }
// PUT api/InventarioPDVAPI/5 public HttpResponseMessage PutINVENTARIO_PDV(int id, INVENTARIO_PDV inventario_pdv) { if (!ModelState.IsValid) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } if (id != inventario_pdv.ID_LIBRERIA) { return Request.CreateResponse(HttpStatusCode.BadRequest); } db.Entry(inventario_pdv).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return Request.CreateErrorResponse(HttpStatusCode.NotFound, ex); } return Request.CreateResponse(HttpStatusCode.OK); }
// POST api/InventarioPDVAPI public HttpResponseMessage PostINVENTARIO_PDV(INVENTARIO_PDV inventario_pdv) { if (ModelState.IsValid) { db.INVENTARIO_PDV.Add(inventario_pdv); db.SaveChanges(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, inventario_pdv); response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = inventario_pdv.ID_LIBRERIA })); return response; } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } }