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");
}
}