Пример #1
0
 public ViewUsersSlave(User user, IUserDL userDB)
 {
     Answer  = null;
     _user   = user;
     _userDB = userDB;
     userID  = user?.SystemID ?? -1;
 }
Пример #2
0
 public User SignIn(string name, string password)
 {
     try
     {
         MarketLog.Log("UserSpot", "User " + guestID + " attempting to sign in the system...");
         ApproveSignIn(name, password);
         string encryptedPassword = UserSecurityService.ToEncryptPassword(_guest.SystemID, password);
         MarketLog.Log("UserSpot", "Searching for existing user and logging in Guest "
                       + guestID + " into the system...");
         object[] userData   = ValidateUserExist(name, encryptedPassword);
         User     loggedUser = _userDB.LoadUser(userData, _guest.Cart.GetCartStorage());
         MarketLog.Log("UserSpot", "User " + loggedUser.SystemID + " sign in to the system has been successfull!");
         MarketLog.Log("UserSpot", "User " + loggedUser.SystemID + " is now recognized as Registered User "
                       + loggedUser.SystemID);
         string returnedState = loggedUser.IsSystemAdmin() ? "Admin" : "Registered";
         Answer = new UserAnswer(SignInStatus.Success, "Sign in has been successful!", loggedUser.SystemID, returnedState);
         return(loggedUser);
     }
     catch (UserException e)
     {
         MarketLog.Log("UserSpot",
                       "User " + guestID + " has failed to sign in. Error message has been created!");
         Answer = new UserAnswer((SignInStatus)e.Status, e.GetErrorMessage());
         return(_guest);
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((SignInStatus)e.Status, e.GetErrorMessage());
         return(_guest);
     }
 }
Пример #3
0
 public GetControlledStoreNamesSlave(User user, IUserDL userDB)
 {
     Answer  = null;
     _user   = user;
     _userDB = userDB;
     userID  = user?.SystemID ?? -1;
 }
Пример #4
0
        public void RemoveFromCart(string product, string store, double unitPrice)
        {
            try
            {
                MarketLog.Log("UserSpot",
                              "User " + userID + " attempting to remove his cart item: " + product + " from store: " + store +
                              " ...");
                CartItem toRemove = ApproveModifyCart(store, product, unitPrice);

                MarketLog.Log("UserSpot",
                              "User " + userID + " found cart item: " + product + " from store: " + store +
                              ". proceeding for the removal...");
                _user.Cart.RemoveFromCart(toRemove);
                MarketLog.Log("UserSpot",
                              "User " + userID + "successfully removed cart item: " + product + " from store: " + store + " ...");
                Answer = new UserAnswer(RemoveFromCartStatus.Success, "Remove Cart Item has been successful!");
            }
            catch (UserException e)
            {
                Answer = new UserAnswer((RemoveFromCartStatus)e.Status, e.GetErrorMessage());
            }
            catch (DataException e)
            {
                Answer = new UserAnswer((RemoveFromCartStatus)e.Status, e.GetErrorMessage());
            }
        }
Пример #5
0
        public void GetStoreManagerPolicies(string store)
        {
            try
            {
                MarketLog.Log("UserSpot", "User " + userID + " attempting to view this policies in the store " + store);
                ApproveEnetered();
                MarketLog.Log("UserSpot", "User " + userID + " has successfully viewing his policies in this store...");
                StoreManagerPolicy[] policies       = _user.GetStoreManagerPolicies(store);
                string[]             stringPolicies = { "Manage Products", "Promote Store Admins",   "Manage Store Discounts",
                                                        "View Purchase History",       "View Promotion History", "Manage Store Purchase-Policy" };

                if (!_user.IsSystemAdmin())
                {
                    stringPolicies = new string[policies.Length];
                    int count = 0;
                    foreach (StoreManagerPolicy policy in policies)
                    {
                        stringPolicies[count] = StoreManagerPolicy.GetStoreActionName(policy.Action);
                        count++;
                    }
                }
                Answer = new UserAnswer(GetStoreManagerPoliciesStatus.Success, "View of store policies has been successfully granted!",
                                        stringPolicies);
            }
            catch (UserException e)
            {
                Answer = new UserAnswer((GetStoreManagerPoliciesStatus)e.Status, e.GetErrorMessage());
            }
            catch (DataException e)
            {
                Answer = new UserAnswer((GetStoreManagerPoliciesStatus)e.Status, e.GetErrorMessage());
            }
        }
