Exemple #1
0
 public void DeleteProduct(Product product)
 {
     try
     {
         mProductRepository.DeleteProduct(product, true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void InsertProduct(Product product, bool isImmediateSave)
        {
            try
            {
                mContext.Products.AddObject(product);

                if (isImmediateSave)
                {
                    mContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // TODO: Add exception handling code here.
                throw ex;
            }
        }
        public void DeleteProduct(Product product, bool isImmediateSave)
        {
            try
            {
                // Cascade deletion for reviews.
                IReviewRepository reviewRepository = new ReviewRepository();
                var reviews = reviewRepository.GetReviews().Where(review => review.productID == product.productID);

                foreach (Review review in reviews)
                {
                    reviewRepository.DeleteReview(review, false);
                }

                reviewRepository.Dispose();

                // Cascade deletion for discount items.
                IDiscountItemRepository discountItemRepository = new DiscountItemRepository();
                var discountItems = discountItemRepository.GetDiscountItems().Where(discountItem => discountItem.productID == product.productID);

                foreach (DiscountItem discountItem in discountItems)
                {
                    discountItemRepository.DeleteDiscountItem(discountItem, false);
                }

                discountItemRepository.Dispose();

                mContext.Products.Attach(product);
                mContext.Products.DeleteObject(product);

                if (isImmediateSave)
                {
                    mContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                // TODO: Add exception handling code here.
                throw ex;
            }
        }
Exemple #4
0
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            // The new product to insert.
            Product product = new Product();

            product.productName = this.ProductNameTextBox.Text;
            product.price = Convert.ToDecimal(this.PriceTextBox.Text);
            product.location = this.LocationTextBox.Text;
            product.brand = this.BrandTextBox.Text;
            product.description = this.ProductDescriptionTextBox.Text;
            product.secCategoryID = Convert.ToInt32(this.SecCategoriesDropDownList.SelectedValue);
            product.barCode = this.BarcodeTextBox.Text;

            // Set the image url and copy the cooresponding image from temporary directory to persistence directory
            // only when the user has uploaded an image.
            if (this.ProductImage.ImageUrl != null && this.ProductImage.ImageUrl != "")
            {
                try
                {
                    // Get the file name for the image.
                    String fileName = ProductImage.ImageUrl.Substring(ProductImage.ImageUrl.LastIndexOf("/") + 1);
                    String tempFile = tempPath + fileName;

                    if (File.Exists(tempFile))
                    {
                        File.Copy(tempFile, imageSavePath + fileName);
                    }

                    product.imageURL = fileName;
                }
                catch (Exception ex)
                {
                    // TODO: Handling exception.
                    product.imageURL = DEFAULT_IMAGE;
                }
            }
            else
            {
                product.imageURL = DEFAULT_IMAGE;
            }

            // For insertion.
            if((bool)ViewState["IsNew"])
            {
                mProducts.InsertProduct(product);
            }
            else // For updating.
            {
                Product origProduct = GetProduct();

                if (File.Exists(imageSavePath + origProduct.imageURL))
                {
                    File.Delete(imageSavePath + origProduct.imageURL);
                }

                product.productID = origProduct.productID;
                mProducts.UpdateProduct(product, origProduct);
            }
            Response.Write("<script type='text/javascript'>alert('成功');window.location ='Categories.aspx';</script>");
            mProducts.Dispose();

            // Jump to the product list which the edited product is in.
        }
Exemple #5
0
 public void InsertProduct(Product product)
 {
     try
     {
         mProductRepository.InsertProduct(product, true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #6
0
 public void UpdateProduct(Product product, Product origProduct)
 {
     try
     {
         mProductRepository.UpdateProduct(product, origProduct, true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public void UpdateProduct(Product newProduct, Product origProduct, bool isImmediateSave)
        {
            try
            {
                mContext.Products.Attach(origProduct);
                mContext.ApplyCurrentValues("Products", newProduct);

                if (isImmediateSave)
                {
                    mContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                // TODO: Add exception handling code here.
                throw ex;
            }
        }
 /// <summary>
 /// 创建新的 Product 对象。
 /// </summary>
 /// <param name="productID">productID 属性的初始值。</param>
 /// <param name="secCategoryID">secCategoryID 属性的初始值。</param>
 /// <param name="barCode">barCode 属性的初始值。</param>
 /// <param name="productName">productName 属性的初始值。</param>
 /// <param name="price">price 属性的初始值。</param>
 /// <param name="description">description 属性的初始值。</param>
 public static Product CreateProduct(global::System.Int32 productID, global::System.Int32 secCategoryID, global::System.String barCode, global::System.String productName, global::System.Decimal price, global::System.String description)
 {
     Product product = new Product();
     product.productID = productID;
     product.secCategoryID = secCategoryID;
     product.barCode = barCode;
     product.productName = productName;
     product.price = price;
     product.description = description;
     return product;
 }
 /// <summary>
 /// 用于向 Products EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToProducts(Product product)
 {
     base.AddObject("Products", product);
 }