public HttpResponseBase ExportStatistics()
        {
            ExcelWriter writer = new ExcelWriter();
            writer.startWorksheet("Users");
            writer.startRow();
            writer.addCell("Name");
            writer.addCell("Email");
            writer.addCell("Facility");
            writer.addCell("Size of Facility");
            writer.addCell("Industrial Classification");
            writer.addCell("2nd Classification");
            writer.addCell("3rd Classification");
            writer.addCell("Registration Date");
            writer.addCell("Expiration Date");
            writer.addCell("Overall H,M,Low");
            writer.addCell("Overall Score #");

            //Header
            int questionId = 1;
            IList<Category> categories = _context.Categories.ToList();

            foreach (Category category in categories)
            {
                writer.addCell(category.Index + ". " + category.Title + "  H,M,L");
                writer.addCell(category.Index + ". " + category.Title + "  Score");
                writer.addCell(category.Index + ". " + category.Title + "  Max");
                writer.addCell(category.Index + ". " + category.Title + "  Score #");
                for (int i = 0; i < category.Questions.Count; i++)
                {
                    writer.addCell("Q." + questionId + " answer");
                    writer.addCell("Answer Score");
                    writer.addCell("Max Score");
                    questionId++;
                }
            }
            writer.endRow();

            //Cycle through user entries and create lists
            IList<UserEntry> ul = (new UsersList()).Users;
            foreach (UserEntry userEntry in ul)
            {
                if (!userEntry.WasCompleteQuestionnaire)
                    continue;

                writer.startRow();

                //Common info
                writer.addCell(userEntry.User.Name);
                writer.addCell(userEntry.User.Email);
                writer.addCell(userEntry.User.FacilityName);
                writer.addCell(userEntry.User.SizeOfFacilityValue);
                writer.addCell(userEntry.User.IndustrialClassificationValue);
                writer.addCell(userEntry.User.AdditionalProductClassificationValue);
                writer.addCell(userEntry.User.AnotherProductClassificationValue);
                writer.addCell(userEntry.User.UserRegistrationDate);
                writer.addCell(userEntry.User.UserExpirationDate);

                //Get report for this user
                QuestionnairePrototype.Models.Report.QuestionnaireReport report = _questionnaireAnswersRepository.getQuestionnaireReport(userEntry.User.Id);

                //Overall
                writer.addCell(report.Overall.RiskTypeName);
                writer.addCell(report.Overall.OverallScore);

                //Categories and answers
                foreach (CategoryRecomendation category in report.Categories)
                {
                    writer.addCell(category.RiskTypeName);
                    writer.addCell(category.QuestionsValueSum);
                    writer.addCell(category.QuestionsMaxValueSum);
                    writer.addCell(category.CategoryScore);
                    foreach (QuestionRecomendation question in category.QuestionRecomendations)
                    {
                        writer.addCell(question.answerId);
                        writer.addCell(question.checkedValue);
                        writer.addCell(question.maxValue);
                    }
                }
                writer.endRow();
            }

            writer.endWorksheet();
            writer.endWorkbook();

            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=Users submissions.xls");
            Response.Charset = "";
            Response.ContentType = "application/ms-excel";
            Response.Write(writer.getString());
            Response.End();

            return Response;
        }
        public HttpResponseBase ExportStatistics(int id)
        {
            List<VendorEmailStatisticEntry> statisticItems = new List<VendorEmailStatisticEntry>();
            _context.VendorStatisticsEntries.Where(x => x.VendorId == id && x.Type == VendorStatisticsEntry.CONTACT_ME_TYPE).ToList()
                .ForEach(x => statisticItems.Add(new VendorEmailStatisticEntry(x)));

            ExcelWriter writer = new ExcelWriter();
            writer.startWorksheet("Statistics");
            writer.startRow();

            writer.addCell("Person name");
            writer.addCell("Person email");
            writer.addCell("Facility name");
            writer.addCell("Category name");
            writer.addCell("Date/time");
            writer.endRow();

            foreach (VendorEmailStatisticEntry entry in statisticItems)
            {
                writer.startRow();
                writer.addCell(entry.User.Name);
                writer.addCell(entry.User.Email);
                writer.addCell(entry.User.FacilityName);
                writer.addCell(entry.CategoryName);
                writer.addCell(entry.OccurredAt);
                writer.endRow();
            }

            writer.endWorksheet();
            writer.endWorkbook();

            string vendorName = _context.Vendors.Where(x => x.Id == id).First().Name;
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment;filename=Statistics for " + vendorName + ".xls");
            Response.Charset = "";
            Response.ContentType = "application/ms-excel";
            Response.Write(writer.getString());
            Response.End();

            return Response;
        }