//Register the system admin public Tuple <bool, string> RegisterMaster(string username, string pass) { Logger.logSensitive(this, System.Reflection.MethodBase.GetCurrentMethod()); Tuple <bool, string> ans = name_and_pass_check(username, pass); if (!ans.Item1) { return(ans); } User System_Admin = new User(0, username, false, true); users.Add(username, System_Admin); string sha1 = SB.CalcSha1(pass); Users_And_Hashes.Add(username, sha1); DbUser dbadmin = DbManager.Instance.GetUser(username); if (dbadmin == null) { DbManager.Instance.InsertUser(AdapterUser.CreateDBUser(username, false, true, false)); DbManager.Instance.InsertPassword(AdapterUser.CreateNewPasswordEntry(username, sha1), true); } return(new Tuple <bool, string>(true, "")); }
//Set User permission over spesific store public Tuple <bool, string> setPermmisions(int store_id, int[] permission_set, bool saveChanges = false) { Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod()); if (store_id < 1) { return(new Tuple <bool, string>(false, "No such Store id\n")); } if (permission_set == null) { return(new Tuple <bool, string>(false, "Null Argument\n")); } if (!isStorManager(store_id) && !isStoreOwner(store_id)) { return(new Tuple <bool, string>(false, "The user is not Store Manager or owner\n")); } if (Store_options.ContainsKey(store_id)) { int[] oldp = Store_options[store_id]; List <UserStorePermissions> perms = DbManager.Instance.GetUserStorePermissionSet(store_id, this.Name); Store_options.Remove(store_id); try { DbManager.Instance.DeletePermission(perms); } catch (Exception ex) { Logger.logError("Delete Permissions error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Delete Permissions DB Failed cannot proceed")); } } Store_options.Add(store_id, permission_set); List <UserStorePermissions> permsN = AdapterUser.CreateNewPermissionSet(Name, store_id, permission_set); try { DbManager.Instance.InsertUserStorePermissionSet(permsN, saveChanges); } catch (Exception ex) { Logger.logError("Insert Permissions error : " + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Insert Permissions DB Failed cannot proceed")); } return(new Tuple <bool, string>(true, "")); }
//Register regular user to the system //User name must be unique public Tuple <bool, string> Register(string username, string pass) { Logger.logSensitive(this, System.Reflection.MethodBase.GetCurrentMethod()); Tuple <bool, string> ans = name_and_pass_check(username, pass); if (!ans.Item1) { return(ans); } User nUser = new User(Available_ID, username, false); users.Add(username, nUser); //insert to user to db: DbManager.Instance.InsertUser(AdapterUser.CreateDBUser(username, false, false, false)); Available_ID++; string sha1 = SB.CalcSha1(pass); Users_And_Hashes.Add(username, sha1); DbManager.Instance.InsertPassword(AdapterUser.CreateNewPasswordEntry(username, sha1), true); return(new Tuple <bool, string>(true, "")); }
//Owner appoints addto to be Store Manager. //Set his permissions to the store to be [1,1,0] only read and view public Tuple <bool, string> AppointStoreManager(string owner, string addto, int storeId) { Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod()); Store store = storeManagment.getStore(storeId); if (store is null) { return(new Tuple <bool, string>(false, "Store Does not Exist")); } if (owner == null || addto == null) { Logger.logError(CommonStr.ArgsTypes.None, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Null Arguments")); } if (owner == "" || addto == "") { Logger.logError(CommonStr.ArgsTypes.Empty, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Blank Arguemtns\n")); } User appointer = UM.GetAtiveUser(owner); User appointed = UM.GetUser(addto); 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")); } if (store.IsStoreOwner(appointed) || store.IsStoreManager(appointed)) { return(new Tuple <bool, string>(false, addto + " Is already Store Owner or Manager\n")); } if (!store.IsStoreOwner(appointer) && !store.IsStoreManager(appointer)) { return(new Tuple <bool, string>(false, owner + "Is not a store Owner or Manager\n")); } //appointed.addManagerAppointment(appointer, store.GetStoreId()); Tuple <bool, string> res = appointed.addStoreManagment(store, owner); if (!res.Item1) { return(new Tuple <bool, string>(false, "Insert to store Managmnet Failed to DB")); } if (!store.AddStoreManager(appointed)) { return(new Tuple <bool, string>(false, "Insert to store Managmnet Failed to DB")); } //Insert StoreManager Appoint Into DB int[] p = { 1, 1, 0, 0, 0 }; appointed.setPermmisions(store.GetStoreId(), p); try { DbManager.Instance.InsertStoreManagerAppoint(AdapterUser.CreateNewManagerAppoitment(owner, addto, storeId), true); } catch (Exception ex) { Logger.logError("Managment status to approve isnert Failed" + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); } //Version 2 Addition Tuple <bool, string> ans = Publisher.Instance.subscribe(addto, storeId); if (!ans.Item1) { return(ans); } return(res); }
//Owner appoints addto to be Store Owner. public Tuple <bool, string> AppointStoreOwner(string owner, string addto, int storeId) { Logger.logEvent(this, System.Reflection.MethodBase.GetCurrentMethod()); Store store = storeManagment.getStore(storeId); if (store is null) { return(new Tuple <bool, string>(false, "Store Does not Exist")); } if (owner == null || addto == null) { Logger.logError(CommonStr.ArgsTypes.None, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Null Arguments")); } if (owner == "" || addto == "") { Logger.logError(CommonStr.ArgsTypes.Empty, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Blank Arguemtns\n")); } User appointer = UM.GetAtiveUser(owner); User appointed = UM.GetUser(addto); 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")); } if (store.IsStoreOwner(appointed)) { return(new Tuple <bool, string>(false, addto + " Is already Store Owner\n")); } if (!store.IsStoreOwner(appointer)) { return(new Tuple <bool, string>(false, owner + "Is not a store Owner\n")); } appointed.SetMasterAppointer(storeId, appointer); List <string> owners = new List <string>(); foreach (string ow in store.getOwners()) { owners.Add(ow); } owners.Remove(owner); if (owners.Count == 0) { //Is ready to become Owner. insertAppointment(owner, addto, storeId); string maserAppointer = appointed.MasterAppointer[storeId]; appointed.MasterAppointer.Remove(storeId); if (!appointed.addStoreOwnership(storeId, appointer.getUserName()).Item1) { return(new Tuple <bool, string>(false, "Could not add store Owner to DB")); } if (!store.AddStoreOwner(appointed)) { return(new Tuple <bool, string>(false, "Could not add store Owner to DB")); } 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(addto, new NotifyData("Your request to be an Owner to Store - " + storeId + " is Approved")); Tuple <bool, string> ansSuccess = Publisher.Instance.subscribe(addto, storeId); DbManager.Instance.SaveChanges(); return(ansSuccess); } //Add Candidate TO ownership appointed.SetApprovalStatus(storeId, true); //No need to Inser Here Approvals we will Insert in the Inner Loop by the Owners. appointed.InsertOtherApprovalRequest(storeId, owners); foreach (string storeOwner in owners) { User tmpOwner = UM.GetUser(storeOwner); try { DbManager.Instance.InsertNeedToApprove(AdapterUser.CreateNewApprovalNote(storeOwner, addto, storeId)); } catch (Exception ex) { appointed.RemoveApprovalStatus(storeId); appointed.RemoveOtherApprovalList(storeId); Logger.logError("Need to approve isnert Failed" + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); return(new Tuple <bool, string>(false, "Insert Failed")); } } foreach (string storeOwner in owners) { User tmpOwner = UM.GetUser(storeOwner); tmpOwner.INeedToApproveInsert(storeId, addto); Publisher.Instance.Notify(storeOwner, new NotifyData("User: "******" Is want to Be store:" + storeId + " Owner Let him know what you think")); } //Add AptovmentStatus to DB insertCandidate(owner, addto, storeId); try { DbManager.Instance.InsertStoreOwnerShipApprovalStatus(AdapterUser.CreateNewStoreAppoitmentApprovalStatus(storeId, true, addto)); DbManager.Instance.InsertCandidateToOwnerShip(AdapterUser.CreateCandidate(owner, addto, storeId), true); } catch (Exception ex) { Logger.logError("Ownership status to approve isnert Failed" + ex.Message, this, System.Reflection.MethodBase.GetCurrentMethod()); appointed.RemoveApprovalStatus(storeId); appointed.RemoveOtherApprovalList(storeId); foreach (string storeOwner in owners) { User tmpOwner = UM.GetUser(storeOwner); NeedToApprove nta = DbManager.Instance.GetNeedToApprove(storeOwner, addto, storeId); tmpOwner.INeedToApproveRemove(storeId, addto); } return(new Tuple <bool, string>(false, "Ownership status Failed")); } return(new Tuple <bool, string>(true, "Waiting For Approal By store Owners")); }