Beispiel #1
0
        public async Task <IActionResult> PutFormulaProducto(int id, FormulaProducto formulaProducto)
        {
            if (id != formulaProducto.Id)
            {
                return(BadRequest());
            }
            _context.Entry(formulaProducto).State = EntityState.Modified;

            foreach (DetalleFormula detalle in formulaProducto.DetallesFormula)
            {
                if (detalle.Id == 0)
                {
                    _context.Entry(detalle).State = EntityState.Added;
                }
                else
                {
                    _context.Entry(detalle).State = EntityState.Modified;
                }
            }

            var detallesId      = formulaProducto.DetallesFormula.Select(x => x.Id).ToList();
            var detallesABorrar = _context.detalleFormula.Where(x => !detallesId.Contains(x.Id) && x.FormulaProductoId == formulaProducto.Id).ToList();

            _context.detalleFormula.RemoveRange(detallesABorrar);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FormulaProductoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
        public async Task <ActionResult <FormulaProducto> > PostFormulaProducto(FormulaProducto formulaProducto)
        {
            try
            {
                formulaProducto.DetallesFormula.ForEach(x => {
                    x.ProductoPresentacion.PresentacionProducto = null;

                    _context.Entry(x.ProductoPresentacion).State          = EntityState.Unchanged;
                    _context.Entry(x.ProductoPresentacion.Producto).State = EntityState.Unchanged;
                });
                _context.FormulaProducto.Add(formulaProducto);



                await _context.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                throw;
            }

            return(CreatedAtAction("GetFormulaProducto", new { id = formulaProducto.Id }, formulaProducto));
        }
Beispiel #3
0
 public async Task EliminarFormulaProducto(FormulaProducto formula)
 {
     await http.DeleteAsync($"api/formulaProducto/{formula.Id}");
 }