/// <summary> /// returns false if using too many or less than 1 /// </summary> public bool IsValidQuantity(int amount, string item, int storeID) { using (var db = new ProjectOneContext()) { if (amount <= 0) { return(false); } Product p = new Product(); int pID = p.GetID(item); if (pID == -1) { return(false); //this shouldn't happen since it checks for valid product before this can be ran anyway } var locs = db.Locations .FromSqlInterpolated($"SELECT * FROM Locations WHERE ItemID = {pID} AND StoreID = {storeID}") .ToList(); int avail = -1; foreach (var l in locs) { avail = l.Quantity; } if (amount > avail) { return(false); } else { return(true); } } }
/// <summary> /// directs program to correct method /// </summary> public void UpdateInventory(Order ord) { using (var db = new ProjectOneContext()) { Product p = new Product(); int ID = p.GetID(ord.SoldItems); try { var ords = db.Locations .FromSqlInterpolated($"UPDATE Locations SET Quantity = Quantity - {ord.Quantity} WHERE StoreID = {ord.StoreID} AND ItemID = {ID}") .ToList(); } catch { } } }
/// <summary> /// returns bool is customer ID valid /// </summary> public bool IsValidCustomer(int ID) { using (var db = new ProjectOneContext()) { var custs = db.Customers .FromSqlInterpolated($"SELECT * FROM Customers WHERE CustomerID = {ID}") .ToList(); if (custs.Count != 0) { return(true); } else { return(false); } } }
/// <summary> /// return true if store ID is valid /// </summary> public bool IsValidLocation(int i) { using (var db = new ProjectOneContext()) { var locs = db.Locations .FromSqlInterpolated($"SELECT * FROM Locations WHERE StoreID = {i}") .ToList(); if (locs.Count != 0) { return(true); } else { return(false); } } }
/// <summary> /// uses product name instead for validation /// </summary> public bool IsValidProduct(string product) { using (var db = new ProjectOneContext()) { var prods = db.Products .FromSqlInterpolated($"SELECT * FROM Products WHERE PName = {product}") .ToList(); if (prods.Count != 0) { return(true); } else { return(false); } } }
/// <summary> /// return id of a product /// </summary> public int GetID(string item) { using (var db = new ProjectOneContext()) { try { var prods = db.Products .FromSqlInterpolated($"SELECT * FROM Products WHERE PName = {item}") .ToList(); foreach (var p in prods) { return(p.ProductID); } return(-1); //in case nothing is found } catch { //something went wrong return(-10); } } }