Пример #1
0
        public string do_traslado(traslado _traslado)
        {
            var _mov_salida  = new producto_bodega();
            var _mov_entrada = new producto_bodega();

            #region preparando salida

            var bodegaInicial = db.producto_bodega.Where(x => x.idProducto == _traslado.IdProducto && x.idBodega == _traslado.IdBodegaSalida).ToList();
            if (bodegaInicial.Count() < 1)
            {
                return("no hay stock en la bodega que ha solicitado");
            }

            var bodegaFuente = bodegaInicial.First();

            if (bodegaFuente.cantidad < _traslado.Cantidad)
            {
                return("no hay stock suficiento en la bodega que ha solicitado");
            }

            bodegaFuente.cantidad       -= _traslado.Cantidad;
            db.Entry(bodegaFuente).State = EntityState.Modified;

            var bodegaDestina = db.producto_bodega.Where(x => x.idProducto == _traslado.IdProducto && x.idBodega == _traslado.IdBodegaDestino).FirstOrDefault();

            if (bodegaDestina == null)
            {
                bodegaDestina            = new producto_bodega();
                bodegaDestina.idBodega   = _traslado.IdBodegaDestino;
                bodegaDestina.cantidad   = _traslado.Cantidad;
                bodegaDestina.idProducto = _traslado.IdProducto;
                db.producto_bodega.Add(bodegaDestina);
            }
            else
            {
                bodegaDestina.cantidad       += _traslado.Cantidad;
                db.Entry(bodegaDestina).State = EntityState.Modified;
            }

            try
            {
                db.SaveChanges();
                return("ok");
            }
            catch (Exception ex)
            {
                return("ocurrio un error:" + ex.Message);
            }

            #endregion
        }
Пример #2
0
        public IHttpActionResult Postmovimiento(movimiento movimiento)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var store_movimiento = db.movimiento.Add(movimiento);

            db.SaveChanges();
            var store_producto = db.producto.Find(store_movimiento.idProducto);

            if (store_producto.stock == null)
            {
                store_producto.stock = 0;
            }

            if (movimiento.idTMovimiento == "1")
            {
                store_producto.stock += movimiento.cantidad;
            }
            else
            {
                if (store_producto.stock > movimiento.cantidad)
                {
                    store_producto.stock -= movimiento.cantidad;
                }
                else
                {
                    return(BadRequest("cantidad no funciona"));
                }
            }

            var k   = store_producto.id;
            var pbd = new producto_bodega()
            {
                idBodega     = movimiento.idBodega,
                idProducto   = k,
                idMovimiento = store_movimiento.id,
                cantidad     = store_movimiento.cantidad
            };

            db.producto_bodega.Add(pbd);
            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                string str = ex.Message;
                if (movimientoExists(movimiento.id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtRoute("DefaultApi", new { id = movimiento.id }, movimiento));
        }