示例#1
0
        public void addProductVisibleDiscount(Product product, double percentage, string duration)
        {
            Store           store    = product.getStore();
            VisibleDiscount discount = new VisibleDiscount(percentage, duration, "ProductVisibleDiscount", store.getStoreID());

            store.addDiscount(discount);
            discount.setProduct(product);
            product.setDiscount(discount);
            DBDiscount.getInstance().addDiscount(discount);
        }
示例#2
0
 public Discount getProductDiscount(int storeId, int productId)
 {
     try
     {
         //SqlConnection connection = Connector.getInstance().getSQLConnection();
         lock (connection)
         {
             connection.Open();
             var discountEntry = connection.Query <DiscountEntry>("SELECT * FROM [dbo].[Discount] WHERE storeId=@storeId AND productId=@productId", new { storeId = storeId, productId = productId }).First();
             connection.Close();
             DiscountEntry     d   = (DiscountEntry)discountEntry;
             DiscountComponent dis = getDiscountByID(d.getId());
             if (dis != null)
             {
                 return((Discount)dis);
             }
             int discountId = d.getId();
             DiscountComponentEntry component = (DiscountComponentEntry)connection.Query <DiscountComponentEntry>("SELECT * FROM [dbo].[DiscountComponent] WHERE id=@id", new { id = discountId }).First();
             bool isPartOfComplex             = false;
             if (component.getIsPartOfComplex() == 1)
             {
                 isPartOfComplex = true;
             }
             if (d.getType() == "Visible")
             {
                 VisibleDiscount v = new VisibleDiscount(component.getId(), isPartOfComplex, component.getPercentage(), component.getDuration(), d.getVisibleType(), component.getStoreId());
                 Product         p = DBProduct.getInstance().getProductByID(d.getProductId());
                 v.setProduct(p);
                 discounts.AddFirst(v);
                 connection.Close();
                 return(v);
             }
             else
             {
                 int             productID = d.getProductId();
                 ReliantDiscount r         = null;
                 if (d.getReliantType() == "sameProduct")
                 {
                     Product p = DBProduct.getInstance().getProductByID(productID);
                     r = new ReliantDiscount(component.getId(), isPartOfComplex, component.getPercentage(), component.getDuration(), d.getNumOfProducts(), p, component.getStoreId());
                     discounts.AddFirst(r);
                 }
                 return(r);
             }
         }
     }
     catch (Exception)
     {
         if (connection.State != ConnectionState.Closed)
         {
             connection.Close();
         }
         return(null);
     }
 }