Esempio n. 1
0
        public HttpResponseMessage Export()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK);

            List <ProductDTO> products = _unitOfWork.ProductRepository
                                         .Get()
                                         .Select(p => new ProductDTO()
            {
                ID             = p.ID,
                Name           = p.Name,
                Description    = p.Description,
                PurchasePrice  = p.PurchasePrice,
                SalesPrice     = p.SalesPrice,
                SpoilDate      = p.SpoilDate,
                UnitsAvailable = p.UnitsAvailable
            }).ToList();

            MediaTypeHeaderValue mediaType    = new MediaTypeHeaderValue("application/octet-stream");
            MemoryStream         memoryStream = new MemoryStream(ExportService.ExcelReport(products));

            response.Content = new StreamContent(memoryStream);
            response.Content.Headers.ContentType        = mediaType;
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("fileName")
            {
                FileName = "myReport.xls"
            };

            return(response);
        }