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()); } }
public static string[] PromoteStorePolicies(string userName, string store, StoreManagerPolicy.StoreAction[] actionsToAdd) { var userDB = UserDL.Instance; if (!userDB.IsUserNameExist(userName)) { throw new UserException(PromoteStoreStatus.NoUserFound, "No user by the name '" + userName + " has been found for promotion!"); } foreach (StoreManagerPolicy.StoreAction oldAction in Enum.GetValues(typeof(StoreManagerPolicy.StoreAction))) { userDB.DeleteUserStorePolicy(userName, new StoreManagerPolicy(store, oldAction)); } if (actionsToAdd.Contains(StoreManagerPolicy.StoreAction.StoreOwner)) { actionsToAdd = new [] { StoreManagerPolicy.StoreAction.StoreOwner }; } var actionsThatAddedSuccessfully = new List <string>(); foreach (StoreManagerPolicy.StoreAction action in actionsToAdd) { userDB.SaveUserStorePolicy(userName, new StoreManagerPolicy(store, action)); actionsThatAddedSuccessfully.Add(StoreManagerPolicy.GetStoreActionString(action)); } return(actionsThatAddedSuccessfully.ToArray()); }
public void SaveUserStorePolicy(int userID, StoreManagerPolicy policy) { dbConnection.CheckInput(policy.Store); dbConnection.CheckInput(StoreManagerPolicy.GetStoreActionString(policy.Action)); string[] valuesNames = { "@idParam", "@storeParam", "@actionParam" }; object[] values = { userID, policy.Store, StoreManagerPolicy.GetStoreActionString(policy.Action) }; dbConnection.InsertTable("StoreManagerPolicy", "SystemID,Store,Action", valuesNames, values); }
public void AddStoreOwnership(string store) { StoreManagerPolicy storeOwnershipPermission = new StoreManagerPolicy(store, StoreManagerPolicy.StoreAction.StoreOwner); StorePolicies.Add(storeOwnershipPermission); _userDB.SaveUserStorePolicy(_userID, storeOwnershipPermission); }
public void DeleteUserStorePolicy(string userName, StoreManagerPolicy policy) { dbConnection.CheckInput(policy.Store); dbConnection.CheckInput(policy.Action.ToString()); int idOfDemoted = GetIDFromUserName(userName); dbConnection.DeleteFromTable("StoreManagerPolicy", "SystemID = " + idOfDemoted + " AND Store = '" + policy.Store + "' AND Action = '" + policy.Action + "'"); }
public StoreManagerPolicy[] LoadUserStorePolicies(int userID) { List <StoreManagerPolicy> loadedStorePolicies = new List <StoreManagerPolicy>(); using (var dbReader = dbConnection.SelectFromTableWithCondition("StoreManagerPolicy", "*", "SystemID = " + userID)) { while (dbReader.Read()) { string storeName = dbReader.GetString(1); StoreManagerPolicy.StoreAction action = StoreManagerPolicy.GetActionFromString(dbReader.GetString(2)); loadedStorePolicies.Add(new StoreManagerPolicy(storeName, action)); } } return(loadedStorePolicies.ToArray()); }
private bool Equals(StoreManagerPolicy obj) { return(obj.Store.Equals(Store) && obj.Action == Action); }