66 lines
1.8 KiB
C#
66 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using EnVisage.Models;
|
|
|
|
namespace EnVisage.Code.BLL
|
|
{
|
|
public class StatusManager : ManagerBase<Status, StatusModel>
|
|
{
|
|
public StatusManager(EnVisageEntities dbContext)
|
|
: base(dbContext)
|
|
{
|
|
}
|
|
protected override Status InitInstance()
|
|
{
|
|
return new Status { Id = Guid.NewGuid() };
|
|
}
|
|
|
|
protected override Status RetrieveReadOnlyById(Guid key)
|
|
{
|
|
return DataTable.AsNoTracking().FirstOrDefault(t => t.Id == key);
|
|
}
|
|
|
|
public override DbSet<Status> DataTable
|
|
{
|
|
get
|
|
{
|
|
return DbContext.Status;
|
|
}
|
|
}
|
|
public StatusModel GetTypeByName(string name)
|
|
{
|
|
return (StatusModel) DataTable.Where(x => x.Name == name).FirstOrDefault();
|
|
}
|
|
|
|
public StatusModel GetTypeById(Guid id)
|
|
{
|
|
return (StatusModel) RetrieveReadOnlyById(id);
|
|
}
|
|
|
|
public Dictionary<string, StatusModelBrief> GetItemsForDisplay()
|
|
{
|
|
var result = DbContext.Status.Where(x => !x.IsSystem).AsNoTracking().ToList()
|
|
.ToDictionary(k => k.Id.ToString(), v => new StatusModelBrief()
|
|
{
|
|
Id = v.Id,
|
|
Name = v.Name
|
|
});
|
|
return result;
|
|
}
|
|
|
|
public List<Status> GetStatuses(IEnumerable<Guid> statuses, bool readOnly = false)
|
|
{
|
|
if (statuses == null || !statuses.Any())
|
|
return new List<Status>();
|
|
|
|
var statusesQuery = DbContext.Status.Where(x => statuses.Contains(x.Id));
|
|
if (readOnly)
|
|
statusesQuery = statusesQuery.AsNoTracking();
|
|
|
|
return statusesQuery.ToList();
|
|
}
|
|
}
|
|
} |