Exemple #1
0
        public IHttpActionResult GetInsumoModel(int id)
        {
            InsumoModel insumoModel = db.InsumoModels.Find(id);

            if (insumoModel == null)
            {
                return(NotFound());
            }

            return(Ok(insumoModel));
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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)));
        }
Exemple #4
0
        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));
        }
Exemple #5
0
        //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));
        }
Exemple #6
0
        //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));
        }
Exemple #7
0
        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));
        }
Exemple #8
0
        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));
        }