public IHttpActionResult ListResumenSaldoCtaCte() { try { ServiciosVentas servicio = new ServiciosVentas(); List <ListadoCtaCte> resp = servicio.ObenerResumenSaldosCtaCte(); if (resp == null) { return(NotFound()); } return(Ok(resp)); } catch (Exception ex) { LoggerHelper.LogError(MethodBase.GetCurrentMethod(), ex); return(BadRequest(ex.GetExceptionOriginal().Message)); } }
public HttpResponseMessage ExportarResumenSaldoCsv() { HttpResponseMessage result = null; try { ServiciosVentas servicio = new ServiciosVentas(); List <ListadoCtaCte> listado = servicio.ObenerResumenSaldosCtaCte(); StringBuilder registros = new StringBuilder(); registros.AppendLine("Cliente,Nombre Fantasia,Debitos,Creditos,Saldo"); string _cli = string.Empty; listado.ForEach(delegate(ListadoCtaCte item) { _cli = string.Format("({0}) - {1}", item.Campo1, item.Campo2); registros.AppendLine(string.Format("{0},{1},{2},{3},{4}", _cli, item.Campo3, item.Campo4, item.Campo5, item.Campo6)); }); byte[] byteArray = Encoding.UTF8.GetBytes(registros.ToString()); MemoryStream reportStream = new MemoryStream(byteArray); result = Request.CreateResponse(HttpStatusCode.OK); result.Content = new StreamContent(reportStream); //excel //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); //csv result.Content.Headers.ContentType = new MediaTypeHeaderValue("text/csv"); result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = string.Format("ResumenSaldo_{0}.csv", DateTime.Now.ToString("yyyyMMdd")) }; return(result); } catch (Exception ex) { LoggerHelper.LogError(MethodBase.GetCurrentMethod(), ex); return(Request.CreateResponse(HttpStatusCode.Gone)); } }