narsil/Tanshu.Accounts.Repository/BusinessLayer/AdvanceBI.cs
unknown 59909a5ee7 Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
2011-06-30 01:57:07 +05:30

52 lines
1.7 KiB
C#

using System;
using System.Collections.Generic;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.Entities.Auth;
using NHibernate;
namespace Tanshu.Accounts.Repository
{
public class AdvanceBI : FluentGenericBase<Advance>
{
public AdvanceBI()
: base()
{ }
public AdvanceBI(bool beginTransaction)
: base(beginTransaction)
{ }
public AdvanceBI(ISession session)
: base(session)
{ }
public AdvanceBI(ISession session, bool beginTransaction)
: base(session, beginTransaction)
{ }
public IList<Advance> GetAdvances(DateTime startDate, DateTime finishDate, bool all)
{
startDate = startDate.Date;
finishDate = finishDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
var query = from ad in Session.QueryOver<Advance>()
where ad.DateIn >= startDate && ad.DateIn <= finishDate
select ad;
if (!all)
query = from a in query
where a.CashierOut == null
select a;
var list = query.List();
foreach (var item in list)
{
NHibernateUtil.Initialize(item.CashierIn);
NHibernateUtil.Initialize(item.CashierOut);
}
return list;
}
public void Adjust(int advanceID, int userID)
{
var advance = Session.Get<Advance>(advanceID);
advance.DateOut = DbValues.Date;
advance.CashierOut = Session.Get<User>(userID);
Session.Update(advance);
}
}
}