92 lines
2.1 KiB
C#
92 lines
2.1 KiB
C#
using Newtonsoft.Json;
|
|
|
|
namespace RhSolutions.Models;
|
|
public class Product : IDisposable
|
|
{
|
|
[JsonIgnore]
|
|
public string Id
|
|
{
|
|
get => ProductSku.Id;
|
|
set
|
|
{
|
|
ProductSku = new(value);
|
|
}
|
|
}
|
|
public string Name { get; set; } = string.Empty;
|
|
public ProductSku ProductSku { get; set; }
|
|
public List<ProductSku> DeprecatedSkus { get; set; } = new();
|
|
public List<string> ProductLines { get; set; } = new();
|
|
public bool IsOnWarehouse { get; set; } = false;
|
|
public Measure ProductMeasure { get; set; }
|
|
public double? DeliveryMakeUp { get; set; }
|
|
public decimal Price { get; set; }
|
|
|
|
[JsonConstructor]
|
|
public Product(string id,
|
|
string name,
|
|
ProductSku productSku,
|
|
ProductSku[] deprecatedSkus,
|
|
string[] productLines,
|
|
bool isOnWarehouse,
|
|
int productMeasure,
|
|
int deliveryMakeUp,
|
|
decimal price)
|
|
{
|
|
Id = id;
|
|
Name = name;
|
|
ProductSku = productSku;
|
|
DeprecatedSkus = deprecatedSkus.ToList();
|
|
ProductLines = productLines.ToList();
|
|
IsOnWarehouse = isOnWarehouse;
|
|
ProductMeasure = (Measure)productMeasure;
|
|
DeliveryMakeUp = deliveryMakeUp;
|
|
Price = price;
|
|
}
|
|
public Product(string sku)
|
|
{
|
|
ProductSku = new(sku);
|
|
}
|
|
|
|
public Product(ProductSku productSku)
|
|
{
|
|
ProductSku = productSku;
|
|
}
|
|
|
|
public override bool Equals(object? obj)
|
|
{
|
|
return obj is Product product &&
|
|
Name == product.Name &&
|
|
EqualityComparer<ProductSku>.Default.Equals(ProductSku, product.ProductSku) &&
|
|
DeprecatedSkus.SequenceEqual(product.DeprecatedSkus) &&
|
|
ProductLines.SequenceEqual(product.ProductLines) &&
|
|
IsOnWarehouse == product.IsOnWarehouse &&
|
|
ProductMeasure == product.ProductMeasure &&
|
|
DeliveryMakeUp == product.DeliveryMakeUp &&
|
|
Price == product.Price;
|
|
}
|
|
|
|
public override int GetHashCode()
|
|
{
|
|
HashCode hash = new HashCode();
|
|
hash.Add(Name);
|
|
hash.Add(ProductSku);
|
|
DeprecatedSkus.ForEach(x => hash.Add(x));
|
|
ProductLines.ForEach(x => hash.Add(x));
|
|
hash.Add(IsOnWarehouse);
|
|
hash.Add(ProductMeasure);
|
|
hash.Add(DeliveryMakeUp);
|
|
hash.Add(Price);
|
|
return hash.ToHashCode();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return $"({ProductSku}) {Name}";
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
|
|
}
|
|
}
|