/// <req> https://github.com/chendoy/wsep_14a/wiki/Use-cases#use-case-store-products-in-the-shopping-basket-26 </req> /// <req> https://github.com/chendoy/wsep_14a/wiki/Use-cases#use-case-view-and-edit-shopping-cart-27 </req> /// Get the user ,store and product to add to the shopping cart /// Additionaly indicate how much items of the product should be in the cart /// <param name="exist"> means this product meant to be already in the cart (in case of change/remove existing product </param> public Tuple <bool, string> AddProductToShoppingCart(string userId, int storeId, int productId, int wantedAmount, bool exist) { Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod()); if (String.IsNullOrWhiteSpace(userId)) { Logger.logError(CommonStr.PurchaseMangmentErrorMessage.BlankOrNullInputErrMsg, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, CommonStr.PurchaseMangmentErrorMessage.BlankOrNullInputErrMsg)); } User user = userManager.GetAtiveUser(userId); if (user == null) { Logger.logError(CommonStr.StoreMangmentErrorMessage.nonExistOrActiveUserErrMessage, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, CommonStr.StoreMangmentErrorMessage.nonExistOrActiveUserErrMessage)); } Store store = storeManagment.getStore(storeId); if (store == null || !store.ActiveStore) { Logger.logError(CommonStr.StoreMangmentErrorMessage.nonExistingStoreErrMessage, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, CommonStr.StoreMangmentErrorMessage.nonExistingStoreErrMessage)); } if (!store.ProductExist(productId)) { return(new Tuple <bool, string>(false, CommonStr.InventoryErrorMessage.ProductNotExistErrMsg)); } if (wantedAmount < 0) { return(new Tuple <bool, string>(false, CommonStr.PurchaseMangmentErrorMessage.NegativeProductAmountErrMsg)); } if (!exist && wantedAmount == 0) { return(new Tuple <bool, string>(false, CommonStr.PurchaseMangmentErrorMessage.ZeroProductAmountErrMsg)); } int amount = store.GetProductDetails(productId).Item2; if (amount < wantedAmount) { return(new Tuple <bool, string>(false, CommonStr.InventoryErrorMessage.ProductShortageErrMsg)); } Cart cart; if (!carts.TryGetValue(userId, out cart)) { cart = CreateNewCart(userId); if (cart == null) { return(new Tuple <bool, string>(false, "there was error with CreateNewCart in the DB in addProduct Function")); } carts.Add(userId, cart); } return(cart.AddProduct(store, productId, wantedAmount, exist)); }
public static Store initValidStore() { StoreManagment sm = StoreManagment.Instance; UserManager userManager = UserManager.Instance; userManager.Register("shimon", "123"); userManager.Login("shimon", "123", false); sm.createStore("shimon", "Store"); userManager.Register("yosi", "123"); userManager.Login("yosi", "123"); userManager.Register("shmuel", "123"); userManager.Login("shmuel", "123"); AppoitmentManager appmgr = AppoitmentManager.Instance; appmgr.AppointStoreManager("shimon", "shmuel", 100); appmgr.AppointStoreManager("shimon", "yosi", 100); userManager.GetAtiveUser("shmuel").setPermmisions(100, new int[] { 0, 0, 1, 0, 0 }); userManager.GetAtiveUser("yosi").setPermmisions(100, new int[] { 1, 1, 0, 0, 0 }); Store validStore = sm.getStore(100); validStore.Inventory = InventoryTest.getInventory(InventoryTest.getValidInventroyProdList()); return(validStore); }
public void TestInitialize() { SM = StoreManagment.Instance; UM = UserManager.Instance; AP = AppoitmentManager.Instance; UM.Register("owner", "Test1"); UM.Register("Appointed", "Test1"); UM.Login("owner", "Test1"); UM.Login("Appointed", "Test1"); UM.Login("", "G", true); SM.createStore("owner", "Store"); UM.Register("user1", "Test1"); UM.Register("user2", "Test1"); UM.Register("user3", "Test1"); Assert.IsNotNull(UM.GetAtiveUser("owner")); Assert.IsNotNull(UM.GetAtiveUser("Appointed")); Assert.IsNotNull(UM.GetAtiveUser("Guest3")); Assert.IsTrue(UM.GetAtiveUser("Guest3").isguest()); Assert.IsTrue(UM.GetAtiveUser("owner").isStoreOwner(100)); Assert.IsTrue(SM.getStore(100).IsStoreOwner(UM.GetAtiveUser("owner"))); Assert.IsNotNull(SM.getStore(100)); }
public void TestInitialize() { PaymentDetails = "3333444455556666&4&11&Wolloloo&333&222222222"; DeliveryDetails = "dani&Wollu&Wollurberg&wolocountry&12345678"; SM = StoreManagment.Instance; UM = UserManager.Instance; AP = AppoitmentManager.Instance; purchaseManagement = PurchaseManagement.Instance; UM.Register("owner", "Test1"); UM.Register("Appointed", "Test1"); UM.Login("owner", "Test1"); UM.Login("Appointed", "Test1"); SM.createStore("owner", "Store"); SM.getStore(100).Inventory = getInventory(getValidInventroyProdList()); }
public Tuple <bool, string> ApproveAppoitment(string owner, string Appointed, int storeID, bool approval) { Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod()); if (owner == null || Appointed == null) { Logger.logError(CommonStr.ArgsTypes.None, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Null Arguments")); } if (owner == "" || Appointed == "") { Logger.logError(CommonStr.ArgsTypes.Empty, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Blank Arguemtns\n")); } Store store = storeManagment.getStore(storeID); if (store is null) { return(new Tuple <bool, string>(false, "Store Does not Exist")); } User appointer = UM.GetAtiveUser(owner); User appointed = UM.GetUser(Appointed); if (appointer is null || appointed is null) { return(new Tuple <bool, string>(false, "One of the users is not logged Exist\n")); } if (appointer.isguest() || appointed.isguest()) { return(new Tuple <bool, string>(false, "One of the users is a Guest\n")); } //Remove this approvalRequest if (appointer.INeedToApproveRemove(storeID, Appointed)) { //Remove The Pending for the user if (appointed.RemoveOtherApprovalRequest(storeID, owner)) { //Remove Need to Approve From DB try { NeedToApprove ndap = DbManager.Instance.GetNeedToApprove(owner, Appointed, storeID); DbManager.Instance.DeleteSingleApproval(ndap); } catch (Exception ex) { Logger.logError("DeleteSingleApproval error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Delete Operation from DB Failed cannot proceed")); } } } //Set to false if False and the operation will fail. if (!approval) { RemoveCnadidate(owner, Appointed, storeID); appointed.SetApprovalStatus(storeID, approval); //Update The Approval Status in the DB //Remove MasterAppointer - Candidtae Table from DB string masterNmae = appointed.MasterAppointer[storeID]; appointed.RemoveMasterAppointer(storeID); try { StoreOwnertshipApprovalStatus status = DbManager.Instance.getApprovalStat(Appointed, storeID); CandidateToOwnership cand = DbManager.Instance.GetCandidateToOwnership(Appointed, masterNmae, storeID); Publisher.Instance.Notify(Appointed, new NotifyData("Your request to be an Owner to Store - " + storeID + " Didn't Approved")); DbManager.Instance.DeApprovalTransaction(status, approval, cand, true); //DbManager.Instance.DeleteSingleCandidate(cand); //DbManager.Instance.UpdateApprovalStatus(status, approval); } catch (Exception ex) { Logger.logError("De-Approval db error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "De-Approval Operation from DB Failed cannot proceed")); } return(new Tuple <bool, string>(true, "User failed to become an owner")); } if (appointed.CheckSApprovalStatus(storeID)) { RemoveCnadidate(owner, Appointed, storeID); //User can be assigned to Store owner appointed.RemoveApprovalStatus(storeID); string Mappointer = appointed.MasterAppointer[storeID]; //Add Store Ownership in store Liav is incharge of this if (!appointed.addStoreOwnership(storeID, Mappointer).Item1) { StoreOwner so = DbManager.Instance.getStoreOwnerbyStore(appointed.getUserName(), store.Id); DbManager.Instance.DeleteStoreOwner(so, true); return(new Tuple <bool, string>(false, "Failed to insert store owner to DB memory")); } appointed.AppointerMasterAppointer(storeID); if (!store.AddStoreOwner(appointed)) { return(new Tuple <bool, string>(false, "Failed to insert store owner to DB memory")); } insertAppointment(owner, Appointed, storeID); if (store.IsStoreManager(appointed)) { try { StoreManagersAppoint Sma = DbManager.Instance.GetSingleManagerAppoints(appointed.Store_Managment[storeID], appointed.Name, storeID); DbManager.Instance.DeleteSingleManager(Sma); } catch (Exception ex) { Logger.logError("Remove Store Manager db error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Could not Remove Manager store from DB")); } store.RemoveManager(appointed); appointed.RemoveStoreManagment(storeID); } Publisher.Instance.Notify(Appointed, new NotifyData("Your request to be an Owner to Store - " + storeID + " is Approved")); Tuple <bool, string> ans = Publisher.Instance.subscribe(Appointed, storeID); try { CandidateToOwnership cand = DbManager.Instance.GetCandidateToOwnership(Appointed, Mappointer, storeID); DbManager.Instance.DeleteSingleCandidate(cand); //Delete Approval Status from DB StoreOwnertshipApprovalStatus status = DbManager.Instance.getApprovalStat(Appointed, storeID); DbManager.Instance.DeleteSingleApprovalStatus(status); DbManager.Instance.SaveChanges(); } catch (Exception ex) { Logger.logError("Inser Store Owner db error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Inser Store Owner Operation from DB Failed cannot proceed")); } return(ans); } DbManager.Instance.SaveChanges(); return(new Tuple <bool, string>(true, "User Still has some Work to do before he can become an Owner of this Store.")); }
public Store GetStoreById(int storeID) { return(storeManagment.getStore(storeID)); }
public void createStoreTest() { SM.createStore("owner", "Store"); Assert.IsTrue(SM.getStore(100).IsStoreOwner(UM.GetUser("owner"))); Assert.IsTrue(UM.GetUser("owner").isStoreOwner(100)); }
private Store getStoreDriver(int storeId) { return(storeManagment.getStore(storeId)); }
public void AddNewStoreOwnerWaitingList() { Assert.IsTrue(AP.AppointStoreOwner("owner", "Appointed", 100).Item1); AP.AppointStoreOwner("owner", "user1", 100); Assert.IsFalse(SM.getStore(100).IsStoreOwner(UM.GetUser("user1"))); Assert.IsFalse(UM.GetUser("user1").isAppointedByOwner("owner", 100)); Assert.IsFalse(UM.GetUser("user1").isStoreOwner(100)); }