Example #1
0
 public PurchasePolicy parseRegular(PolicyEntry p)
 {
     if (p.getType() == "min")
     {
         MinAmountPurchase policy = new MinAmountPurchase(p.getAmount(), p.getPolicyID());
         return(policy);
     }
     else if (p.getType() == "max")
     {
         MaxAmountPurchase policy = new MaxAmountPurchase(p.getAmount(), p.getPolicyID());
         return(policy);
     }
     else
     {
         TotalPricePolicy policy = new TotalPricePolicy(p.getAmount(), p.getPolicyID());
         return(policy);
     }
 }
Example #2
0
        public void addMaxAmountPolicy(int minAmount)
        {
            if (hasMaxPurchasePolicy())
            {
                throw new AlreadyExistException("Store can not have 2 maximum amount purchase policy.");
            }
            MinAmountPurchase minPolicy = getMinPolicy();

            if (minPolicy != null)
            {
                if (minPolicy.getAmount() < minAmount)
                {
                    throw new AlreadyExistException("Max purchase policy can not be smaller than Min purchase policy.");
                }
            }
            MaxAmountPurchase p = new MaxAmountPurchase(minAmount);

            policies.AddLast(p);
            DBStore.getInstance().addMaxPolicy(p, storeId);
        }
Example #3
0
        //public HashSet<string> getApproved(int storeId, string pending)
        //{
        //    HashSet<string> output;
        //    if (pendingOwners.TryGetValue(pending.getUsername(), out output))
        //    {
        //        return output;
        //    }
        //    throw new DoesntExistException("User is not a pending owner");
        //}


        public void addMinPolicy(MinAmountPurchase p, int storeID)
        {
            try
            {
                lock (connection)
                {
                    connection.Open();
                    int policyID = p.getPolicyID();
                    int amount   = p.getAmount();
                    //  bool isPartOfComplex = false;
                    int    isPartOfComplex = 0;
                    string type            = "min";

                    string sql = "INSERT INTO [dbo].[PurchasePolicy] (storeID, policyID,type, amount,isPartOfComplex)" +
                                 " VALUES (@storeID, @policyID,@type, @amount,@isPartOfComplex )";
                    connection.Execute(sql, new { storeID, policyID, type, amount, isPartOfComplex });
                    connection.Close();
                }
            }
            catch (Exception e) {
                connection.Close();
                throw new StoreException("cant add min policy");
            }
        }