public IHttpActionResult GetInsumoModel(int id) { InsumoModel insumoModel = db.InsumoModels.Find(id); if (insumoModel == null) { return(NotFound()); } return(Ok(insumoModel)); }
public IHttpActionResult PostInsumoModel(InsumoModel insumoModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.InsumoModels.Add(insumoModel); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = insumoModel.id }, insumoModel)); }
public async Task <IActionResult> EditarInsumo(InsumoModel model) { if (HttpContext.Session.GetString("Logueo") != "Si") { HttpContext.Session.SetString("MensajeError", "Su sesión expiró."); return(RedirectToAction("Login", "Home")); } _context.Update(model.oInsumo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public IHttpActionResult DeleteInsumoModel(int id) { InsumoModel insumoModel = db.InsumoModels.Find(id); if (insumoModel == null) { return(NotFound()); } db.InsumoModels.Remove(insumoModel); db.SaveChanges(); return(Ok(insumoModel)); }
//GET: Insumo/Edit public async Task <IActionResult> Edit(int IdInsumo) { if (HttpContext.Session.GetString("Logueo") != "Si") { HttpContext.Session.SetString("MensajeError", "Su sesión expiró."); return(RedirectToAction("Login", "Home")); } InsumoModel model = new InsumoModel(); model.oInsumo = await _context.Insumo.FindAsync(IdInsumo); ViewData["UnidadMedida"] = new SelectList(_context.Unidadmedida, "IdMedida", "NombreLargo"); return(View(model)); }
//GET: Insumo public async Task <IActionResult> Index() { if (HttpContext.Session.GetString("Logueo") != "Si") { HttpContext.Session.SetString("MensajeError", "Su sesión expiró."); return(RedirectToAction("Login", "Home")); } InsumoModel model = new InsumoModel(); model.listInsumo = await _context.Insumo.ToListAsync(); model.listUnidadmedida = await _context.Unidadmedida.ToListAsync(); return(View(model)); }
public IHttpActionResult PostUpdateStock(InsumoModel insumoModel) { var insumoToUpdate = db.InsumoModels.SingleOrDefault(x => x.id == insumoModel.id); insumoToUpdate.Stock -= insumoModel.Stock; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(BadRequest(ex.Message)); } return(StatusCode(HttpStatusCode.OK)); }
public IHttpActionResult PutInsumoModel([FromBody] InsumoModel insumoModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Entry(insumoModel).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { return(BadRequest(ex.Message)); } return(StatusCode(HttpStatusCode.OK)); }