Пример #6
0
 public SignInSlave(User guest, IUserDL userDB)
 {
     _userDB = userDB;
     Answer  = null;
     _guest  = guest;
     guestID = _guest?.SystemID ?? -1;
 }
Пример #7
0
 public User SignUp(string name, string address, string password, string creditCard)
 {
     try
     {
         MarketLog.Log("UserSpot", "User " + currentID + " attempting to sign up to the system...");
         ApproveSignUp(name, address, password, creditCard);
         string encryptedPassword = UserSecurityService.ToEncryptPassword(_guest.SystemID, password);
         MarketLog.Log("UserSpot", "Searching for existing user and storing newly Registered User "
                       + currentID + " data...");
         ValidateUserNotExist(name);
         RegisteredUser newRegistered = _userDB.RegisterUser(_guest.SystemID, name, address, encryptedPassword,
                                                             creditCard, _guest.Cart.GetCartStorage());
         MarketLog.Log("UserSpot", "User " + newRegistered.SystemID + " sign up to the system has been successfull!");
         Answer = new UserAnswer(SignUpStatus.Success, "Sign up has been successfull!");
         _publisher.AddFeedQueue(newRegistered.SystemID);
         return(newRegistered);
     }
     catch (UserException e)
     {
         Answer = new UserAnswer((SignUpStatus)e.Status, e.GetErrorMessage());
         return(_guest);
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((SignUpStatus)e.Status, e.GetErrorMessage());
         return(_guest);
     }
 }
Пример #8
0
 public SignUpSlave(User guest, IUserDL userDB, IPublisher publisher)
 {
     _userDB    = userDB;
     Answer     = null;
     _guest     = guest;
     currentID  = _guest?.SystemID ?? -1;
     _publisher = publisher;
 }
Пример #9
0
 public void ViewStores()
 {
     try
     {
         MarketLog.Log("UserSpot", "User " + userID + " attempting to view all store names...");
         ApproveEnetered();
         var storeNames = _userDB.GetAllActiveStoreNames();
         Answer = new UserAnswer(ViewStoresStatus.Success, "you've got all the store names!", storeNames);
     }
     catch (UserException)
     {
         Answer = new UserAnswer(ViewStoresStatus.NoPermission, "The operation didn't succeed!");
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((GetControlledStoresStatus)e.Status, e.GetErrorMessage());
     }
 }
Пример #10
0
 public void GetControlledStoreNames()
 {
     try
     {
         MarketLog.Log("UserSpot", "User " + userID + " attempting to view which store he can manage...");
         ApproveEnetered();
         MarketLog.Log("UserSpot", "User " + userID + " has successfully retrieved all store names...");
         Answer = new UserAnswer(GetControlledStoresStatus.Success, "View of store names has been granted successfully!",
                                 FindControlledStoresOfUser());
     }
     catch (UserException e)
     {
         Answer = new UserAnswer((GetControlledStoresStatus)e.Status, e.GetErrorMessage());
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((GetControlledStoresStatus)e.Status, e.GetErrorMessage());
     }
 }
Пример #11
0
 public void ViewUsers()
 {
     try
     {
         MarketLog.Log("UserSpot", "User " + userID + " attempting to view all users...");
         ApproveEnetered();
         MarketLog.Log("UserSpot", "User " + userID + " has successfully retrieved all users info...");
         Answer = new UserAnswer(ViewUsersStatus.Success, "View of users has been granted successfully!",
                                 _userDB.UserNamesInSystem());
     }
     catch (UserException e)
     {
         Answer = new UserAnswer((ViewUsersStatus)e.Status, e.GetErrorMessage());
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((ViewUsersStatus)e.Status, e.GetErrorMessage());
     }
 }
