コード例 #1
0
        /// <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;
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates a Product
        /// Level: Data
        /// </summary>
        /// <param name="myProduct">A Products view representing the product</param>
        public void UpdateProduct(ProductsView myProduct)
        {
            try
            {
                Product myOriginalProduct = RetrieveProductByID(myProduct.Id);

                myOriginalProduct.Name = myProduct.Name;
                myOriginalProduct.Description = myProduct.Description;

                if (myProduct.ImageURL != null)
                {
                    myOriginalProduct.ImageURL = myProduct.ImageURL;
                }

                myOriginalProduct.Status = myProduct.Status;
                myOriginalProduct.CategoryFK = myProduct.CategoryFK;
                myOriginalProduct.SupplierFK = myProduct.SupplierFK;
                myOriginalProduct.ReorderLevel = myProduct.ReorderLevel;

                Vatrate myVatRate = RetrieveVatRate(myProduct.VatRate);

                if (myVatRate != null)
                {
                    myOriginalProduct.Vatrate = myVatRate;
                }
                else
                {
                    myVatRate = new Vatrate();
                    myVatRate.Vatrate1 = myProduct.VatRate;
                    myOriginalProduct.Vatrate = myVatRate;
                }

                Entities.SaveChanges();
            }
            catch (Exception Exception)
            {
                throw Exception;
            }
        }