80 lines
2.2 KiB
C#
80 lines
2.2 KiB
C#
using System;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using EnVisage.Models;
|
|
using System.Collections.Generic;
|
|
using jQuery.DataTables.Mvc;
|
|
|
|
namespace EnVisage.Code.BLL
|
|
{
|
|
public class ScenarioGroupManager : ManagerBase<SystemAttribute, ScenarioGroupModel>
|
|
{
|
|
public ScenarioGroupManager(EnVisageEntities dbContext)
|
|
: base(dbContext)
|
|
{
|
|
}
|
|
protected override SystemAttribute InitInstance()
|
|
{
|
|
return new SystemAttribute { Id = Guid.NewGuid(), Type=3 };
|
|
}
|
|
|
|
protected override SystemAttribute RetrieveReadOnlyById(Guid key)
|
|
{
|
|
return DataTable.AsNoTracking().FirstOrDefault(t => t.Id == key);
|
|
}
|
|
|
|
public override DbSet<SystemAttribute> DataTable => DbContext.SystemAttributes;
|
|
|
|
public void Delete(Guid id)
|
|
{
|
|
|
|
SystemAttribute dbObj = Load(id, false);
|
|
if (dbObj != null)
|
|
DataTable.Remove(dbObj);
|
|
if (IsContextLocal)
|
|
{
|
|
DbContext.SaveChanges();
|
|
|
|
}
|
|
}
|
|
|
|
public IEnumerable<ScenarioGroupModel> GetGroups(int startIndex,
|
|
int pageSize,
|
|
IEnumerable<SortedColumn> sortedColumns,
|
|
out int totalRecordCount,
|
|
out int searchRecordCount,
|
|
string searchString)
|
|
{
|
|
var query = DataTable.Where(c => c.Type == 3)
|
|
.Select(c => new ScenarioGroupModel
|
|
{
|
|
Id = c.Id,
|
|
Name = c.Name
|
|
});
|
|
|
|
//filter
|
|
if (!string.IsNullOrWhiteSpace(searchString))
|
|
{
|
|
query = query.Where(c => c.Name.ToLower().Contains(searchString.ToLower()));
|
|
}
|
|
|
|
//sort
|
|
foreach (var sortedColumn in sortedColumns)
|
|
{
|
|
switch (sortedColumn.PropertyName)
|
|
{
|
|
case "Id":
|
|
query = sortedColumn.Direction == SortingDirection.Ascending ? query.OrderBy(c => c.Id) : query.OrderByDescending(c => c.Id);
|
|
break;
|
|
default:
|
|
query = sortedColumn.Direction == SortingDirection.Ascending ? query.OrderBy(c => c.Name) : query.OrderByDescending(c => c.Name);
|
|
break;
|
|
}
|
|
}
|
|
|
|
totalRecordCount = DataTable.Count(x => x.Type == 3);
|
|
searchRecordCount = query.Count();
|
|
return query.Skip(startIndex).Take(pageSize).ToList();
|
|
}
|
|
}
|
|
} |