Пример #12
0
 public void ViewCart()
 {
     try
     {
         MarketLog.Log("UserSpot", "User " + userID + " attempting to view his cart...");
         ApproveEnetered();
         MarketLog.Log("UserSpot", "User " + userID + " has successfully retrieved his cart info...");
         Answer = new UserAnswer(ViewCartStatus.Success, "View of the user's cart has been granted successfully!",
                                 _user.Cart.GetCartStorageToString());
     }
     catch (UserException e)
     {
         Answer = new UserAnswer((ViewCartStatus)e.Status, e.GetErrorMessage(), null);
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((ViewCartStatus)e.Status, e.GetErrorMessage(), null);
     }
 }
Пример #13
0
        public void GetUserDetails()
        {
            try
            {
                MarketLog.Log("UserSpot", "User " + userID + " attempting to view his own details...");
                ApproveEnetered();
                var userDetails = ExtractDetails();
                MarketLog.Log("UserSpot", "User " + userID + " has successfully retrieved all his own user details...");

                Answer = new UserAnswer(GetUserDetailsStatus.Success, "Data of user details has been granted successfully!",
                                        userDetails);
            }
            catch (UserException e)
            {
                Answer = new UserAnswer((GetUserDetailsStatus)e.Status, e.GetErrorMessage());
            }
            catch (DataException e)
            {
                Answer = new UserAnswer((GetUserDetailsStatus)e.Status, e.GetErrorMessage());
            }
        }
Пример #14
0
 public User EnterSystem()
 {
     try
     {
         MarketLog.Log("UserSpot", "New User attempting to enter the system...");
         User newGuest = new User(_userDB, GenerateSystemID());
         MarketLog.Log("UserSpot", "User " + newGuest.SystemID + " has entered the system! " +
                       "attempting to save the user entry...");
         _userDB.SaveUser(newGuest);
         MarketLog.Log("UserSpot", "User " + newGuest.SystemID + " has been saved successfully as new " +
                       "guest entry in the system!");
         Answer = new UserAnswer(EnterSystemStatus.Success, "You've been entered the system successfully!",
                                 newGuest.SystemID);
         _userDB.InsertSignedInUser(newGuest.SystemID);
         return(newGuest);
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((EnterSystemStatus)e.Status, e.GetErrorMessage());
         return(null);
     }
 }
Пример #15
0
 public void EditCartItem(string store, string product, int quantity, double unitPrice)
 {
     try
     {
         MarketLog.Log("UserSpot", "User " + userID + " attempting to edit his cart item: " + product + " from store: " + store + " ...");
         CartItem toEdit = ApproveModifyCart(store, product, unitPrice);
         MarketLog.Log("UserSpot",
                       "User " + userID + " found cart item: " + product + " from store: " + store +
                       ". proceeding for the edit...");
         _user.Cart.EditCartItem(toEdit, quantity);
         MarketLog.Log("UserSpot",
                       "User " + userID + "successfully edited cart item: " + product + " from store: " + store + " ...");
         Answer = new UserAnswer(EditCartItemStatus.Success, "Edit Cart Item has been successful!");
     }
     catch (UserException e)
     {
         Answer = new UserAnswer((EditCartItemStatus)e.Status, e.GetErrorMessage());
     }
     catch (DataException e)
     {
         Answer = new UserAnswer((EditCartItemStatus)e.Status, e.GetErrorMessage());
     }
 }
Пример #16
0
 public EditCartItemSlave(User user)
 {
     Answer = null;
     _user  = user;
     userID = user?.SystemID ?? -1;
 }
Пример #17
0
 public GetStoreManagerPoliciesSlave(User user)
 {
     Answer = null;
     _user  = user;
     userID = user?.SystemID ?? -1;
 }
Пример #18
0
 public ViewCartSlave(User user)
 {
     Answer = null;
     _user  = user;
     userID = user?.SystemID ?? -1;
 }
Пример #19
0
 public EnterSystemSlave(IUserDL userDB)
 {
     _userDB = userDB;
     Answer  = null;
 }
Пример #20
0
 public RemoveFromCartSlave(User user)
 {
     Answer = null;
     _user  = user;
     userID = user?.SystemID ?? -1;
 }
Пример #21
0
 public GetUserDetailsSlave(User user)
 {
     Answer = null;
     _user  = user;
     userID = user?.SystemID ?? -1;
 }