public ActionResult Toptenpages(string txtDateFrom, string txtDateTo, string Export)
        {
            try
            {
                ViewData["FromDate"] = DateTime.Today.Subtract(TimeSpan.FromDays(365)).ToShortDateString();
                ViewData["ToDate"]   = DateTime.Today.ToShortDateString();
                string strClientUserName = Environment.UserName.ToString().Trim();
                if (txtDateFrom == null | txtDateTo == null)
                {
                    txtDateTo   = System.DateTime.Today.ToShortDateString();
                    txtDateFrom = System.DateTime.Today.Subtract(TimeSpan.FromDays(30)).ToShortDateString();
                }

                ViewData["txtDateFrom"] = txtDateFrom;
                ViewData["txtDateTo"]   = txtDateTo;

                bool mFromDateStatus = isDate(txtDateFrom);
                bool mToDateStatus   = isDate(txtDateTo);

                if (mFromDateStatus == false)
                {
                    txtDateFrom = System.DateTime.Today.Subtract(TimeSpan.FromDays(30)).ToShortDateString();
                    ModelState.AddModelError("FromDateValidation", "Invalid Date Range");
                }
                if (mToDateStatus == false)
                {
                    ModelState.AddModelError("ToDateValidation", "Invalid Date Range");
                    txtDateTo = System.DateTime.Today.ToShortDateString();
                }
                ViewData["txtDateFrom"] = txtDateFrom;
                ViewData["txtDateTo"]   = txtDateTo;
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                else
                {
                    if (Convert.ToDateTime(txtDateFrom) > Convert.ToDateTime(txtDateTo))
                    {
                        ModelState.AddModelError("FromDateValidation", "Invalid Date Range");
                        ModelState.AddModelError("ToDateValidation", "Invalid Date Range");
                        return(View());
                    }
                }
                ReportsDomain _reportsDomain = new ReportsDomain(ConfigurationManager.ConnectionStrings["FeedbackScriptConnectionString"].ConnectionString);

                var orderedResultsPerPage = _reportsDomain.GetTopTenList(txtDateFrom, txtDateTo);



                bool m = isDate(txtDateFrom);
                if (Export != null)
                {
                    ExportToExcelTopTenPages(orderedResultsPerPage.ToList(), txtDateFrom.ToString(), txtDateTo.ToString());
                }

                if (_reportsDomain.GetTopTenList(txtDateFrom, txtDateTo).Count() <= 0)
                {
                    ModelState.AddModelError("RecordCount", "No results found for the specified search criteria");
                }


                return(View(orderedResultsPerPage));
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message + ex.StackTrace;
                return(View("Error"));
            }
        }
        public ActionResult ViewComments(string txtDateFrom, string txtDateTo, string URL, int?Page, string SortBy, string Order, string Export, string urlContains, string SelectedAgency)
        {
            try
            {
                int resultsPerPage = 10;

                ReportsDomain _reportsDomain = new ReportsDomain(ConfigurationManager.ConnectionStrings["FeedbackScriptConnectionString"].ConnectionString);

                URL         = ReplaceBad(URL);
                txtDateFrom = ReplaceBad(txtDateFrom);
                txtDateTo   = ReplaceBad(txtDateTo);

                var orderedResultsPerPage = _reportsDomain.GetCommentsList(txtDateFrom, txtDateTo, URL);

                if (Export == string.Empty | Export == null)
                {
                    if (!Page.HasValue || Page.Value < 1)
                    {
                        Page = 1;
                    }
                    if (SortBy == "" || SortBy == null)
                    {
                        SortBy = "utcDate";
                    }
                    if (Order == "" || Order == null)
                    {
                        Order = "Asc";
                    }

                    PaginationInfo pi = new PaginationInfo {
                        CurrentPage = Page.Value, ResultPerPage = resultsPerPage, TotalCount = _reportsDomain.GetCommentsList(txtDateFrom, txtDateTo, URL).Count(), SortBy = SortBy, Order = Order, txtDateFrom = txtDateFrom, txtDateTo = txtDateTo, URL = URL
                    };
                    ViewData["paging"] = pi;

                    switch (SortBy)
                    {
                    case "utcDate":
                    default:
                        orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetCommentsList(txtDateFrom, txtDateTo, URL).OrderBy(a => a.utcDate) : _reportsDomain.GetCommentsList(txtDateFrom, txtDateTo, URL).OrderByDescending(a => a.utcDate);
                        break;
                    }

                    var CountViewPage = _reportsDomain.GetCommentsList(txtDateFrom, txtDateTo, URL);
                    if (CountViewPage.Count() == 0)
                    {
                        txtDateFrom = "";
                        txtDateTo   = "";
                        URL         = "";
                    }

                    ViewData["SortBy"]         = SortBy;
                    ViewData["Order"]          = Order;
                    ViewData["txtDateFrom"]    = txtDateFrom;
                    ViewData["txtDateTo"]      = txtDateTo;
                    ViewData["URL"]            = URL;
                    ViewData["urlContains"]    = urlContains;
                    ViewData["SelectedAgency"] = SelectedAgency;



                    return(View(orderedResultsPerPage.Skip(resultsPerPage * (Page.Value - 1)).Take(resultsPerPage)));
                }
                else
                {
                    ExportToExcelCommentsPage(orderedResultsPerPage.ToList(), txtDateFrom.ToString(), txtDateTo.ToString(), txtDateFrom, txtDateTo, URL);
                    return(View(orderedResultsPerPage));
                }
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message + ex.StackTrace;
                return(View("Error"));
            }
        }
        public ActionResult Trends(string txtDateFrom, string txtDateTo, string txtURLContains, string SelectedAgency, string SelectedUnit, string Export, int?Page, string SortBy, string Order)
        {
            try
            {
                if (txtURLContains == "Enter Text")
                {
                    txtURLContains = "";
                }
                string sUnit = string.Empty;
                if (SelectedUnit == null)
                {
                    SelectedUnit = "D";
                }


                var list = new SelectList(new []
                {
                    new { ID = "D", Name = "Days" },
                    new{ ID = "W", Name = "Weeks" },
                    new{ ID = "M", Name = "Months" },
                    new{ ID = "Q", Name = "Quarters" },
                    new{ ID = "Y", Name = "Years" },
                },
                                          "ID", "Name", SelectedUnit);

                ViewData["UnitList"] = list;
                if (SelectedAgency == null)
                {
                    SelectedAgency = "DOL.Gov";
                }
                if (txtURLContains == null)
                {
                    txtURLContains = "";
                }

                int resultsPerPage = 10;

                if (txtDateFrom == null | txtDateTo == null)
                {
                    txtDateTo   = System.DateTime.Today.ToShortDateString();
                    txtDateFrom = System.DateTime.Today.Subtract(TimeSpan.FromDays(30)).ToShortDateString();
                }


                ReportsDomain _reportsDomain = new ReportsDomain(ConfigurationManager.ConnectionStrings["FeedbackScriptConnectionString"].ConnectionString);

                bool mFromDateStatus = isDate(txtDateFrom);
                bool mToDateStatus   = isDate(txtDateTo);

                if (mFromDateStatus == false)
                {
                    txtDateFrom = System.DateTime.Today.Subtract(TimeSpan.FromDays(30)).ToShortDateString();
                    ModelState.AddModelError("FromDateValidation", "Invalid Date Range");
                }
                if (mToDateStatus == false)
                {
                    txtDateTo = System.DateTime.Today.ToShortDateString();
                    ModelState.AddModelError("ToDateValidation", "Invalid Date Range");
                }

                txtURLContains          = ReplaceBad(txtURLContains);
                ViewData["txtDateFrom"] = txtDateFrom;
                ViewData["txtDateTo"]   = txtDateTo;
                ViewData["urlContains"] = txtURLContains;

                if (!ModelState.IsValid)
                {
                    ViewData["AgencyList"] = new SelectList(new[]
                    {
                        new { Agency = "Empty List", Val = "Empty List" },
                    },
                                                            "Agency", "Agency", "Empty List");
                    return(View());
                }
                else
                {
                    if (Convert.ToDateTime(txtDateFrom) > Convert.ToDateTime(txtDateTo))
                    {
                        ModelState.AddModelError("FromDateValidation", "Invalid Date Range");
                        ModelState.AddModelError("ToDateValidation", "Invalid Date Range");
                        ViewData["AgencyList"] = new SelectList(new[]
                        {
                            new { Agency = "Empty List", Val = "Empty List" },
                        },
                                                                "Agency", "Agency", "Empty List");
                        return(View());
                    }
                }

                var orderedResultsPerPage = _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, 'D');

                if (Export == string.Empty | Export == null)
                {
                    if (!Page.HasValue || Page.Value < 1)
                    {
                        Page = 1;
                    }
                    if (SortBy == "" || SortBy == null)
                    {
                        SortBy = "UnitName";
                    }
                    if (Order == "" || Order == null)
                    {
                        Order = "Asc";
                    }
                    char           mEmpty = new char();
                    PaginationInfo pi     = new PaginationInfo {
                        CurrentPage = Page.Value, ResultPerPage = resultsPerPage, TotalCount = _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).Count(), SortBy = SortBy, Order = Order, txtDateFrom = txtDateFrom, txtDateTo = txtDateTo, SelectedAgency = SelectedAgency, urlContains = txtURLContains, UnitName = SelectedUnit
                    };
                    ViewData["paging"] = pi;

                    switch (SortBy)
                    {
                    case "VolumeOfFeedback":
                        orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderBy(a => a.VolumeFeedBack) : _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderByDescending(a => a.VolumeFeedBack);
                        break;

                    case "NumOfPosComments":
                        orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderBy(a => a.NumOfPosComments) : _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderByDescending(a => a.NumOfPosComments);
                        break;

                    case "NumOfNegComments":
                        orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderBy(a => a.NumOfNegComments) : _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderByDescending(a => a.NumOfNegComments);
                        break;

                    case "UnitName":
                    default:
                        if (SelectedUnit == "M")
                        {
                            orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, 'A') : _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, 'D');
                        }
                        else
                        {
                            orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderBy(a => a.UnitName) : _reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).OrderByDescending(a => a.UnitName);
                        }
                        break;
                    }


                    ViewData["SortBy"]     = SortBy;
                    ViewData["Order"]      = Order;
                    ViewData["AgencyList"] = new SelectList(_reportsDomain.GetAgencyList(txtDateFrom, txtDateTo).ToList(), "Agency", "Agency", SelectedAgency);

                    if (_reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, mEmpty).Count() <= 0)
                    {
                        ModelState.AddModelError("RecordCount", "No results found for the specified search criteria");
                    }
                    else
                    {
                        int MaxRecSizeVolFeedBack = new int();
                        ViewData["graphData"]             = GetGraphData(_reportsDomain.GetTrend(txtDateFrom, txtDateTo, txtURLContains, SelectedAgency, SelectedUnit, 'A').ToList(), out MaxRecSizeVolFeedBack);
                        ViewData["MaxRecSizeVolFeedBack"] = MaxRecSizeVolFeedBack;
                    }

                    return(View(orderedResultsPerPage.Skip(resultsPerPage * (Page.Value - 1)).Take(resultsPerPage)));
                }
                else
                {
                    ExportToExcelTrendPage(orderedResultsPerPage.ToList(), txtDateFrom.ToString(), txtDateTo.ToString(), SelectedUnit, txtURLContains, SelectedAgency);
                    return(View(orderedResultsPerPage));
                }
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message + ex.StackTrace;
                return(View("Error"));
            }
        }
        public ActionResult Summary(string txtDateFrom, string txtDateTo, string Export, string SortBy, string Order)
        {
            try
            {
                if (txtDateFrom == null | txtDateTo == null)
                {
                    txtDateTo   = System.DateTime.Today.ToShortDateString();
                    txtDateFrom = System.DateTime.Today.Subtract(TimeSpan.FromDays(30)).ToShortDateString();
                }

                bool mFromDateStatus = isDate(txtDateFrom);
                bool mToDateStatus   = isDate(txtDateTo);

                if (mFromDateStatus == false)
                {
                    txtDateFrom = System.DateTime.Today.Subtract(TimeSpan.FromDays(30)).ToShortDateString();
                    ModelState.AddModelError("FromDateValidation", "Invalid Date Range");
                }
                if (mToDateStatus == false)
                {
                    txtDateTo = System.DateTime.Today.ToShortDateString();
                    ModelState.AddModelError("ToDateValidation", "Invalid Date Range");
                }

                ViewData["txtDateFrom"] = txtDateFrom;
                ViewData["txtDateTo"]   = txtDateTo;
                if (!ModelState.IsValid)
                {
                    return(View());
                }
                else
                {
                    if (Convert.ToDateTime(txtDateFrom) > Convert.ToDateTime(txtDateTo))
                    {
                        ModelState.AddModelError("FromDateValidation", "Invalid Date Range");
                        ModelState.AddModelError("ToDateValidation", "Invalid Date Range");
                        return(View());
                    }
                }

                ReportsDomain _reportsDomain = new ReportsDomain(ConfigurationManager.ConnectionStrings["FeedbackScriptConnectionString"].ConnectionString);

                var orderedResultsPerPage = _reportsDomain.GetSummary(txtDateFrom, txtDateTo);

                if (Export == string.Empty | Export == null)
                {
                    if (SortBy == "" || SortBy == null)
                    {
                        SortBy = "AgencyName";
                    }
                    if (Order == "" || Order == null)
                    {
                        Order = "Asc";
                    }

                    switch (SortBy)
                    {
                    case "VolumeOfFeedback":
                        orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetSummary(txtDateFrom, txtDateTo).OrderBy(a => a.VolumeFeedBack) : _reportsDomain.GetSummary(txtDateFrom, txtDateTo).OrderByDescending(a => a.VolumeFeedBack);
                        break;

                    case "PositiveFeedback":
                        orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetSummary(txtDateFrom, txtDateTo).OrderBy(a => a.Pfeedback) : _reportsDomain.GetSummary(txtDateFrom, txtDateTo).OrderByDescending(a => a.Pfeedback);
                        break;

                    case "AgencyName":
                    default:
                        orderedResultsPerPage = Order == "Asc" ? _reportsDomain.GetSummary(txtDateFrom, txtDateTo).OrderBy(a => a.Agency) : _reportsDomain.GetSummary(txtDateFrom, txtDateTo).OrderByDescending(a => a.Agency);
                        break;
                    }

                    ViewData["SortBy"] = SortBy;
                    ViewData["Order"]  = Order;


                    if (_reportsDomain.GetSummary(txtDateFrom, txtDateTo).Count() <= 0)
                    {
                        ModelState.AddModelError("RecordCount", "No results found for the specified search criteria");
                    }

                    return(View(orderedResultsPerPage));
                }
                else
                {
                    ExportToExcelSummaryPage(orderedResultsPerPage.ToList(), txtDateFrom.ToString(), txtDateTo.ToString());
                    return(View(orderedResultsPerPage));
                }
            }
            catch (Exception ex)
            {
                ViewData["ErrorMessage"] = ex.Message + ex.StackTrace;
                return(View("Error"));
            }
        }