Ejemplo n.º 1
0
        public async Task <HttpResponseMessage> ObtenerMovimientosClienteCSV(paraCsv data)
        {
            var movimientos = _movimientosService.ObtenerDeCliente(data.inicio, data.fin, data.clienteId).AsQueryable();

            byte[] output = null;
            await Task.Run(() =>
            {
                using (var stream = _movimientosService.ObtenerResumenMovimientosEnCSV(movimientos.ToList()))
                {
                    stream.Flush();
                    output = stream.ToArray();
                }
            });

            if (output != null)
            {
                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(output)
                };
                result.Content.Headers.ContentType        = new MediaTypeHeaderValue("application/octet-stream");
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = "prefacturacion.xls"
                };
                result.Content.Headers.Add("x-filename", "prefacturacion.xls");
                return(result);
            }

            return(this.Request.CreateErrorResponse(HttpStatusCode.NoContent, "No hay datos."));
        }
Ejemplo n.º 2
0
        public async Task<HttpResponseMessage> ObtenerMovimientosClienteCSV(paraCsv data)
        {
            var movimientos = _movimientosService.ObtenerDeCliente(data.inicio, data.fin, data.clienteId).AsQueryable();

            byte[] output = null;
            await Task.Run(() =>
            {
                using (var stream = _movimientosService.ObtenerResumenMovimientosEnCSV(movimientos.ToList()))
                {
                    stream.Flush();
                    output = stream.ToArray();
                }
            });

            if (output != null)
            {
                var result = new HttpResponseMessage(HttpStatusCode.OK) { Content = new ByteArrayContent(output) };
                result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
                {
                    FileName = "prefacturacion.xls"
                };
                result.Content.Headers.Add("x-filename", "prefacturacion.xls");
                return result;
            }

            return this.Request.CreateErrorResponse(HttpStatusCode.NoContent, "No hay datos.");
        }