public void ViewStoreInfo(string store) { try { CheckIfStoreExistsAndActive(store); MarketLog.Log("StoreCenter", "check that have premission to view store info"); _shopper.ValidateCanBrowseMarket(); MarketLog.Log("StoreCenter", "premission gained"); string[] storeInfo = storeLogic.GetStoreInfo(store); CheckIfStoreInfoIsNotNull(storeInfo); MarketLog.Log("StoreCenter", "info gained"); answer = new StoreAnswer(ViewStoreStatus.Success, "Store info has been successfully granted!", storeInfo); } catch (StoreException e) { MarketLog.Log("StoreCenter", ""); answer = new StoreAnswer((ViewStoreStatus)e.Status, "Something is wrong with viewing " + store + " info by customers . Error message has been created!"); } catch (DataException e) { answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (MarketException) { MarketLog.Log("StoreCenter", "no premission"); answer = new StoreAnswer(ViewStoreStatus.InvalidUser, "User validation as valid customer has been failed . only valid users can browse market. Error message has been created!"); } }
public void AddProductToCart(string store, string productName, int quantity) { try { MarketLog.Log("StoreCenter", "trying to add something to the cart"); MarketLog.Log("StoreCenter", "checking if store exists"); CheckIfStoreExitsts(store); MarketLog.Log("StoreCenter", "checking if user has premmisions"); _shopper.ValidateCanBrowseMarket(); MarketLog.Log("StoreCenter", "checking if product exists"); CheckIsProductNameAvailableInStore(store, productName); StockListItem stockListItem = storeLogic.GetProductFromStore(store, productName); CheckifQuantityIsOK(quantity, stockListItem); stockListItem.CheckIfDiscountExistsAndCalcValue(store); _shopper.AddToCart(stockListItem.Product, stockListItem.Product.Categories, store, quantity); MarketLog.Log("StoreCenter", "add product successeded"); answer = new StoreAnswer(StoreEnum.Success, quantity + " " + productName + " from " + store + "has been" + " successfully added to the user's cart!"); } catch (StoreException e) { answer = new StoreAnswer((AddProductStatus)e.Status, "There is no product or store or quantity of that type in the market." + " request has been denied. Error message has been created!"); } catch (DataException e) { answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (MarketException) { answer = new StoreAnswer(StoreEnum.NoPermission, "User validation as valid customer has been failed . only valid users can browse market. Error message has been created!"); } }
public void GetAllCategoryNames() { try { _shopper.ValidateCanBrowseMarket(); MarketLog.Log("StoreCenter", "User has enetered the system!"); string[] categories = _storeLogic.GetAllCategorysNames(); Answer = new StoreAnswer(GetCategoriesStatus.Success, "All categories names have been granted!", categories); } catch (StoreException e) { MarketLog.Log("StoreCenter", ""); Answer = new StoreAnswer((GetCategoriesStatus)e.Status, e.GetErrorMessage()); } catch (DataException e) { Answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (MarketException) { MarketLog.Log("StoreCenter", "no premission"); Answer = new StoreAnswer(GetCategoriesStatus.DidntEnterSystem, "User didn't enter the system!"); } }
public void GetAllDiscountCategoriesNameInStore(string storeName) { try { CheckIfStoreExistsAndActive(storeName); _shopper.ValidateCanBrowseMarket(); MarketLog.Log("StoreCenter", "User has enetered the system!"); string[] categories = _storeLogic.GetCategoriesWhichHaveDiscounts(storeName); Answer = new StoreAnswer(GetCategoriesDiscountStatus.Success, "All categories names have been granted!", categories); } catch (StoreException e) { MarketLog.Log("StoreCenter", ""); Answer = new StoreAnswer((GetCategoriesDiscountStatus)e.Status, e.GetErrorMessage()); } catch (DataException e) { Answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (MarketException) { MarketLog.Log("StoreCenter", "no premission"); Answer = new StoreAnswer(GetCategoriesDiscountStatus.DidntEnterSystem, "User didn't enter the system!"); } }
public void ViewStoreStock(string storename) { try { _storeName = storename; MarketLog.Log("StoreCenter", "checking store stack"); _shopper.ValidateCanBrowseMarket(); MarketLog.Log("StoreCenter", "check if store exists"); CheckIfStoreExists(storename); Store store = storeLogic.GetStorebyName(storename); LinkedList <string> result = new LinkedList <string>(); var IDS = storeLogic.GetAllStoreProductsID(store.SystemId); string info; foreach (string item in IDS) { info = GetProductStockInformation(item, false); if (info != "") { result.AddLast(info); } } string[] resultArray = new string[result.Count]; result.CopyTo(resultArray, 0); answer = new StoreAnswer(StoreEnum.Success, "", resultArray); } catch (StoreException e) { answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (DataException e) { answer = new StoreAnswer((StoreEnum)e.Status, e.GetErrorMessage()); } catch (MarketException) { MarketLog.Log("StoreCenter", "no premission"); answer = new StoreAnswer(StoreEnum.NoPermission, "User validation as valid customer has been failed . only valid users can browse market. Error message has been created!"); } }
public void SearchProduct(string value, double minPrice, double maxPrice, string category) { try { MarketLog.Log("StoreCenter", "searching for a product!"); _shopper.ValidateCanBrowseMarket(); MarketLog.Log("StoreCenter", "User enetred the system!"); validatePrices(minPrice, maxPrice); Product[] products; if (value.IsNullOrEmpty()) { products = _storeLogic.GetAllProducts(); } else { Product[] productsKeyWord = FindKeyWord(value); Product[] productsCategory = findProductsCategory(findSimilarCategories(value)); List <Product> product = new List <Product>(productsKeyWord); foreach (Product prod in productsCategory) { product.Add(prod); } products = product.ToArray(); } products = FilterResultsByPrice(products, minPrice, maxPrice); products = FilterResultByCategory(products, category); Answer = new StoreAnswer(SearchProductStatus.Success, "Data retrieved successfully!", AddStoreToProducts(products)); } catch (StoreException e) { Answer = new StoreAnswer((SearchProductStatus)e.Status, e.GetErrorMessage()); } catch (DataException e) { Answer = new StoreAnswer((SearchProductStatus)e.Status, e.GetErrorMessage()); } catch (MarketException) { MarketLog.Log("StoreCenter", "no premission"); Answer = new StoreAnswer(SearchProductStatus.DidntEnterSystem, "User Didn't enter the system!"); } }