Esempio n. 1
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);
     }
 }
Esempio n. 2
0
        public Discount getStoreDiscount(int id, int storeId)
        {
            //SqlConnection connection = Connector.getInstance().getSQLConnection();
            var discountEntry = connection.Query <DiscountEntry>("SELECT * FROM [dbo].[Discount] WHERE id=@id AND storeId=@storeId", new { id, storeId = storeId }).First();

            DiscountEntry d          = (DiscountEntry)discountEntry;
            int           discountId = d.getId();


            DiscountComponentEntry component = (DiscountComponentEntry)connection.Query <DiscountComponentEntry>("SELECT * FROM [dbo].[DiscountComponent] WHERE id=@id", new { id = discountId }).First();

            connection.Close();
            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());
                return(v);
            }
            else
            {
                ReliantDiscount r = null;
                if (d.getReliantType() == "totalAmount")
                {
                    r = new ReliantDiscount(component.getId(), isPartOfComplex, component.getPercentage(), component.getDuration(), d.getTotalAmount(), component.getStoreId());
                }
                return(r);
            }
        }