narsil/Tanshu.Accounts.Contracts/Data Contracts Display/BillItemKey.cs
tanshu 20eac3c216 Refactor: Instead of a concept of Price/FullPrice, happy hour is now a checkbox in the product.
This needed major refactor in all parts dealing with product or inventory.
2016-04-11 12:31:52 +05:30

71 lines
2.1 KiB
C#

using System;
namespace Tanshu.Accounts.Contracts
{
public enum BillItemType
{
RegularProduct,
HappyHourProduct,
Kot
}
public class BillItemKey
{
private BillItemKey(Guid productID, Guid kotID, BillItemType billItemType)
{
BillItemType = billItemType;
ProductID = productID;
KotID = kotID;
}
public BillItemKey(Guid kotID)
: this(Guid.Empty, kotID, BillItemType.Kot)
{ }
public BillItemKey(Guid productID, Guid kotID, bool IsHappyHour)
: this(productID, kotID, IsHappyHour? BillItemType.HappyHourProduct : BillItemType.RegularProduct)
{ }
private Guid _productID;
public Guid ProductID
{
get { return BillItemType != BillItemType.Kot ? _productID : Guid.Empty; }
private set { _productID = BillItemType != BillItemType.Kot ? value : Guid.Empty; }
}
public Guid KotID { get; private set; }
public BillItemType BillItemType { get; private set; }
public override int GetHashCode()
{
return BillItemType.GetHashCode() ^ KotID.GetHashCode() ^ ProductID.GetHashCode() ^ BillItemType.GetHashCode();
}
public static bool operator ==(BillItemKey a, BillItemKey b)
{
if (object.ReferenceEquals(null, a))
return object.ReferenceEquals(null, b);
if (!(a is BillItemKey))
return false;
if (!(b is BillItemKey))
return false;
if (a.BillItemType != b.BillItemType)
return false;
return a.KotID == b.KotID && a.BillItemType == b.BillItemType && a.ProductID == b.ProductID && a.BillItemType == b.BillItemType;
}
public static bool operator !=(BillItemKey a, BillItemKey b)
{
return !(a == b);
}
public override bool Equals(object obj)
{
if (obj is BillItemKey)
return (this == (BillItemKey)obj);
else
return false;
}
}
}