/// <summary> /// Deletes a Product /// Level: Logic /// </summary> /// <param name="ProductID">The Product ID</param> /// <returns>True if successful, false if not.</returns> public bool DeleteProduct(Guid ProductID) { try { ProductsRepository myRepository = new ProductsRepository(); if (!myRepository.ProductHasOrders(ProductID)) { myRepository.DeleteProduct(ProductID); return true; } else { return false; } } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Adds A Product /// Level: Logic /// </summary> /// <param name="Name">Product Name</param> /// <param name="Status">Product Status</param> /// <param name="Description">Product Description</param> /// <param name="ImageURL">Product ImageURL</param> /// <param name="CategoryFK">The Category ID</param> /// <param name="VatRate">The VatRate</param> /// <param name="SupplierFK">The Supplier FK</param> /// <param name="ReorderLevel">The Reorder Level</param> public void AddProduct(string Name, bool Status, string Description, string ImageURL, int CategoryFK, double VatRate, int SupplierFK, int ReorderLevel) { try { ProductsRepository myRepository = new ProductsRepository(); Product myProduct = new Product(); myProduct.Id = Guid.NewGuid(); myProduct.Name = Name; myProduct.Description = Description; myProduct.StockQuantity = 0; myProduct.Status = Status; myProduct.ImageURL = ImageURL; myProduct.CategoryFK = CategoryFK; myProduct.SupplierFK = SupplierFK; myProduct.ReorderLevel = ReorderLevel; Vatrate myVatRate = myRepository.RetrieveVatRate(VatRate); if (myVatRate != null) { myProduct.Vatrate = myVatRate; } else { myVatRate = new Vatrate(); myVatRate.Vatrate1 = VatRate; myProduct.Vatrate = myVatRate; } myRepository.AddProduct(myProduct); } catch (Exception Exception) { throw Exception; } }
/// <summary> /// Updates a Product /// Level: Logic /// </summary> /// <param name="ProductID">The Product ID</param> /// <param name="Name">The Product Name</param> /// <param name="Description">The Product Description</param> /// <param name="ImageURL">The Product Image URL</param> /// <param name="Status">The Product Status</param> /// <param name="CategoryFK">The Category FK</param> /// <param name="VatRate">The VatRate</param> /// <param name="SupplierFK">The SupplierFK</param> /// <param name="ReorderLevel">The Reorder Level</param> public void UpdateProduct(string ProductID, string Name, string Description, string ImageURL, bool Status, int CategoryFK, double VatRate, int SupplierFK, int ReorderLevel) { try { ProductsRepository myRepository = new ProductsRepository(); ProductsView myProduct = new ProductsView(); myProduct.Id = Guid.Parse(ProductID); myProduct.Name = Name; myProduct.Description = Description; myProduct.ImageURL = ImageURL; myProduct.Status = Status; myProduct.CategoryFK = CategoryFK; myProduct.VatRate = VatRate; myProduct.SupplierFK = SupplierFK; myProduct.ReorderLevel = ReorderLevel; myRepository.UpdateProduct(myProduct); } catch (Exception Exception) { throw Exception; } }
public ProductsController(ProductsRepository productRepository) { _productRepository = productRepository; }