using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LD_24.Code
{
///
/// Class used for storing a single order
///
public class Order: IEquatable, IComparable
{
///
/// Surname of customer who ordered
///
public string CustomerSurname { get; set; }
///
/// Name of customer who ordered
///
public string CustomerName { get; set; }
///
/// ID of ordered product
///
public string ProductID { get; set; }
///
/// Amount of ordered products
///
public int ProductAmount { get; set; }
///
/// Creates a new order
///
/// The customers surname
/// The customers name
/// Product ID
/// Product amount
public Order(string customerSurname, string customerName, string productID, int productAmount)
{
CustomerSurname = customerSurname;
CustomerName = customerName;
ProductID = productID;
ProductAmount = productAmount;
}
///
/// Compares the sorting order of this and other.
///
///
///
public int CompareTo(Order other)
{
if (ProductAmount > other.ProductAmount)
{
return 1;
}
else if (ProductAmount == other.ProductAmount)
{
int surnameCompare = CustomerSurname.CompareTo(other.CustomerSurname);
if (surnameCompare < 0)
{
return 1;
}
else if (surnameCompare == 0 && CustomerName.CompareTo(other.CustomerName) < 0)
{
return 1;
}
}
return Equals(other) ? 0 : -1;
}
///
/// Compare if this order has the same sorting order as another one.
///
///
///
public bool Equals(Order other)
{
return CustomerSurname == other.CustomerSurname &&
CustomerName == other.CustomerName &&
ProductID == other.ProductID &&
ProductAmount == other.ProductAmount;
}
public override int GetHashCode()
{
int hashCode = -273364163;
hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(CustomerSurname);
hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(CustomerName);
hashCode = hashCode * -1521134295 + EqualityComparer.Default.GetHashCode(ProductID);
hashCode = hashCode * -1521134295 + ProductAmount.GetHashCode();
return hashCode;
}
public override string ToString()
{
return String.Format("Order{Name = '{0}'}", CustomerName);
}
}
}