CODE
CODE
using Microsoft.VisualBasic.CompilerServices;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
//using System.Net.NetworkInformation; //JEN: Removed
//using System.Reflection.Metadata.Ecma335; //JEN: Removed
using static ICT711_Day5_classes.ProductGarment; //JEN: Added
namespace ICT711_Day5_classes
{
public class Inventory : IInventory
{
private List<Product> products;
//JEN: Revised
public List<IProduct> this[string search]
{
get
{
List<IProduct> productsOut = new List<IProduct>();
return productsOut;
}
}
/*public Inventory()
{
products = new List<Product>();
}
public List<IProduct> this[string search]
{
get
{
return products.Where(p => p.ProductName.Contains(search)).ToList<IProduct>();
}
}
public IProduct this[int productID]
{
get
{
return products.FirstOrDefault(p => p.ProductId == productID);
}
}
Products.Add(product);
return true;
}
/*public bool AddProduct(Product product)
{
//throw new NotImplementedException();
// FIRST CODE
Product existingProduct = products.FirstOrDefault(p => p.ProductId == product.ProductId);
if (existingProduct == null)
{
throw new InvalidOperationException("Product is not in inventory.");
}
if (!existingGarment.SizePriceQuantity.ContainsKey(size) ||
existingGarment.SizePriceQuantity[size].quantity < quantity)
{
throw new ArgumentOutOfRangeException($"There is not enough quantity of size {size}");
}
else
{
if (existingProduct.Quantity < product.Quantity)
{
throw new ArgumentOutOfRangeException((existingProduct.Quantity.ToString()), $"There is not enough
quantity.");
}
if (existingProduct.Quantity == product.Quantity)
{
products.Remove(existingProduct);
}
else
{
existingProduct.Quantity -= product.Quantity;
}
}
return true;
}*/
inventory.AddProduct(product);
return inventory;
}
inventory.RemoveProduct(product);
return inventory;
}
}
}
SALE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
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()
{
this.Id = new Random().Next();
}
public Sale(int id, DateTime date, int customerId, int associateId, SaleStatus status)
{
this.Id = id;
this.Date = date;
this.CustomerId = customerId;
this.AssociateId = associateId;
this.Status = status;
}
inventory.RemoveProduct(product);
p.Add(product);
return 1;
};
}
inventory.RemoveProduct(product);
ProductsList.Add(product);
return 1;
}
return total;
}
saleProduct.Remove(product);
inventory.AddProduct(product);
return 1;
}
}
}
}
STORE
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Newtonsoft.Json;
//using Newtonsoft.Json.Serialization;
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; } = "associates.json";
[JsonProperty]
public static string CustomersFileName { get; set; } = "customers.json";
[JsonProperty]
public static string InventoryFileName { get; set; } = "inventory.json";
[JsonProperty]
public static string SalesFileName { get; set; } = "sales.json";
public static string StoreFileName { get; set; } = "store.json";
public Store()
{
this.StoreName = "New Store Name"; //JEN: Added
this.Address = "Somewhere address"; //JEN: Added
}
}
}
}