public StockListItem AddNewProduct(string name, double price, string description, int quantity) { try { Store store = DataLayerInstance.GetStorebyName(_storeName); MarketLog.Log("StoreCenter", "trying to add product to store"); checkIfStoreExistsAndActive(); MarketLog.Log("StoreCenter", " store exists"); MarketLog.Log("StoreCenter", " check if has premmision to add products"); _storeManager.CanManageProducts(); MarketLog.Log("StoreCenter", " has premmission"); MarketLog.Log("StoreCenter", " check if product name avlaiable in the store" + _storeName); CheckInput(name, price, description, quantity); MarketLog.Log("StoreCenter", " Input is valid."); Product product = new Product(name, price, description); StockListItem stockListItem = new StockListItem(quantity, product, null, PurchaseEnum.Immediate, store.SystemId); DataLayerInstance.AddStockListItemToDataBase(stockListItem); MarketLog.Log("StoreCenter", "product added"); answer = new StoreAnswer(StoreEnum.Success, "product added"); return(stockListItem); } 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"); } return(null); }
public void RemoveProduct(string productName) { try { MarketLog.Log("StoreCenter", "trying to remove product from store"); checkIfStoreExistsAndActive(); MarketLog.Log("StoreCenter", " check if has premmision to remove products"); _storeManager.CanManageProducts(); MarketLog.Log("StoreCenter", " check if product name exists in the store " + _storeName); Product product = DataLayerInstance.GetProductByNameFromStore(_storeName, productName); checkifProductExists(product); MarketLog.Log("StoreCenter", "product exists"); StockListItem stockListItem = DataLayerInstance.GetProductFromStore(_storeName, productName); HandleIfLottery(stockListItem); DataLayerInstance.RemoveStockListItem(stockListItem); Answer = new StoreAnswer(StoreEnum.Success, "product removed"); } 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 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 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"); } }
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"); } }
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()); } }
public bool ProductExistsInQuantity(string storeName, string product, int quantity) { CheckThatStoreExitst(storeName); CheckThatProductExitst(storeName, product); StockListItem sli = DataLayer.GetProductFromStore(storeName, product); return(sli != null && sli.Quantity >= quantity); }
private void CheckIfAlreadyLottery(StockListItem stockListItem) { if (stockListItem.PurchaseWay == PurchaseEnum.Lottery) { MarketLog.Log("StoreCenter", " product has a lottery"); throw new StoreException(ChangeToLotteryEnum.LotteryExists, "product has a lottery"); } }
private static void CheckHasNoExistsDiscount(StockListItem stockListItem) { if (stockListItem.Discount == null) { return; } MarketLog.Log("StoreCenter", "the product have another discount"); throw new StoreException(DiscountStatus.ThereIsAlreadyAnotherDiscount, "the product have another discount"); }
private bool Equals(StockListItem obj) { var isDiscountsEqual = Discount?.Equals(obj.Discount) ?? obj.Discount == null; return(systemId.Equals(obj.systemId) && Quantity == obj.Quantity && Product.SystemId == obj.Product.SystemId && isDiscountsEqual && EnumStringConverter.PrintEnum(PurchaseWay).Equals(EnumStringConverter.PrintEnum(obj.PurchaseWay))); }
// this fucntion calculate item price if it has Hidden discount. happend only in Purches time and this is way it's happening here public double CalculateItemPriceWithDiscount(string storeName, string productName, string _DiscountCode, int _quantity) { if (!DataLayer.IsStoreExistAndActive(storeName)) { throw new StoreException(CalculateEnum.StoreNotExists, "store not exists"); } if (IsProductNameAvailableInStore(storeName, productName)) { throw new StoreException(CalculateEnum.ProductNotFound, "Product Not Found"); } StockListItem item = DataLayer.GetProductFromStore(storeName, productName); if (_quantity > item.Quantity) { throw new StoreException(CalculateEnum.QuantityIsGreaterThenStack, "quantity Is Greater Then Stack"); } if (_quantity <= 0) { throw new StoreException(CalculateEnum.QuanitityIsNonPositive, "quanitity is <=0"); } if (item.Discount == null) { throw new StoreException(CalculateEnum.ProductHasNoDiscount, "product has no discount"); } if (item.Discount.discountCode != _DiscountCode) { throw new StoreException(CalculateEnum.DiscountCodeIsWrong, "discount code is wrong"); } if (item.Discount.discountType != DiscountTypeEnum.Hidden) { throw new StoreException(CalculateEnum.DiscountIsNotHidden, "discount Is Not Hiddeng"); } if (MarketYard.MarketDate < item.Discount.startDate.Date) { throw new StoreException(CalculateEnum.DiscountNotStarted, "Discount Time Not Started Yet"); } if (MarketYard.MarketDate > item.Discount.EndDate.Date) { throw new StoreException(CalculateEnum.DiscountExpired, "discount expired"); } double ans = item.Discount.CalcDiscount(item.Product.BasePrice); CategoryDiscount categoryDiscount; foreach (string categoryName in item.Product.Categories) { categoryDiscount = null; categoryDiscount = DataLayer.GetCategoryDiscount(categoryName, storeName); if (categoryDiscount != null) { ans = categoryDiscount.CalcDiscount(ans); } } ans = ans * _quantity; return(ans); }
private void HandleIfLottery(StockListItem stockListItem) { if (stockListItem.PurchaseWay != PurchaseEnum.Lottery) { return; } LotterySaleManagmentTicket lotteryManagment = DataLayerInstance.GetLotteryByProductID(stockListItem.Product.SystemId); lotteryManagment.InformCancel(syncher); DataLayerInstance.RemoveLottery(lotteryManagment); }
public MarketAnswer AddNewProduct(string name, double price, string description, int quantity) { AddNewProductSlave slave = new AddNewProductSlave(_storeManager, _storeName, storeDL); StockListItem stockListItem = slave.AddNewProduct(name, price, description, quantity); if (stockListItem != null) { stockListItemToRemove.AddLast(stockListItem); } return(slave.answer); }
private void ValidateLottery(StockListItem stockList) { if (stockList.PurchaseWay != PurchaseEnum.Lottery) { return; } LotterySaleManagmentTicket lottery = DataLayerInstance.GetLotteryByProductID(stockList.Product.SystemId); lottery.InformCancel(syncher); DataLayerInstance.EditLotteryInDatabase(lottery); }
public MarketAnswer AddNewLottery(string name, double price, string description, DateTime startDate, DateTime endDate) { AddNewLotterySlave slave = new AddNewLotterySlave(_storeName, _storeManager, storeDL); StockListItem stockListItem = slave.AddNewLottery(name, price, description, startDate, endDate); if (stockListItem != null) { stockListItemToRemove.AddLast(stockListItem); } return(slave.answer); }
public void UpdateQuantityAfterPurchase(string storeName, string productName, int quantity) { CheckThatStoreExitst(storeName); CheckThatProductExitst(storeName, productName); StockListItem product = DataLayer.GetProductFromStore(storeName, productName); if (product.Quantity < quantity || quantity <= 0) { throw new StoreException(StoreSyncStatus.NoProduct, "product doesn't exist in this quantity"); } product.Quantity -= quantity; DataLayer.EditStockInDatabase(product); }
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); }
private void CheckifQuantityIsOK(int quantity, StockListItem stockListItem) { MarketLog.Log("StoreCenter", "checking that the required quantity is not too big"); if (quantity > stockListItem.Quantity) { MarketLog.Log("StoreCenter", "required quantity is not too big"); throw new StoreException(StoreEnum.QuantityIsTooBig, "required quantity is not too big"); } MarketLog.Log("StoreCenter", "checking that the required quantity is not negative or zero"); if (quantity > 0) { return; } MarketLog.Log("StoreCenter", "required quantity is negative or zero"); throw new StoreException(StoreEnum.QuantityIsNegative, "required quantity is negative"); }
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 AddStockListItemToDataBase(StockListItem stockListItem) { object[] itemVals = stockListItem.GetStockListItemArray(); foreach (object val in itemVals) { dbConnection.CheckInput(val.ToString()); } if (stockListItem.Discount != null) { AddDiscount(stockListItem.Discount); } AddProductToDatabase(stockListItem.Product); dbConnection.InsertTable("Stock", "StockID, ProductSystemID, quantity, discount, PurchaseWay", new [] { "@idParam", "@productIdParam", "@quantParam", "@discountParam", "@purchParam" }, itemVals); }
public void RemoveStockListItem(StockListItem stockListItem) { if (stockListItem.PurchaseWay == PurchaseEnum.Lottery) { var lsmt = GetLotteryByProductID(stockListItem.Product.SystemId); if (lsmt != null) { RemoveLottery(lsmt); } } if (stockListItem.Discount != null) { RemoveDiscount(stockListItem.Discount); } RemoveProduct(stockListItem .Product); // the DB will delete the StockListItem due to the conection between of the 2 tables }
public StockListItem GetStockListItembyProductID(string productid) { dbConnection.CheckInput(productid); Product product = GetProductID(productid); StockListItem stockListItem = null; using (var dbReader = dbConnection.SelectFromTableWithCondition("Stock", "*", "ProductSystemID = '" + productid + "'")) { while (dbReader.Read()) { stockListItem = new StockListItem(dbReader.GetInt32(2), product, GetDiscount(dbReader.GetString(3)), EnumStringConverter.GetPurchaseEnumString(dbReader.GetString(4)), dbReader.GetString(0)); return(stockListItem); } } return(stockListItem); }
public void EditStockInDatabase(StockListItem stockListItem) { string[] columnNames = { "StockID", "ProductSystemID", "quantity", "discount", "PurchaseWay" }; object[] itemVals = stockListItem.GetStockListItemArray(); foreach (object val in itemVals) { dbConnection.CheckInput(val.ToString()); } dbConnection.UpdateTable("Stock", "ProductSystemID = '" + stockListItem.Product.SystemId + "'", columnNames, new[] { "@idParam", "@productIdParam", "@quantParam", "@discountParam", "@purchParam" }, itemVals); }
private string GetProductStockInformation(string productID, bool showAll) { StockListItem stockListItem = storeLogic.GetStockListItembyProductID(productID); if (stockListItem == null) { MarketLog.Log("storeCenter", "product not exists"); throw new StoreException(StoreEnum.ProductNotFound, "product " + productID + " does not exist in Stock"); } if (stockListItem.PurchaseWay == PurchaseEnum.Lottery && !showAll) { LotterySaleManagmentTicket managmentTicket = storeLogic.GetLotteryByProductID((productID)); StockListItem sli = storeLogic.GetStockListItembyProductID(productID); if ((managmentTicket.EndDate < MarketYard.MarketDate) || (managmentTicket.StartDate > MarketYard.MarketDate) || ((managmentTicket.TotalMoneyPayed == managmentTicket.ProductNormalPrice) && sli.Quantity == 0)) { return(""); } } Discount totalDiscount = stockListItem.CalcTotalDiscount(_storeName); string discountString = " Discount: {"; string product = stockListItem.Product.ToString(); if (totalDiscount != null) { discountString += totalDiscount; } else { discountString += "null"; } discountString += "}"; string purchaseWay = " Purchase Way: " + EnumStringConverter.PrintEnum(stockListItem.PurchaseWay); string quanitity = " Quantity: " + stockListItem.Quantity; string result = product + discountString + purchaseWay + quanitity; return(result); }
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 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); }