78 lines
2.3 KiB
C#
78 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using EnVisage.Models;
|
|
using System.Data.Entity;
|
|
|
|
namespace EnVisage.Code.BLL
|
|
{
|
|
public class GLAccountManager : ManagerBase<GLAccount, GLAccountModel>
|
|
{
|
|
public GLAccountManager(EnVisageEntities dbContext) : base(dbContext)
|
|
{
|
|
}
|
|
|
|
public override GLAccount Save(GLAccountModel model)
|
|
{
|
|
GLAccount glAccount = null;
|
|
glAccount = base.Save(model);
|
|
return glAccount;
|
|
}
|
|
|
|
public GLAccountModel LoadWithChildCollections(Guid? value, bool isReadOnly = true)
|
|
{
|
|
GLAccountModel result = (GLAccountModel)base.Load(value, isReadOnly);
|
|
|
|
int? clientCount =
|
|
DbContext.GLAccountClientsCounts.Where(x => x.Id.Equals(value.Value))
|
|
.Select(z => z.ClientCount).FirstOrDefault();
|
|
|
|
int? expCatsCount =
|
|
DbContext.GLAccountExpCatsCounts.Where(x => x.Id.Equals(value.Value))
|
|
.Select(z => z.ExpCatCount).FirstOrDefault();
|
|
|
|
result.ClientCount = clientCount.HasValue ? clientCount.Value : 0;
|
|
result.ExpenditureCount = expCatsCount.HasValue ? expCatsCount.Value : 0;
|
|
|
|
return result;
|
|
}
|
|
|
|
protected override GLAccount InitInstance()
|
|
{
|
|
return new GLAccount { Id = Guid.NewGuid() };
|
|
}
|
|
|
|
protected override GLAccount RetrieveReadOnlyById(Guid key)
|
|
{
|
|
return DataTable.AsNoTracking().FirstOrDefault(t=>t.Id == key);
|
|
}
|
|
|
|
public override System.Data.Entity.DbSet<GLAccount> DataTable
|
|
{
|
|
get
|
|
{
|
|
return DbContext.GLAccounts;
|
|
}
|
|
}
|
|
|
|
// SA. ENV-1171
|
|
public IEnumerable<GLAccountListModel> GetListReadOnly()
|
|
{
|
|
IEnumerable<GLAccountListModel> qry =
|
|
(from ac in DbContext.GLAccounts
|
|
join clcnt in DbContext.GLAccountClientsCounts on ac.Id equals clcnt.Id
|
|
join expcnt in DbContext.GLAccountExpCatsCounts on ac.Id equals expcnt.Id
|
|
select new GLAccountListModel()
|
|
{
|
|
Id = ac.Id,
|
|
Name = ac.Name,
|
|
GLNumber = ac.GLNumber,
|
|
ExpenditureCount = expcnt.ExpCatCount.HasValue ? expcnt.ExpCatCount.Value : 0,
|
|
ClientCount = clcnt.ClientCount.HasValue ? clcnt.ClientCount.Value : 0
|
|
}).AsNoTracking();
|
|
|
|
return qry;
|
|
}
|
|
}
|
|
} |