Exemplo n.º 1
0
        private CategoryDiscount EditDiscountStartDatePrivateMethod(CategoryDiscount categoryDiscount, string newValue)
        {
            MarketLog.Log("StoreCenter", " edit start date");
            MarketLog.Log("StoreCenter", " checking that the start date is legal");
            if (!DateTime.TryParse(newValue, out var startTime))
            {
                MarketLog.Log("StoreCenter", "date format is not legal");
                throw new StoreException(DiscountStatus.DatesAreWrong, "date format is not legal");
            }
            if (startTime.Date < MarketYard.MarketDate)
            {
                MarketLog.Log("StoreCenter", "can't set start time in the past");
                throw new StoreException(DiscountStatus.DatesAreWrong, "can't set start time in the past");
            }

            if (startTime.Date >= categoryDiscount.EndDate.Date)
            {
                MarketLog.Log("StoreCenter", "can't set start time that is later then the discount end time");
                throw new StoreException(DiscountStatus.DatesAreWrong, "can't set start time that is later then the discount end time");
            }
            categoryDiscount.StartDate = startTime;
            MarketLog.Log("StoreCenter", " start date changed successfully");
            Answer = new StoreAnswer(DiscountStatus.Success, "category " + categoryDiscount.CategoryName + " Start Date become " + startTime);
            return(categoryDiscount);
        }
Exemplo n.º 2
0
        public Discount CalcTotalDiscount(string storeName)
        {
            double beginPrice = Product.BasePrice;

            if (Discount?.discountType == DiscountTypeEnum.Visible && Discount.CheckTime())
            {
                beginPrice = Discount.CalcDiscount(beginPrice);
            }
            CategoryDiscount categoryDiscount = null;

            foreach (string categoryName in Product.Categories)
            {
                categoryDiscount = StoreDL.Instance.GetCategoryDiscount(categoryName, storeName);
                if (categoryDiscount != null)
                {
                    beginPrice = categoryDiscount.CalcDiscount(beginPrice);
                }
            }

            if (categoryDiscount != null)
            {
                return(new Discount(DiscountTypeEnum.Visible, categoryDiscount.StartDate, categoryDiscount.EndDate, (1 - beginPrice / Product.BasePrice) * 100, true));
            }

            return(Discount);
        }
Exemplo n.º 3
0
 public void RemoveCategoryDiscount(string categoryName)
 {
     try
     {
         MarketLog.Log("StoreCenter", "trying to remove discount from category in store");
         MarketLog.Log("StoreCenter", "check if store exists");
         checkIfStoreExistsAndActive();
         MarketLog.Log("StoreCenter", " check if has premmision to edit products");
         _storeManager.CanDeclareDiscountPolicy();
         MarketLog.Log("StoreCenter", " has premmission");
         MarketLog.Log("StoreCenter", " check that cateory exists");
         CheckIfCategoryExists(categoryName);
         MarketLog.Log("StoreCenter", "category exists");
         MarketLog.Log("StoreCenter", " check that category has discount in this store");
         CheckHasExistsDiscount(categoryName);
         CategoryDiscount categoryDiscount = DataLayerInstance.GetCategoryDiscount(categoryName, _storeName);
         DataLayerInstance.RemoveCategoryDiscount(categoryDiscount);
         MarketLog.Log("StoreCenter", "categoryDiscountd added successfully");
         Answer = new StoreAnswer(StoreEnum.Success, "categoryDiscountd removed successfully");
     }
     catch (StoreException exe)
     {
         Answer = new StoreAnswer((StoreEnum)exe.Status, exe.GetErrorMessage());
     }
     catch (DataException e)
     {
         Answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage());
     }
     catch (MarketException)
     {
         Answer = new StoreAnswer(StoreEnum.NoPermission, "you have no premmision to do that");
     }
 }
Exemplo n.º 4
0
        private void CheckHasExistsDiscount(string categoryName)
        {
            CategoryDiscount categoryDiscount = DataLayerInstance.GetCategoryDiscount(categoryName, _storeName);

            if (categoryDiscount == null)
            {
                throw new StoreException(StoreEnum.CategoryDiscountNotExistsInStore, "categorydiscount not exists in the store");
            }
        }
