Exemplo n.º 1
0
        public void ChangeProductPurchaseWayToImmediate(string productName)
        {
            try
            {
                MarketLog.Log("StoreCenter", "trying to edit discount from product in store");
                checkIfStoreExistsAndActive();
                MarketLog.Log("StoreCenter", " check if has premmision to edit product purches type");
                _storeManager.CanManageProducts();
                MarketLog.Log("StoreCenter", "check if product exists");
                checkifProductExists(DataLayerInstance.GetProductByNameFromStore(_storeName, productName));
                MarketLog.Log("StoreCenter", "product exists");
                StockListItem stockList = DataLayerInstance.GetProductFromStore(_storeName, productName);
                ValidateLottery(stockList);
                stockList.PurchaseWay = PurchaseEnum.Immediate;
                DataLayerInstance.EditStockInDatabase(stockList);
                answer = new StoreAnswer(StoreEnum.Success, "purches way changed");
            }
            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.º 2
0
 public void RemoveDiscountFromProduct(string productName)
 {
     try
     {
         MarketLog.Log("StoreCenter", "trying to remove discount from product 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");
         Product P = DataLayerInstance.GetProductByNameFromStore(_storeName, productName);
         checkifProductExists(P);
         Discount      D             = CheckIfDiscountExistsPrivateMethod(productName);
         StockListItem stockListItem = DataLayerInstance.GetProductFromStore(_storeName, productName);
         stockListItem.Discount = null;
         DataLayerInstance.RemoveDiscount(D);
         DataLayerInstance.EditStockInDatabase(stockListItem);
         MarketLog.Log("StoreCenter", "discount removed successfully");
         Answer = new StoreAnswer(DiscountStatus.Success, "discount 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.º 3
0
        public void AddQuanitityToProduct(string productName, int quantity)
        {
            try
            {
                MarketLog.Log("StoreCenter", "checking that store exists");
                checkIfStoreExistsAndActive();
                MarketLog.Log("StoreCenter", "checking that has premmisions");
                _storeManager.CanManageProducts();
                MarketLog.Log("StoreCenter", "checking that Product Exists");
                checkifProductExists(DataLayerInstance.GetProductByNameFromStore(_storeName, productName));
                StockListItem stockListItem = DataLayerInstance.GetProductFromStore(_storeName, productName);
                MarketLog.Log("StoreCenter", "checking that quantity is positive");
                CheckIfQuanityIsOK(quantity);
                stockListItem.Quantity += quantity;
                DataLayerInstance.EditStockInDatabase(stockListItem);
                answer = new StoreAnswer(StoreEnum.Success, "item " + productName + " added by amound of " + quantity);
            }
            catch (StoreException exe)
            {
                answer = new StoreAnswer((StoreEnum)exe.Status, exe.GetErrorMessage());
            }

            catch (DataException e)
            {
                answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage());
            }

            catch (MarketException e)
            {
                MarketLog.Log("StoreCenter", "Manager " + _storeManager.GetID() + " has no permission to view purchase history in Store"
                              + _storeName + " and therefore has been denied. Error message has been created!");
                answer = new StoreAnswer(StoreEnum.NoPermission, e.GetErrorMessage());
            }
        }
Exemplo n.º 4
0
        public Discount AddDiscountToProduct(string productName, DateTime startDate, DateTime endDate,
                                             int discountAmount, string discountType, bool presenteges)
        {
            try
            {
                MarketLog.Log("StoreCenter", "trying to add discount to product in store");
                MarketLog.Log("StoreCenter", "check if store exists");
                CheckIfStoreExistsAndActiveDiscount();
                MarketLog.Log("StoreCenter", " store exists");
                MarketLog.Log("StoreCenter", " check if has premmision to edit products");
                _storeManager.CanDeclareDiscountPolicy();
                MarketLog.Log("StoreCenter", " has premmission");
                MarketLog.Log("StoreCenter", " check if product name exists in the store " + _storeName);
                Product product = DataLayerInstance.GetProductByNameFromStore(_storeName, productName);
                CheckifProductExistsDiscount(product);
                MarketLog.Log("StoreCenter", "check if dates are OK");
                CheckIfDatesOK(startDate, endDate);
                MarketLog.Log("StoreCenter", "check that discount amount is OK");
                CheckPresentegesAndAmountOK(discountAmount, presenteges, product);
                StockListItem stockListItem = DataLayerInstance.GetProductFromStore(_storeName, product.Name);
                MarketLog.Log("StoreCenter", "check that the product don't have another discount");
                CheckHasNoExistsDiscount(stockListItem);
                Discount discount = new Discount(EnumStringConverter.GetdiscountTypeEnumString(discountType), startDate,
                                                 endDate, discountAmount, presenteges);
                stockListItem.Discount = discount;
                DataLayerInstance.AddDiscount(discount);
                DataLayerInstance.EditStockInDatabase(stockListItem);
                MarketLog.Log("StoreCenter", "discount added successfully");
                string[] coupon = { discount.discountCode };
                answer = new StoreAnswer(DiscountStatus.Success, "discount added successfully", coupon);
                return(discount);
            }
            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");
            }

            return(null);
        }
        public void ChangeProductPurchaseWayToLottery(string productName, DateTime startDate, DateTime endDate)
        {
            try
            {
                MarketLog.Log("StoreCenter", "check if store exists");
                checkIfStoreExistsAndActive();
                MarketLog.Log("StoreCenter", " check if has premmision to edit products");
                _storeManager.CanManageProducts();
                MarketLog.Log("StoreCenter", " has premmission");
                MarketLog.Log("StoreCenter", "check if product exists");
                checkifProductExists(DataLayerInstance.GetProductByNameFromStore(_storeName, productName));
                MarketLog.Log("StoreCenter", "product exists");
                StockListItem stockListItem = DataLayerInstance.GetProductFromStore(_storeName, productName);
                CheckIfAlreadyLottery(stockListItem);
                MarketLog.Log("StoreCenter", "check if dates are OK");
                CheckIfDatesAreOK(startDate, endDate);
                stockListItem.PurchaseWay = PurchaseEnum.Lottery;
                DataLayerInstance.EditStockInDatabase(stockListItem);
                LotterySaleManagmentTicket lotterySaleManagmentTicket = new LotterySaleManagmentTicket(
                    _storeName, stockListItem.Product, startDate, endDate);
                DataLayerInstance.AddLottery(lotterySaleManagmentTicket);

                answer = new StoreAnswer(ChangeToLotteryEnum.Success, "type changed");
            }
            catch (StoreException exe)
            {
                answer = new StoreAnswer((ChangeToLotteryEnum)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");
            }
        }