Files
LeafWeb/WebCms/Controllers/ResultsController.cs
T

103 lines
3.0 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using LeafWeb.WebCms.Models;
using LeafWeb.WebCms.Utility;
using Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSix;
using Umbraco.Web.Mvc;
namespace LeafWeb.WebCms.Controllers
{
public class ResultsController : BaseController
{
[MemberAuthorize(AllowGroup = "Authenticated")]
public ActionResult Index(LeafDataQuery model)
{
// if there are no search parameters, show an empty search page
if (!model.HasParameters)
{
// Default to "only my data"
if (!TempData.ContainsKey("Posted"))
model.usr = "on";
model.dsp = LeafDataQuery.LeafInputDataSearchParam;
model.compl = "1";
return View("Index", new SearchLeafInputViewModel
{
Q = model
});
}
var currentUserEmail = Members.GetCurrentLoginStatus()?.Email;
if (model.ShowLeafInputData)
{
var resultItems =
DataService.GetLeafInputData();
resultItems =
QueryFilter.Search(resultItems, model, currentUserEmail);
return View("LeafInputData", new SearchLeafInputDataViewModel
{
Results = resultItems,
Q = model
});
}
else
{
var resultItems =
DataService.GetLeafInputsOrdered();
resultItems =
QueryFilter.Search(resultItems, model, currentUserEmail);
return View("LeafInput", new SearchLeafInputViewModel
{
Results = resultItems,
Q = model
});
}
}
[MemberAuthorize(AllowGroup = "Authenticated")]
[HttpPost]
public ActionResult Search(LeafDataQuery model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
TempData["Posted"] = true;
return RedirectToCurrentUmbracoPage(model.GetNameValueCollection());
}
[MemberAuthorize(AllowGroup = "Authenticated")]
public ActionResult Details(int id)
{
var leafInput = DataService.GetLeafInput(id);
if (leafInput == null)
{
SetStatusMessage($"LeafInput '${id}' not found, may have been deleted?");
RedirectToUmbracoPage(LeafWebPageIds.ManageQueue);
}
var viewModel = new LeafInputDetails(leafInput);
return View(viewModel);
}
public ActionResult Recent()
{
var dateThreshold = DateTime.Today.Subtract(TimeSpan.FromDays(90));
var viewModel =
from li in DataService.GetLeafInputsOrdered()
where li.Added >= dateThreshold
select li;
return View(viewModel);
}
}
}