Exemplo n.º 1
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");
            }
        }