Esempio n. 1
0
        public Mercaderia(string NombreFantasia, string Direccion, string Separador, Modelo.Mercaderia mercaderia)
        {
            Texto nombreFantasia = new Texto(NombreFantasia, StringAlignment.Center);

            AgregarLinea(Cabecera1, nombreFantasia);

            Texto direccion = new Texto(Direccion, StringAlignment.Center);

            AgregarLinea(Cabecera2, direccion);

            AgregarLineaSeparador(cuerpo1, Separador);

            Texto titulo = new Texto("Mercadería", StringAlignment.Center);

            AgregarLinea(Cabecera2, titulo);
            Texto proveedor = new Texto($"Prov: {mercaderia.Proveedor.RazonSocial}", StringAlignment.Center);

            AgregarLinea(Cabecera2, proveedor);

            Texto fecha = new Texto($"Fecha:{mercaderia.Fecha.ToString("dd/MM/yyyy")}", StringAlignment.Near, 0.5f);
            Texto hora  = new Texto($"Hora:{mercaderia.Fecha.ToString("HH:mm:ss")}", StringAlignment.Far, 0.5f);

            AgregarLinea(cuerpo1, fecha, hora);

            AgregarLineaSeparador(cuerpo1, Separador);

            IList <(string, string, int)> productos = mercaderia.MercaderiaItems.Select(x => (x.Producto.Codigo, x.Producto.Descripcion, x.Cantidad)).ToList();

            AgregarMovimientos(productos, "Productos");
        }
Esempio n. 2
0
        internal async Task <int> Ingresar(Modelo.Mercaderia mercaderia)
        {
            Modelo.Mercaderia mercaderaDB = _context.Mercaderia
                                            .FirstOrDefault(x => x.Id == mercaderia.Id);

            mercaderia.MercaderiaItems.ToList().ForEach(x =>
            {
                Modelo.Producto producto = _context.Producto.FirstOrDefault(y => y.Id == x.Producto.Id);
                producto.AgregarStock(x.Cantidad);
            });

            return(await _context.SaveChangesAsync());
        }
Esempio n. 3
0
        internal async Task <int> Guardar(Modelo.Mercaderia mercaderia)
        {
            if (mercaderia.Id == 0)
            {
                _context.Entry(mercaderia.Proveedor).State = EntityState.Unchanged;
                mercaderia.MercaderiaItems.ToList().ForEach(x => _context.Entry(x.Producto).State = EntityState.Unchanged);

                _context.Mercaderia.Add(mercaderia);
            }
            else
            {
                Modelo.Mercaderia mercaderaDB = await _context.Mercaderia
                                                .Include(x => x.MercaderiaItems.Select(y => y.Producto))
                                                .FirstOrDefaultAsync(x => x.Id == mercaderia.Id);

                mercaderaDB.Fecha = mercaderia.Fecha;
                mercaderaDB.FechaActualizacion   = mercaderia.FechaActualizacion;
                mercaderaDB.UsuarioActualizacion = mercaderia.UsuarioActualizacion;
                mercaderaDB.FechaRecepcion       = mercaderia.FechaRecepcion;
                mercaderaDB.Estado = mercaderia.Estado;

                mercaderaDB.MercaderiaItems.ToList().ForEach(mercaderiaItemDB =>
                {
                    Modelo.MercaderiaItem mercaderiaItemLocal = mercaderia.MercaderiaItems.FirstOrDefault(x => x.Producto.Id == mercaderiaItemDB.Producto.Id);
                    if (mercaderiaItemLocal != null)
                    {
                        mercaderiaItemDB.ModificarCantidad(mercaderiaItemLocal.Cantidad);
                    }
                    else
                    {
                        _context.MercaderiaItem.Remove(mercaderiaItemDB);
                    }
                });

                mercaderia.MercaderiaItems.Where(x => x.Id == 0).ToList().ForEach(mercaderiaItemLocal =>
                {
                    if (!mercaderaDB.MercaderiaItems.Any(x => x.Producto.Id == mercaderiaItemLocal.Producto.Id))
                    {
                        _context.Entry(mercaderiaItemLocal.Producto).State = EntityState.Unchanged;
                        mercaderaDB.MercaderiaItems.Add(mercaderiaItemLocal);
                    }
                });
            }

            return(await _context.SaveChangesAsync());
        }