/// <summary> /// Adds a given quantity of a product to a locaion /// </summary> /// <param name="location">The location to add too</param> /// <param name="product">The product to add</param> /// <param name="quantity">amount to add</param> /// <returns></returns> public bool AddLocationInventory(Location location, DatabaseModels.Product product, int quantity) { // set up context using var context = new Project0Context(_dbContext); // make the new inventory var inventory = new DatabaseModels.Inventory { LocationId = location.Id, Quantity = quantity, ProductId = product.Id }; context.Inventories.Add(inventory); // ensure that the save works successfully try { context.SaveChanges(); } catch (DbUpdateException) { return(false); } return(true); }
/// <summary> /// Creates a new product and adds it to the database /// </summary> /// <param name="name">Name of product</param> /// <param name="description">Description of product</param> /// <param name="price">Price of product</param> /// <param name="orderLimit">Order Limit of product</param> public void AddDbProduct(string name, string description, decimal price, int orderLimit) { // get the context of the db using var context = new Project0Context(_dbContext); // Create the new product var product = new DatabaseModels.Product() { Name = name, Description = description, Price = price, OrderLimit = orderLimit }; // Add to db context.Products.Add(product); context.SaveChanges(); }
/// <summary> /// Adds Inventory to a Location /// </summary> /// <param name="product">The Product</param> /// <param name="quantity">Amount to add</param> /// <returns>True if sucessful, false otherwise</returns> public bool AddLocationInventory(DatabaseModels.Product product, int quantity) => Locations.AddLocationInventory(CurrentLocation, product, quantity);