Modify CatalogItem for stocking
This commit is contained in:
parent
fbfe287da5
commit
ac53528f89
@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Catalog.API.Infrastructure.Exceptions;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
|
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
|
||||||
{
|
{
|
||||||
@ -14,8 +15,6 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
|
|||||||
|
|
||||||
public string PictureUri { get; set; }
|
public string PictureUri { get; set; }
|
||||||
|
|
||||||
public int Stock { get; set; }
|
|
||||||
|
|
||||||
public int CatalogTypeId { get; set; }
|
public int CatalogTypeId { get; set; }
|
||||||
|
|
||||||
public CatalogType CatalogType { get; set; }
|
public CatalogType CatalogType { get; set; }
|
||||||
@ -24,6 +23,79 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
|
|||||||
|
|
||||||
public CatalogBrand CatalogBrand { get; set; }
|
public CatalogBrand CatalogBrand { get; set; }
|
||||||
|
|
||||||
public CatalogItem() { }
|
// Quantity in stock
|
||||||
|
public int AvailableStock { get; set; }
|
||||||
|
|
||||||
|
// Available stock at which we should reorder
|
||||||
|
public int RestockThreshold { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
// Maximum number of units that can be in-stock at any time (due to physicial/logistical constraints in warehouses)
|
||||||
|
public int MaxStockThreshold { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// True if item is on reorder
|
||||||
|
/// </summary>
|
||||||
|
public bool OnReorder { get; set; }
|
||||||
|
|
||||||
|
public CatalogItem() { }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrements the quantity of a particular item in inventory and ensures the restockThreshold hasn't
|
||||||
|
/// been breached. If so, a RestockRequest is generated in CheckThreshold.
|
||||||
|
///
|
||||||
|
/// If there is sufficient stock of an item, then the integer returned at the end of this call should be the same as quantityDesired.
|
||||||
|
/// In the event that there is not sufficient stock available, the method will remove whatever stock is available and return that quantity to the client.
|
||||||
|
/// In this case, it is the responsibility of the client to determine if the amount that is returned is the same as quantityDesired.
|
||||||
|
/// It is invalid to pass in a negative number.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="quantityDesired"></param>
|
||||||
|
/// <returns>int: Returns the number actually removed from stock. </returns>
|
||||||
|
///
|
||||||
|
public int RemoveStock(int quantityDesired)
|
||||||
|
{
|
||||||
|
if (AvailableStock == 0)
|
||||||
|
{
|
||||||
|
throw new CatalogDomainException($"Empty stock, product item {Name} is sold out");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (quantityDesired <= 0)
|
||||||
|
{
|
||||||
|
throw new CatalogDomainException($"Item units desired should be greater than cero");
|
||||||
|
}
|
||||||
|
|
||||||
|
int removed = Math.Min(quantityDesired, this.AvailableStock);
|
||||||
|
|
||||||
|
this.AvailableStock -= removed;
|
||||||
|
|
||||||
|
return removed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Increments the quantity of a particular item in inventory.
|
||||||
|
/// <param name="quantity"></param>
|
||||||
|
/// <returns>int: Returns the quantity that has been added to stock</returns>
|
||||||
|
/// </summary>
|
||||||
|
public int AddStock(int quantity)
|
||||||
|
{
|
||||||
|
int original = this.AvailableStock;
|
||||||
|
|
||||||
|
// The quantity that the client is trying to add to stock is greater than what can be physically accommodated in the Warehouse
|
||||||
|
if ((this.AvailableStock + quantity) > this.MaxStockThreshold)
|
||||||
|
{
|
||||||
|
// For now, this method only adds new units up maximum stock threshold. In an expanded version of this application, we
|
||||||
|
//could include tracking for the remaining units and store information about overstock elsewhere.
|
||||||
|
this.AvailableStock += (this.MaxStockThreshold - this.AvailableStock);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.AvailableStock += quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.OnReorder = false;
|
||||||
|
|
||||||
|
return this.AvailableStock - original;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user