/// <summary> /// Adds a product to the inventory; a new reference to the product is added if it didnt already /// exist, otherwise just increases a product's quantity /// </summary> /// <param name="product"></param> /// <param name="quantity"></param> public void Add(Product product, int quantity) { // Validate quantity if (quantity < 1) { throw new ArgumentException("Quantity added should be 1 or more.", nameof(quantity)); } // Cannot add a null product if (product == null) { throw new ArgumentNullException("Product cannot be null.", nameof(product)); } // Fetch the item with specified product from inventory's list Library.Item listItem = GetItem(product); // If inventory does not have the item, add a new item with that product and quantity if (listItem == null) { listItem = new Library.Item { Product = product, Quantity = quantity }; MyList.Add(listItem); } // If inventory already has product, increase quantity of that product else { listItem.Quantity += quantity; } }
public static Entities.Items Map(Library.Item item) => new Entities.Items { ItemId = item.Id, Name = item.Name, Price = item.Price, SecurityLevel = (long)item.SecurityLevel };
public static Item Map(Library.Item r) => new Item { ItemId = r.ItemID, Name = r.Name, Description = r.Description, NumDice = r.NumDice, NumSides = r.NumSides, Mods = r.Mods };
public static Library.Item MapInventoryItem(Entities.InventoryItems dbmodel) { Library.Item result = new Library.Item { Product = MapProduct(dbmodel.Product), Quantity = dbmodel.Quantity, }; return(result); }
/* --------------------------------------------------------- */ /* Item to OrderItems Mapping */ public static Entities.OrderItems MapOrderItem(Library.Item modelI, Library.Order modelO) { Entities.OrderItems result = new Entities.OrderItems { OrderId = modelO.OrderID, ProductId = modelI.Product.ID, Quantity = modelI.Quantity, }; return(result); }
public static Library.Item MapOrderItem(Entities.OrderItems dbmodel) { Library.Item result = new Library.Item { // Should this be changed? //ItemID = dbmodel.OrderItem, Product = MapProduct(dbmodel.Product), Quantity = dbmodel.Quantity }; return(result); }
/// <summary> /// Removes a set amount of product from the inventory /// </summary> /// <remarks> /// If the set amount will reduce the product quantity to 0, remove product from the inventory /// </remarks> /// <param name="product"></param> /// <param name="quantity"></param> public void Remove(Product product, int quantity) { // Validate quantity if (quantity < 1) { throw new ArgumentException("Quantity added should be 1 or more.", nameof(quantity)); } // Cannot add a null product if (product == null) { throw new ArgumentNullException("Product cannot be null.", nameof(product)); } // Fetch the item with specified product from inventory's list Library.Item listItem = GetItem(product); // If inventory does not have the item, add a new item with that product and quantity if (listItem == null) { Console.WriteLine("Item does not exist in inventory."); throw new ArgumentException("Item does not exist in inventory.", nameof(product)); } // Amount of product left after decreasing int quantityLeft = listItem.Quantity - quantity; // If leftover quantity would be less than 0, throw exception if (quantityLeft < 0) { throw new ArgumentException("Quantity being removed is more than in inventory.", nameof(quantity)); } // If leftover quantity would be 0, simply remove product from list if (quantityLeft == 0) { MyList.Remove(listItem); } // If leftoever quantity is some positive number, proceed with decreasing quantity if (quantityLeft > 0) { listItem.Quantity -= quantity; } }
/*------------------------------------------------------*/ /* Item to InventoryItems Mapping */ public static Entities.InventoryItems MapInventoryItem(Library.Location modelL, Library.Item modelP) { Entities.InventoryItems result = new Entities.InventoryItems { Product = MapProduct(modelP.Product), ProductId = modelP.Product.ID, Quantity = modelP.Quantity, LocationId = modelL.Id, Location = MapLocation(modelL) }; return(result); }
/// <summary> /// Displays a single item /// </summary> /// <param name="item"></param> public static void DisplayItem(Library.Item item) { Console.WriteLine($"Name:\t{item.Product.Name} | Quantity:\t{item.Quantity}\n"); }
public void UpdateItem(Library.Item item) { _db.Entry(_db.Item.Find(item.ItemID)).CurrentValues.SetValues(Mapper.Map(item)); }
public void CreateItem(Library.Item item) { _db.Add(Mapper.Map(item)); }