/// <summary>
        ///     The Page shown when the report is generated.
        /// </summary>
        /// <param name="form">The FormCollection with the various options chosen</param>
        /// <returns>The Report as an XLS file</returns>
        /// <request type="GET">/Report/Generate</request>
        public ViewResult GeneratingReport(FormCollection form)
        {
            var rg = new ReportManagementController();
            var eec = new ExcelExportController();

            string templatePath = Path.Combine(HttpRuntime.AppDomainAppPath,
                                               "ReportTemplate.xlsx");
            var markDate = new DateTime(2010, 01, 01, 00, 00, 00, 00);
            TimeSpan dateStamp = DateTime.Now.Subtract(markDate);

            string copiedPath = Path.Combine(HttpRuntime.AppDomainAppPath,
                                             "Report" +
                                             dateStamp.TotalSeconds.ToString() +
                                             ".xlsx");

            var dataTableDictionary = new Dictionary<string, DataTable>();

            List<string> dataTypeStrings =
                form[Constants.ReportFormStrings.DATATYPE].Split(',').ToList();
            List<Constants.DataType> dataTypes =
                dataTypeStrings.Select(
                    dType =>
                    (Constants.DataType)
                    Enum.Parse(typeof (Constants.DataType), dType)).ToList();

            List<string> stratifyOptionStrings =
                form[Constants.ReportFormStrings.STRATIFY_BY].Split(',')
                                                             .ToList();
            List<Constants.StratifyOption> stratifyOptions =
                stratifyOptionStrings.Select(
                    stratify =>
                    (Constants.StratifyOption)
                    Enum.Parse(typeof (Constants.StratifyOption), stratify))
                                     .ToList();

            Dictionary<string, DataTable> temp;

            switch (form[Constants.ReportFormStrings.REPORT_OPTION]) {
                case "Monthly":
                    DateTime startDate =
                        Convert.ToDateTime(form["fromdatePicker"]);
                    DateTime endDate =
                        Convert.ToDateTime(form["todatePicker"]).AddMonths(1);
                    if (rg.checkForDataForMonth(startDate, endDate)) {
                        return View("NoDataView");
                    }
                    foreach (
                        Constants.StratifyOption stratifyOption in
                            stratifyOptions) {
                        temp = rg.generateMonthlyReport(startDate,
                                                        endDate,
                                                        dataTypes,
                                                        stratifyOption);
                        foreach (var keyValuePair in temp) {
                            dataTableDictionary.Add(keyValuePair.Key,
                                                    keyValuePair.Value);
                        }
                    }
                    break;
                case "MonthPerYear":
                    var month =
                        (Constants.Month)
                        Enum.Parse(typeof (Constants.Month), form["MPYMonth"]);
                    int startYear = Convert.ToInt32(form["MPYStartYear"]);
                    int endYear = Convert.ToInt32(form["MPYEndYear"]);
                    if (rg.checkForDataForMpy((int) month, startYear, endYear)) {
                        return View("NoDataView");
                    }
                    foreach (
                        Constants.StratifyOption stratifyOption in
                            stratifyOptions) {
                        temp = rg.generateMonthPerYearReport((int) month,
                                                             startYear,
                                                             endYear,
                                                             dataTypes,
                                                             stratifyOption);
                        foreach (var keyValuePair in temp) {
                            dataTableDictionary.Add(keyValuePair.Key,
                                                    keyValuePair.Value);
                        }
                    }
                    break;
                case "FiscalYear":
                    int start = Convert.ToInt32(form["FYStartYear"]);
                    int end = Convert.ToInt32(form["FYEndYear"]);
                    if (rg.checkForDataForFy(start, end)) {
                        return View("NoDataView");
                    }
                    foreach (
                        Constants.StratifyOption stratifyOption in
                            stratifyOptions) {
                        temp = rg.generateYearlyReport(start, end, dataTypes,
                                                       stratifyOption);
                        foreach (var keyValuePair in temp) {
                            dataTableDictionary.Add(keyValuePair.Key,
                                                    keyValuePair.Value);
                        }
                    }
                    break;
            }

            eec.exportDataTable(Constants.ReportType.Report, dataTableDictionary,
                                templatePath, copiedPath);

            return View();
        }
        public void generateMpyStratifiedByCallerTypeTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateMonthPerYearReport(2,
                                                   2013, 2014,
                                                   _dataTypes,
                                                   Constants.StratifyOption
                                                            .RequestorType);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[5]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[6]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[7]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[8]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeByCallerType =
                results[Constants.DATATABLE_TITLES[5]];
            Assert.AreEqual(70, avgTimeByCallerType.Rows[2][1]);
            Assert.AreEqual(0, avgTimeByCallerType.Rows[0][2]);
            //Tests the table size:
            Assert.AreEqual(4, avgTimeByCallerType.Rows.Count);
            Assert.AreEqual(3, avgTimeByCallerType.Columns.Count);

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeToCompleteByCallerType =
                results[Constants.DATATABLE_TITLES[6]];
            Assert.AreEqual(5, avgTimeToCompleteByCallerType.Rows[1][1]);
            Assert.AreEqual(0, avgTimeToCompleteByCallerType.Rows[1][2]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalRequestsByCallerType =
                results[Constants.DATATABLE_TITLES[7]];
            Assert.AreEqual(2, totalRequestsByCallerType.Rows[2][1]);
            Assert.AreEqual(0, totalRequestsByCallerType.Rows[2][2]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalTimeSpentByCallerType =
                results[Constants.DATATABLE_TITLES[8]];
            Assert.AreEqual(70, totalTimeSpentByCallerType.Rows[1][1]);
            Assert.AreEqual(0, totalTimeSpentByCallerType.Rows[3][2]);
        }
        public void generateMpyStratifiedByTumourGroupTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateMonthPerYearReport(2,
                                                   2012, 2013,
                                                   _dataTypes,
                                                   Constants.StratifyOption
                                                            .TumorGroup);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[9]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[10]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[11]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[12]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeByTumourGroup =
                results[Constants.DATATABLE_TITLES[9]];
            Assert.AreEqual(65, avgTimeByTumourGroup.Rows[0][2]);
            Assert.AreEqual(40, avgTimeByTumourGroup.Rows[2][2]);
            Assert.AreEqual(0, avgTimeByTumourGroup.Rows[1][1]);
            //Tests the table size:
            Assert.AreEqual(3, avgTimeByTumourGroup.Rows.Count);
            Assert.AreEqual(3, avgTimeByTumourGroup.Columns.Count);

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeToCompleteByTumourGroup =
                results[Constants.DATATABLE_TITLES[10]];
            Assert.AreEqual(5, avgTimeToCompleteByTumourGroup.Rows[1][2]);
            Assert.AreEqual(0, avgTimeToCompleteByTumourGroup.Rows[2][1]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalQuestionsByTumourGroup =
                results[Constants.DATATABLE_TITLES[11]];
            Assert.AreEqual(2, totalQuestionsByTumourGroup.Rows[0][2]);
            Assert.AreEqual(0, totalQuestionsByTumourGroup.Rows[0][1]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalTimeSpentByTumourGroup =
                results[Constants.DATATABLE_TITLES[12]];
            Assert.AreEqual(80, totalTimeSpentByTumourGroup.Rows[2][2]);
            Assert.AreEqual(0, totalTimeSpentByTumourGroup.Rows[2][1]);
        }
        public void generateMpyNoStratificationTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateMonthPerYearReport(2,
                                                   2013, 2014,
                                                   _dataTypes,
                                                   Constants.StratifyOption.None);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[0]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable generalReport = results[Constants.DATATABLE_TITLES[0]];
            Assert.AreEqual(70, generalReport.Rows[0][1]);
            Assert.AreEqual(0, generalReport.Rows[2][2]);
            Assert.AreNotEqual(0, generalReport.Rows[1][1]);
            //Tests the table size:
            Assert.AreEqual(4, generalReport.Rows.Count);
            Assert.AreEqual(3, generalReport.Columns.Count);
        }