narsil/Tanshu.Accounts.Repository/BusinessLayer/FoodTableBI.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

72 lines
2.3 KiB
C#

using NHibernate;
using Tanshu.Accounts.Entities;
using System.Linq;
namespace Tanshu.Accounts.Repository
{
public class FoodTableBI : FluentGenericBase<FoodTable>
{
public FoodTableBI()
: base()
{ }
public FoodTableBI(bool beginTransaction)
: base(beginTransaction)
{ }
public FoodTableBI(ISession session)
: base(session)
{ }
public FoodTableBI(ISession session, bool beginTransaction)
: base(session, beginTransaction)
{ }
public void UpdateStatus(string name, int voucherID, string status)
{
var table = Get(x => x.Name == name);
table.VoucherID = string.IsNullOrEmpty(status) ? 0 : voucherID;
table.Status = status;
Session.Update(table);
}
public int Move(string name, FoodTable foodTable)
{
var oldTable = Get(x => x.Name == name);
foodTable.Status = oldTable.Status;
foodTable.VoucherID = oldTable.VoucherID;
oldTable.Status = null;
oldTable.VoucherID = 0;
Session.Update(foodTable);
Session.Update(oldTable);
var voucher = Session.Get<Voucher>(foodTable.VoucherID);
voucher.TableID = foodTable.Name;
Session.Update(voucher);
return voucher.VoucherID;
}
public void UpdateStatus(Voucher voucher)
{
string status;
if (!voucher.Printed)
status = "running";
else if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && voucher.Void == false)
status = "printed";
else
status = null;
UpdateStatus(voucher.TableID, voucher.VoucherID, status);
}
public void TableSettled(Voucher voucher)
{
if (voucher.Settlements.Count(x => x.Settled == SettleOption.Unsettled) != 0 && voucher.Void == false)
return;
var table = Get(x => x.Name == voucher.TableID && x.VoucherID == voucher.VoucherID);
if (table == null)
return;
table.VoucherID = 0;
table.Status = null;
Session.Update(table);
}
}
}