Exemplo n.º 5
0
        public void AddCategoryDiscount(CategoryDiscount categorydiscount)
        {
            object[] discountVals = categorydiscount.GetDiscountValuesArray();
            foreach (object val in discountVals)
            {
                dbConnection.CheckInput(val.ToString());
            }

            dbConnection.InsertTable("CategoryDiscount", "SystemID, CategoryName, StoreName, StartDate, EndDate, DiscountAmount",
                                     new[] { "@idParam", "@categoryParam", "@storeParam", "@startParam", "@endParam", "@amountParam" }
                                     , discountVals);
        }
Exemplo n.º 6
0
        public void CheckIfDiscountExistsAndCalcValue(string storename)
        {
            double beginPrice = Product.BasePrice;

            if (Discount?.discountType == DiscountTypeEnum.Visible && Discount.CheckTime())
            {
                Product.BasePrice = Discount.CalcDiscount(Product.BasePrice);
            }
            CategoryDiscount categoryDiscount = null;

            foreach (string categoryName in Product.Categories)
            {
                categoryDiscount = StoreDL.Instance.GetCategoryDiscount(categoryName, storename);
                if (categoryDiscount != null)
                {
                    Product.BasePrice = categoryDiscount.CalcDiscount(Product.BasePrice);
                }
            }
        }
Exemplo n.º 7
0
        public void EditCategoryDiscount(CategoryDiscount categoryDiscount)
        {
            string[] columnNames =
            {
                "SystemID",
                "CategoryName",
                "StoreName",
                "StartDate",
                "EndDate",
                "DiscountAmount",
            };
            object[] discountVals = categoryDiscount.GetDiscountValuesArray();
            foreach (object val in discountVals)
            {
                dbConnection.CheckInput(val.ToString());
            }

            dbConnection.UpdateTable("CategoryDiscount", "SystemId = '" + categoryDiscount.SystemId + "'", columnNames,
                                     new[] { "@idParam", "@categoryParam", "@storeParam", "@startParam", "@endParam", "@amountParam" }
                                     , discountVals);
        }
Exemplo n.º 8
0
 public void AddCategoryDiscount(string categoryName, DateTime startDate, DateTime endDate, int discountAmount)
 {
     try
     {
         MarketLog.Log("StoreCenter", "trying to add discount to category in store");
         MarketLog.Log("StoreCenter", "check if store exists");
         checkIfStoreExistsAndActive();
         MarketLog.Log("StoreCenter", " store exists");
         MarketLog.Log("StoreCenter", " check if has premmision to edit categorys");
         _storeManager.CanDeclareDiscountPolicy();
         MarketLog.Log("StoreCenter", " has premmission");
         MarketLog.Log("StoreCenter", " check if Category exists");
         CheckIfCategoryExists(categoryName);
         MarketLog.Log("StoreCenter", "check if dates are OK");
         CheckIfDatesOK(startDate, endDate);
         MarketLog.Log("StoreCenter", "check that discount amount is OK");
         CheckAmountIsOk(discountAmount);
         MarketLog.Log("StoreCenter", "check that the category don't have another discount");
         CheckHasNoExistsDiscount(categoryName);
         CategoryDiscount discount =
             new CategoryDiscount(_storeName, categoryName, startDate, endDate, discountAmount);
         DataLayerInstance.AddCategoryDiscount(discount);
         MarketLog.Log("StoreCenter", "categoryDiscountd added successfully");
         string[] coupon = { discount.SystemId };
         Answer = new StoreAnswer(StoreEnum.Success, "categoryDiscountd added successfully", coupon);
     }
     catch (StoreException exe)
     {
         Answer = new StoreAnswer((StoreEnum)exe.Status, exe.GetErrorMessage());
     }
     catch (DataException e)
     {
         Answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage());
     }
     catch (MarketException)
     {
         Answer = new StoreAnswer(StoreEnum.NoPermission, "you have no premmision to do that");
     }
 }
Exemplo n.º 9
0
 private CategoryDiscount EditDiscountDiscountAmountPrivateMehtod(CategoryDiscount categoryDiscount, string newValue)
 {
     MarketLog.Log("StoreCenter", " edit discount amount");
     if (!Int32.TryParse(newValue, out var newintValue))
     {
         MarketLog.Log("StoreCenter", "value is not legal");
         throw new StoreException(DiscountStatus.DiscountAmountIsNotNumber, "value is not legal");
     }
     if (newintValue >= 100)
     {
         MarketLog.Log("StoreCenter", "DiscountAmount is >= 100");
         throw new StoreException(DiscountStatus.AmountIsHundredAndpresenteges, "DiscountAmount is >= 100");
     }
     if (newintValue <= 0)
     {
         MarketLog.Log("StoreCenter", "discount amount <=0");
         throw new StoreException(DiscountStatus.DiscountAmountIsNegativeOrZero, "DiscountAmount is >= 100%");
     }
     categoryDiscount.DiscountAmount = newintValue;
     MarketLog.Log("StoreCenter", "discount amount set to " + newintValue);
     Answer = new StoreAnswer(DiscountStatus.Success, "category " + categoryDiscount.CategoryName + "discount amount become " + newValue);
     return(categoryDiscount);
 }
