public HttpResponseMessage GetSiteAnalyticsVendorSummary(int vendorID, DateTime startDate, DateTime endDate) //public FileStreamResult GetSiteAnalyticsVendorSummary(int vendorID, DateTime startDate, DateTime endDate) { string vendorName = _repository.FindVendorByID(vendorID).VendorName; List <SiteAnalyticsVendorSummary> siteAnalytics = _repository.GetSiteAnalyticsForVendor(vendorID, startDate, endDate); ExcelCreate eh = new ExcelCreate(); MemoryStream ms = eh.CreateVendorAnalyticsSummaryAsStream(siteAnalytics, vendorName, startDate, endDate); ms.Position = 0; HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StreamContent(ms); //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel"); //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/force-download"); result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); string fileName = vendorName + "_" + startDate.Day.ToString() + "-" + startDate.Month.ToString() + "-" + startDate.Year.ToString() + "_to_" + endDate.Day.ToString() + "-" + endDate.Month.ToString() + "-" + endDate.Year.ToString() + ".xlsx" ; result.Content.Headers.ContentDisposition.FileName = fileName; return(result); }
public SiteAnalyticsVendorSummary[] GetSiteAnalyticsVendorSummary(int vendorID, DateTime startDate, DateTime endDate) { try { string vendorName = _repository.FindVendorByID(vendorID).VendorName; List <SiteAnalyticsVendorSummary> siteAnalytics = _repository.GetSiteAnalyticsForVendor(vendorID, startDate, endDate); //ExcelCreate eh = new ExcelCreate(); //eh.CreateVendorAnalyticsSummary(siteAnalytics,vendorName,startDate,endDate); //MemoryStream ms = eh.CreateVendorAnalyticsSummaryAsStream(siteAnalytics, vendorName, startDate, endDate); return(siteAnalytics.ToArray()); } catch (Exception e) { return(null); } }