private Discount CheckIfDiscountExistsPrivateMethod(string productName) { StockListItem stockListItem = DataLayerInstance.GetProductFromStore(_storeName, productName); MarketLog.Log("StoreCenter", " Product exists"); MarketLog.Log("StoreCenter", "checking that the product has a discount"); Discount discount = stockListItem.Discount; if (discount == null) { MarketLog.Log("StoreCenter", "product does not exists"); throw new StoreException(DiscountStatus.DiscountNotFound, "there is no discount at this product"); } MarketLog.Log("StoreCenter", " check what you want to edit"); return(discount); }
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); }
private void CheckifProductInCategory(Product product, string categoryName) { LinkedList <Product> products = DataLayerInstance.GetAllCategoryProducts(categoryName); bool check = false; foreach (Product aProduct in products) { if (product.Equals(aProduct)) { check = true; } } if (!check) { throw new StoreException(StoreEnum.ProductNotInCategory, "Product not exists in category, "); } }
private void CheckDiscountAmountDetails(string discountAmount, bool isPercentage) { int discAmountNum; if (Int32.TryParse(discountAmount, out discAmountNum)) { if (isPercentage && 0 < discAmountNum && discAmountNum < 100) { return; } if (!isPercentage && 0 < discAmountNum && discAmountNum < DataLayerInstance.GetProductByNameFromStore(_storeName, productName).BasePrice) { return; } } throw new StoreException(DiscountStatus.InvalidDiscountAmount, "Invalid Discount Amount."); }
private void CheckInput(string name, double price, string description, int quantity) { if (name.IsNullOrEmpty() | description.IsNullOrEmpty()) { throw new StoreException(StoreEnum.ProductNameNotAvlaiableInShop, "Invalid Name or Description"); } Product product = DataLayerInstance.GetProductByNameFromStore(_storeName, name); if (product != null) { throw new StoreException(StoreEnum.ProductNameNotAvlaiableInShop, "Product name must be uniqe per shop"); } if (quantity <= 0) { throw new StoreException(StoreEnum.QuantityIsNegative, "Invalid quantity"); } if (price <= 0) { throw new StoreException(StoreEnum.QuantityIsNegative, "Invalid price"); } }
public void CloseStore() { try { Store store = DataLayerInstance.GetStorebyName(_storeName); checkIfStoreExistsAndActive(); _storeManager.CanPromoteStoreOwner(); answer = store.CloseStore(); } catch (StoreException e) { answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (DataException e) { answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (MarketException) { answer = new StoreAnswer(StoreEnum.CloseStoreFail, "you have no premmision to do that"); } }
public void RemoveProductFromCategory(string categoryName, string productName) { try { MarketLog.Log("StoreCenter", "trying to remove product from category in the store"); MarketLog.Log("StoreCenter", "check if store exists"); checkIfStoreExistsAndActive(); MarketLog.Log("StoreCenter", " store exists"); MarketLog.Log("StoreCenter", " check if has premmision to handle categorys"); _storeManager.CanManageProducts(); MarketLog.Log("StoreCenter", " has premmission"); MarketLog.Log("StoreCenter", " check if category name exists in the store " + _storeName); string storeid = GetStoreIDbyName(); CheckIfCategoryExistsInStore(categoryName, storeid); MarketLog.Log("StoreCenter", "Check if Product exists in store"); var product = DataLayerInstance.GetProductByNameFromStore(_storeName, productName); checkifProductExists(product); MarketLog.Log("StoreCenter", "Product exists"); MarketLog.Log("StoreCenter", "Check if product in this category"); Category category = DataLayerInstance.GetCategoryByName(categoryName); CheckifProductInCategory(product, category.SystemId); MarketLog.Log("StoreCenter", "Product is in category"); DataLayerInstance.RemoveProductFromCategory(category.SystemId, product.SystemId); Answer = new StoreAnswer(StoreEnum.Success, "product " + productName + " removed successfully from category " + categoryName); } catch (StoreException e) { Answer = new StoreAnswer((StoreEnum)e.Status, e.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"); } }
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"); } }
public StockListItem AddNewLottery(string name, double price, string description, DateTime startDate, DateTime endDate) { try { Store store = DataLayerInstance.GetStorebyName(_storeName); MarketLog.Log("StoreCenter", "trying to add product to store"); checkIfStoreExistsAndActive(); MarketLog.Log("StoreCenter", " check if has premmision to add products"); _storeManager.CanManageProducts(); MarketLog.Log("StoreCenter", " check if product name avlaiable in the store" + _storeName); CheckIfProductNameAvailable(name); MarketLog.Log("StoreCenter", "check that dates are OK"); CheckIfDatesAreOK(startDate, endDate); Product product = new Product(name, price, description); StockListItem stockListItem = new StockListItem(1, product, null, PurchaseEnum.Lottery, store.SystemId); DataLayerInstance.AddStockListItemToDataBase(stockListItem); LotterySaleManagmentTicket lotterySaleManagmentTicket = new LotterySaleManagmentTicket( _storeName, stockListItem.Product, startDate, endDate); DataLayerInstance.AddLottery(lotterySaleManagmentTicket); MarketLog.Log("StoreCenter", "product added"); answer = new StoreAnswer(StoreEnum.Success, "product added"); return(stockListItem); } 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"); } }
public void AddProductToCategory(string categoryName, string productName) { try { MarketLog.Log("StoreCenter", "trying to add product to category to in the store"); MarketLog.Log("StoreCenter", "check if store exists"); checkIfStoreExistsAndActive(); MarketLog.Log("StoreCenter", " store exists"); MarketLog.Log("StoreCenter", " check if has premmision to handle categorys"); _storeManager.CanManageProducts(); MarketLog.Log("StoreCenter", " has premmission"); MarketLog.Log("StoreCenter", " check if category name exists in the store " + _storeName); CheckIfCategoryExists(categoryName); MarketLog.Log("StoreCenter", "Check if Product exists in store"); Product P = DataLayerInstance.GetProductByNameFromStore(_storeName, productName); checkifProductExists(P); MarketLog.Log("StoreCenter", "Product exists"); MarketLog.Log("StoreCenter", "Check if product not in this category already"); Category category = DataLayerInstance.GetCategoryByName(categoryName); CheckifProductNotInCategory(P, category.SystemId); MarketLog.Log("StoreCenter", "Product not alrady exists in category"); DataLayerInstance.AddProductToCategory(category.SystemId, P.SystemId); Answer = new StoreAnswer(StoreEnum.Success, "product " + productName + " add successfully to category " + categoryName); } catch (StoreException e) { Answer = new StoreAnswer((StoreEnum)e.Status, e.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"); } }
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"); } }