Ejemplo n.º 1
0
        public DevolucionResponse Add(DevolucionRequest request)
        {
            Venta venta = _unitOfWork.VentaRepository.FindBy(x => x.Comprobante.Numero == request.NumeroFactura, includeProperties: "VentaDetalles").FirstOrDefault();

            if (venta == null)
            {
                return(new DevolucionResponse($"Factura {request.NumeroFactura} no encontrada"));
            }

            DevolucionBuilder builder = new DevolucionBuilder(venta);

            foreach (var item in request.Detalles)
            {
                Producto producto = _unitOfWork.ProductoRepository.FindFirstOrDefault(x => x.Codigo == item.CodigoProducto);
                builder = builder.AgregarDetalle(producto, item.Cantidad);
            }

            if (builder.IsOk().Any())
            {
                return(new DevolucionResponse(string.Join(',', builder.IsOk())));
            }

            Devolucion entity = builder.Build();

            venta.Devolver(entity);

            _unitOfWork.VentaRepository.Edit(venta);
            if (_unitOfWork.Commit() <= 0)
            {
                return(new DevolucionResponse("No se pudo registrar la devolución"));
            }
            return(new DevolucionResponse("Devolucion registrada", entity));
        }
Ejemplo n.º 2
0
        public void DevolverVentaCancelada()
        {
            venta.Cancelar();
            DevolucionBuilder builder = new DevolucionBuilder(venta);

            builder.AgregarDetalle(leche, 1);

            Exception ex = Assert.Throws <Exception>(() => { builder.Build(); });

            Assert.IsTrue(ex.Message.Contains("No hay una venta v�lida para devolver"));
        }
Ejemplo n.º 3
0
        public void DevolverProducto()
        {
            DevolucionBuilder devolucionBuilder = new DevolucionBuilder(venta);

            devolucionBuilder.AgregarDetalle(leche, 10).AgregarDetalle(yogurt, 2).AgregarDescripcion("Descripcion...");

            Devolucion devolucion = devolucionBuilder.Build();

            Assert.AreEqual(1, devolucion.DevolucionDetalles.Count);

            int cantidadEnVenta = venta.VentaDetalles.FirstOrDefault(x => x.ProductoBodega.Producto == yogurt).Cantidad;

            Assert.AreEqual(3, cantidadEnVenta);
        }