INVENTORY
using [Link];
using System;
using [Link];
using [Link];
using [Link];
using [Link];
//using [Link]; //JEN: Removed
//using [Link].Ecma335; //JEN: Removed
using static ICT711_Day5_classes.ProductGarment; //JEN: Added
namespace ICT711_Day5_classes
{
public class Inventory : IInventory
{
private List<Product> products;
public List<Product> Products
{
get
{
if (products == null) products = new List<Product>();
return products;
}
set { products = value; }
}
//JEN: Revised
public List<IProduct> this[string search]
{
get
{
List<IProduct> productsOut = new List<IProduct>();
foreach (var p in [Link])
if ([Link]().Contains([Link]())) [Link](p);
return productsOut;
}
}
public IProduct this[int productId]
{
get
{
foreach (var p in [Link])
{
if ([Link] == productId) return p;
}
throw new Exception("Invalid productId");
}
}
/*public Inventory()
{
products = new List<Product>();
}
public List<IProduct> this[string search]
{
get
{
return [Link](p => [Link](search)).ToList<IProduct>();
}
}
public IProduct this[int productID]
{
get
{
return [Link](p => [Link] == productID);
}
}
public List<IProduct> Products //=> [Link]<IProduct>().ToList();
{
get { return [Link]<IProduct>().ToList(); }
}
List<Product> [Link] => throw new NotImplementedException(); */
public bool AddProduct(Product product)
{
foreach (var p in Products)
{
if ([Link] == [Link])
{
[Link](product);
return true;
};
}
[Link](product);
return true;
}
/*public bool AddProduct(Product product)
{
//throw new NotImplementedException();
Product existingProduct = [Link](p => [Link] == [Link]);
if (existingProduct != null)
{
[Link] += [Link];
return false;
}
else
{
[Link](product);
return true;
}
}*/
public bool RemoveProduct(Product product)
{
foreach (var p in [Link])
{
if ([Link] == [Link])
{
if ([Link] >= [Link])
{
[Link](product);
return true;
}
else throw new ArgumentOutOfRangeException("Quantity", "There is not enough quantity.");
};
}
throw new Exception("Product is not in inventory.");
}
/*public bool RemoveProduct(Product product)
{
// throw new NotImplementedException();
// FIRST CODE
Product existingProduct = [Link](p => [Link] == [Link]);
if (existingProduct == null)
{
throw new InvalidOperationException("Product is not in inventory.");
}
if (existingProduct is ProductGarment existingGarment && product is ProductGarment removeGarment)
{
foreach (var entry in [Link])
{
string size = [Link];
int quantity = [Link];
decimal price = [Link];
if ( ||
[Link][size].quantity < quantity)
{
throw new ArgumentOutOfRangeException($"There is not enough quantity of size {size}");
}
[Link](size, -quantity, price);
}
}
else
{
if ([Link] < [Link])
{
throw new ArgumentOutOfRangeException(([Link]()), $"There is not enough
quantity.");
}
if ([Link] == [Link])
{
[Link](existingProduct);
}
else
{
[Link] -= [Link];
}
}
return true;
}*/
public static Inventory operator +(Inventory inventory, Product product)
{
[Link](product);
return inventory;
}
public static Inventory operator -(Inventory inventory, Product product)
{
[Link](product);
return inventory;
}
}
}
SALE
using System;
using [Link];
using [Link];
using [Link];
using [Link];
namespace ICT711_Day5_classes
{
public class Sale : ISale
{
public int Id { get; set; }
public DateTime Date { get; set; }
public int CustomerId { get; set; }
public int AssociateId { get; set; }
public Sale()
{
[Link] = new Random().Next();
}
public Sale(int customerId, int associateId, SaleStatus status)
{
[Link] = new Random().Next();
[Link] = customerId;
[Link] = associateId;
[Link] = status;
}
public Sale(int id, DateTime date, int customerId, int associateId, SaleStatus status)
{
[Link] = id;
[Link] = date;
[Link] = customerId;
[Link] = associateId;
[Link] = status;
}
private List<Product> productsList;
public List<Product> ProductsList
{
get
{
if (productsList == null) productsList = new List<Product>();
return productsList;
}
}
public SaleStatus Status { get; set; }
public int AddProduct(Product product, IInventory inventory)
{
Product inventoryProduct = (Product)inventory[[Link]];
if (inventoryProduct == null) throw new Exception("Invalid product");
if ([Link] < [Link]) throw new Exception("Insufficient quantity");
foreach (var p in ProductsList)
{
if ([Link] == [Link])
{
[Link](product);
[Link](product);
return 1;
};
}
[Link](product);
[Link](product);
return 1;
}
public decimal GetTotal()
{
decimal total = 0;
foreach (Product product in ProductsList)
{
total += [Link] * [Link];
}
return total;
}
public int RemoveProduct(Product product, IInventory inventory)
{
foreach (Product saleProduct in ProductsList)
{
if ([Link] == [Link])
{
if ([Link] < [Link]) throw new Exception("Insufficient quantity");
[Link](product);
[Link](product);
return 1;
}
}
throw new Exception("Invalid product");
}
}
}
STORE
using System;
using [Link];
using [Link];
using [Link].X509Certificates;
using [Link];
using [Link];
//using [Link];
namespace ICT711_Day5_classes
{
public class Store : IStore
{
public string StoreName { get; set; }
public string Address { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public List<ICustomer> Customers { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public List<IAssociate> Associates { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public Inventory Inventory { get; set; }
[JsonIgnore] // Don't store this data inside the store file. Will be stored in a separate file
public List<ISale> Sales { get; set; }
[JsonProperty]
public static string AssociatesFileName { get; set; } = "[Link]";
[JsonProperty]
public static string CustomersFileName { get; set; } = "[Link]";
[JsonProperty]
public static string InventoryFileName { get; set; } = "[Link]";
[JsonProperty]
public static string SalesFileName { get; set; } = "[Link]";
public static string StoreFileName { get; set; } = "[Link]";
public Store()
{
[Link] = "New Store Name"; //JEN: Added
[Link] = "Somewhere address"; //JEN: Added
}
public void LoadAssociates()
{
if ()
{
Associates = new List<Associate>().ConvertAll(a => (IAssociate)a);
}
string jsonString = [Link](AssociatesFileName);
var ass = [Link]<List<Associate>>(jsonString, new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
Associates = [Link](c => (IAssociate)c); // Typecasting for each element
//return;
// throw new NotImplementedException();
public void LoadCustomers()
{
if ()
{
Customers = new List<Customer>().ConvertAll(a => (ICustomer)a);
return;
}
string jsonString = [Link](CustomersFileName);
var cs = [Link]<List<Customer>>(jsonString, new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
Customers = [Link](c => (ICustomer)c);
// return;
// throw new NotImplementedException();
}
public void LoadInventory()
{
if ()
{
Inventory = new Inventory();
return;
}
string jsonString = [Link](InventoryFileName);
var settings = new JsonSerializerSettings
{
TypeNameHandling = [Link]
};
Inventory = [Link]<Inventory>(jsonString, settings);
}
public void LoadSales()
{
if ()
{
Sales = new List<ISale>(); // Initialize an empty list if the sales file does not exist.
return;
}
string jsonString = [Link](SalesFileName);
var settings = new JsonSerializerSettings
{
TypeNameHandling = [Link]
};
Sales = [Link]<List<ISale>>(jsonString, settings);
}
public void SaveAssociates()
{
string jsonString = [Link](Associates, [Link], new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
[Link](AssociatesFileName, jsonString);
return;
//throw new NotImplementedException();
}
public void SaveCustomers()
{
string jsonString = [Link](Customers, [Link], new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
[Link](CustomersFileName, jsonString);
return;
}
public void SaveInventory()
{
string jsonString = [Link](Inventory, [Link], new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
[Link](InventoryFileName, jsonString);
return;
}
public void SaveSales()
{
string jsonString = [Link](Sales, [Link], new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
[Link](SalesFileName, jsonString);
return;
}
public void SaveStoreInfo(string StoreDataFileName = null)
{
Dictionary<string, string> StoreDetails = new Dictionary<string, string>();
StoreDetails[StoreName] = Address;
string jsonString = [Link](StoreDetails, [Link], new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
[Link]("[Link]", jsonString);
public static Store CreateStore() // Factory method
{
if () // in case no file exists
{
return new Store();
}
string jsonString = [Link](StoreFileName);
return [Link]<Store>(jsonString, new JsonSerializerSettings
{
TypeNameHandling = [Link]
});
}
}
}