narsil/Tanshu.Accounts.SqlDAO/BusinessLayer/AdvanceBI.cs
unknown 1400f42989 Misc. forgot all changes
Working on Cashier Checkout
2011-02-05 01:00:55 +05:30

65 lines
2.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using Tanshu.Accounts.Contracts;
using System.Data.SqlClient;
using Tanshu.Data.DAO;
using Tanshu.Accounts.Entities;
using Tanshu.Accounts.SqlDAO;
using Tanshu.Accounts.Entities.Auth;
using NHibernate;
namespace Tanshu.Accounts.Repository
{
public class AdvanceBI
{
public void Insert(Advance advance)
{
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
session.Save(advance);
trans.Commit();
}
}
}
public IList<Advance> GetAdvances(DateTime startDate, DateTime finishDate, bool all)
{
startDate = startDate.Date;
finishDate = finishDate.Date.AddHours(23).AddMinutes(59).AddSeconds(59);
using (var session = SessionManager.Session)
{
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)
{
using (var session = SessionManager.Session)
{
using (var trans = session.BeginTransaction())
{
var advance = session.Get<Advance>(advanceID);
advance.DateOut = DbValues.Date;
advance.CashierOut = session.Get<User>(userID);
session.Update(advance);
trans.Commit();
}
}
}
}
}