2016-10-26 14:02:40 +08:00
|
|
|
|
using Bootstrap.DataAccess;
|
|
|
|
|
using Longbow.Web.Mvc;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.Admin.Models
|
|
|
|
|
{
|
|
|
|
|
public class QueryMenuOption : PaginationOption
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-11-06 00:48:08 +08:00
|
|
|
|
public string ParentName { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
2016-10-26 14:02:40 +08:00
|
|
|
|
public string Category { get; set; }
|
|
|
|
|
|
2016-11-08 20:37:14 +08:00
|
|
|
|
public QueryData<Menu> RetrieveData(string userName)
|
2016-10-26 14:02:40 +08:00
|
|
|
|
{
|
2016-11-08 20:37:14 +08:00
|
|
|
|
var data = MenuHelper.RetrieveMenus(userName);
|
2016-11-06 00:48:08 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(ParentName))
|
|
|
|
|
{
|
|
|
|
|
data = data.Where(t => t.ParentName.Contains(ParentName));
|
|
|
|
|
}
|
2016-10-26 14:02:40 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(Name))
|
|
|
|
|
{
|
|
|
|
|
data = data.Where(t => t.Name.Contains(Name));
|
|
|
|
|
}
|
2016-10-28 11:12:25 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(Category))
|
|
|
|
|
{
|
2016-10-28 15:51:08 +08:00
|
|
|
|
data = data.Where(t => t.Category.Contains(Category));
|
2016-10-28 11:12:25 +08:00
|
|
|
|
}
|
2016-10-26 14:02:40 +08:00
|
|
|
|
var ret = new QueryData<Menu>();
|
|
|
|
|
ret.total = data.Count();
|
2016-11-03 21:29:32 +08:00
|
|
|
|
switch (Sort)
|
|
|
|
|
{
|
|
|
|
|
case "Name":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.Name) : data.OrderByDescending(t => t.Name);
|
|
|
|
|
break;
|
2016-11-06 00:48:08 +08:00
|
|
|
|
case "ParentName":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.ParentName) : data.OrderByDescending(t => t.ParentName);
|
|
|
|
|
break;
|
2016-11-03 21:29:32 +08:00
|
|
|
|
case "Order":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.Order) : data.OrderByDescending(t => t.Order);
|
|
|
|
|
break;
|
|
|
|
|
case "CategoryName":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.CategoryName) : data.OrderByDescending(t => t.CategoryName);
|
|
|
|
|
break;
|
2016-12-09 12:51:41 +08:00
|
|
|
|
case "Target":
|
|
|
|
|
data = Order == "asc" ? data.OrderBy(t => t.Target) : data.OrderByDescending(t => t.Target);
|
|
|
|
|
break;
|
2016-11-03 21:29:32 +08:00
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2016-10-26 14:02:40 +08:00
|
|
|
|
ret.rows = data.Skip(Offset).Take(Limit);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-25 18:54:20 +08:00
|
|
|
|
}
|