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