/// <summary>
 /// Edits the shelf from the database
 /// </summary>
 public void Edit(string description, int maxUnitStorageSize)
 {
     base.Update($@" UPDATE shelves
                     SET description = '{description}', maxUnitStorageSize = {maxUnitStorageSize}
                     WHERE id = {this.Id}");
     StatusHandler.Write($"Edited shelf {this.Identifier}", StatusHandler.Codes.SUCCESS);
     LoadShelves();
 }
 /// <summary>
 /// Edits the product from the database
 /// </summary>
 public void Edit(string name, ProductCategory category, int unitSize, int unitPrice, Shelf shelf)
 {
     base.Update($@"UPDATE products
                     SET name = '{name}', category_id = {category.Id}, unitSize = {unitSize}, unitPrice = {unitPrice}, shelf_id = {shelf.Id}
                     WHERE id = {this.Id}");
     // Write a status
     StatusHandler.Write($"Edited product {this.Name}", StatusHandler.Codes.SUCCESS);
 }
        /// <summary>
        /// Removes the product from the database
        /// </summary>
        public void Remove()
        {
            // Call the base Delete which also will handle the Saved variable

            base.Delete($@" DELETE FROM products
                            WHERE id = {this.Id}");
            // Write a status
            StatusHandler.Write($"Deleted product {this.Name}", StatusHandler.Codes.SUCCESS);
        }
 /// <summary>
 /// Save the product to the database
 /// </summary>
 /// <param name="shelfId">The id of the shelf the product is going to be added to</param>
 public void Save(int shelfId)
 {
     // Call the base insert which also will handle the Saved variable
     base.Insert($@" INSERT INTO products
                     (name, category_id, unitSize, unitPrice, shelf_id)
                     VALUES ('{this.Name}',{this.Category.Id},{this.UnitSize}, {this.UnitPrice}, {shelfId})");
     // Write a status
     StatusHandler.Write($"Saved product {this.Name}", StatusHandler.Codes.SUCCESS);
 }
        /// <summary>
        /// Saves the shelf from the database
        /// </summary>
        public void Save()
        {
            base.Insert($@" INSERT INTO shelves
                            (identifier, description, maxUnitStorageSize)
                            VALUES ('{this.Identifier}','{this.Description}',{this.MaxUnitStorageSize})");

            StatusHandler.Write($"Saved shelf {this.Identifier}", StatusHandler.Codes.SUCCESS);
            LoadShelves();
        }
        /// <summary>
        /// Removes the shelf from the database
        /// </summary>
        public void Remove()
        {
            // Delete all products first
            foreach (var product in products)
            {
                Database.Execute($"DELETE FROM products WHERE id = {product.Id}");
            }

            base.Delete($@" DELETE FROM shelves
                            WHERE id = {this.Id}");
            StatusHandler.Write($"Deleted shelf {this.Identifier}", StatusHandler.Codes.SUCCESS);
            LoadShelves();
        }
 /// <summary>
 /// Removes a product from the shelf
 /// </summary>
 /// <param name="product">Product to be removed</param>
 public void RemoveProduct(Product product)
 {
     // Check if the shelf contains the product before removal
     if (this.products.Contains(product))
     {
         // Remove the product
         product.Remove();
         LoadProducts();
     }
     else
     {
         StatusHandler.Write($"{product}, does not exist in the shelf' product list", StatusHandler.Codes.ERROR);
     }
 }
 /// <summary>
 /// EditProduct method
 /// This methods makes it possible to edit a product through the shelf
 /// </summary>
 /// <param name="product">The product instance we want to edit</param>
 /// <param name="name">Edited name</param>
 /// <param name="category">Edited category</param>
 /// <param name="unitSize">Edited unitSize</param>
 /// <param name="unitPrice">Edited unitPrice</param>
 /// <param name="shelf">Edited shelf</param>
 public void EditProduct(Product product, string name, ProductCategory category, int unitSize, int unitPrice, Shelf shelf)
 {
     // First check if the product contains the the list of products
     if (this.products.Contains(product))
     {
         product.Edit(name, category, unitSize, unitPrice, shelf);
         // Load shelves incase the shelf of the product has changed
         LoadShelves();
         LoadProducts();
     }
     else
     {
         StatusHandler.Write($"{product}, does not exist in the shelf' product list", StatusHandler.Codes.ERROR);
     }
 }
 /// <summary>
 /// AddProduct method
 /// This method adds a product to the instance of the shelf and checks if the product first has been saved in the database
 /// </summary>
 /// <param name="product"></param>
 public void AddProduct(Product product)
 {
     if (!product.Saved)
     {
         if (product.UnitSize <= (this.MaxUnitStorageSize - UsedStorage()))
         {
             product.Save(this.Id);
             LoadProducts();
         }
         else
         {
             StatusHandler.Write($"Insufficient shelf-{this.Identifier} storage {UsedStorage()}/{MaxUnitStorageSize}", StatusHandler.Codes.ERROR);
         }
     }
 }