Exemplo n.º 10
0
        public CategoryDiscount GetCategoryDiscount(string categoryName, string storeName)
        {
            dbConnection.CheckInput(categoryName); dbConnection.CheckInput(storeName);
            CategoryDiscount categoryDiscount = null;

            using (var dbReader =
                       dbConnection.SelectFromTableWithCondition("CategoryDiscount", "*",
                                                                 "CategoryName = '" + categoryName + "' AND StoreName = '" + storeName + "'"))
            {
                while (dbReader.Read())
                {
                    categoryDiscount = new CategoryDiscount(dbReader.GetString(0),
                                                            dbReader.GetString(1),
                                                            dbReader.GetString(2),
                                                            dbReader.GetDateTime(3)
                                                            , dbReader.GetDateTime(4)
                                                            , dbReader.GetInt32(5)
                                                            );
                }
            }

            return(categoryDiscount);
        }
Exemplo n.º 11
0
 private bool Equals(CategoryDiscount obj)
 {
     return(obj.SystemId == SystemId && obj.DiscountAmount == DiscountAmount && CategoryName == obj.CategoryName && StoreName == obj.StoreName);
 }
Exemplo n.º 12
0
        public void EditCategoryDiscount(string categoryName, string whatToEdit, string newValue)
        {
            try
            {
                MarketLog.Log("StoreCenter", "trying to edit discount from product in store");
                checkIfStoreExistsAndActive();
                MarketLog.Log("StoreCenter", " check if has premmision to edit products");
                _storeManager.CanDeclareDiscountPolicy();
                MarketLog.Log("StoreCenter", " has premmission");
                MarketLog.Log("StoreCenter", " check that cateory exists");
                CheckIfCategoryExists(categoryName);
                MarketLog.Log("StoreCenter", "category exists");
                MarketLog.Log("StoreCenter", " check that category has discount in this store");
                CategoryDiscount categoryDiscount = CheckHasExistsCategoryDiscount(categoryName);
                switch (whatToEdit)
                {
                case "startDate":
                case "start Date":
                case "StartDate":
                case "Start Date":
                case "startdate":
                case "start date":
                case "STARTDATE":
                case "START DATE":
                    categoryDiscount = EditDiscountStartDatePrivateMethod(categoryDiscount, newValue);
                    break;

                case "EndDate":
                case "end Date":
                case "enddate":
                case "End Date":
                case "end date":
                case "ENDDATE":
                case "END DATE":
                    categoryDiscount = EditDiscountEndDatePrivateMethod(categoryDiscount, newValue);
                    break;

                case "DiscountAmount":
                case "Discount Amount":
                case "discount amount":
                case "discountamount":
                case "DISCOUNTAMOUNT":
                case "DISCOUNT AMOUNT":
                    categoryDiscount = EditDiscountDiscountAmountPrivateMehtod(categoryDiscount, newValue);
                    break;
                }

                if (Answer == null)
                {
                    throw new StoreException(DiscountStatus.NoLegalAttrebute, "no legal attribute found");
                }
                DataLayerInstance.EditCategoryDiscount(categoryDiscount);
            }
            catch (StoreException exe)
            {
                Answer = new StoreAnswer((StoreEnum)exe.Status, exe.GetErrorMessage());
            }
            catch (DataException e)
            {
                Answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage());
            }
            catch (MarketException)
            {
                Answer = new StoreAnswer(StoreEnum.NoPermission, "you have no premmision to do that");
            }
        }
Exemplo n.º 13
0
 public void RemoveCategoryDiscount(CategoryDiscount categoryDiscount)
 {
     dbConnection.CheckInput(categoryDiscount.SystemId);
     dbConnection.DeleteFromTable("CategoryDiscount", "SystemId = '" + categoryDiscount.SystemId + "'");
 }