2020-12-20 08:36:11 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using System;
|
2014-04-15 19:12:42 +10:00
|
|
|
|
2021-02-18 11:06:02 +01:00
|
|
|
namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core.Models.Collections
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2014-04-15 19:12:42 +10:00
|
|
|
public class OrderItem : Item
|
|
|
|
|
{
|
|
|
|
|
public readonly int PartNumber;
|
|
|
|
|
public readonly string Description;
|
|
|
|
|
public readonly double UnitPrice;
|
|
|
|
|
|
|
|
|
|
private int _quantity = 0;
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
public OrderItem(int partNumber, string description, int quantity, double unitPrice)
|
2014-04-15 19:12:42 +10:00
|
|
|
{
|
2020-10-26 14:26:49 +01:00
|
|
|
PartNumber = partNumber;
|
|
|
|
|
Description = description;
|
|
|
|
|
Quantity = quantity;
|
|
|
|
|
UnitPrice = unitPrice;
|
2014-04-15 19:12:42 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int Quantity
|
|
|
|
|
{
|
2020-12-20 08:36:11 +01:00
|
|
|
get => _quantity;
|
|
|
|
|
|
2014-04-15 19:12:42 +10:00
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value < 0)
|
2020-12-20 08:36:11 +01:00
|
|
|
{
|
2014-04-15 19:12:42 +10:00
|
|
|
throw new ArgumentException("Quantity cannot be negative.");
|
2020-12-20 08:36:11 +01:00
|
|
|
}
|
2014-04-15 19:12:42 +10:00
|
|
|
|
|
|
|
|
_quantity = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 08:36:11 +01:00
|
|
|
public override string ToString() =>
|
|
|
|
|
string.Format(
|
2014-04-15 19:12:42 +10:00
|
|
|
"{0,9} {1,6} {2,-12} at {3,8:#,###.00} = {4,10:###,###.00}",
|
2020-12-20 08:36:11 +01:00
|
|
|
PartNumber,
|
|
|
|
|
_quantity,
|
|
|
|
|
Description,
|
|
|
|
|
UnitPrice,
|
2014-04-15 19:12:42 +10:00
|
|
|
UnitPrice * _quantity);
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
}
|