Esempio n. 1
0
        public List <User> RemoveManagerLoop(User appointer, User DemoteOwner, Store store)
        {
            List <User> ManagersToRemove = new List <User>();

            RemoveAppoitment(appointer.Name, DemoteOwner.Name, store.Id);
            ManagersToRemove.Add(DemoteOwner);
            string Message = "You have been Removed From Manager position in the Store " + store.StoreName + " Due to the fact that you appointer " + DemoteOwner.getUserName() + "Was fired now\n";

            DemoteOwner.RemoveStoreManagment(store.GetStoreId());
            StoreManagersAppoint stap = DbManager.Instance.GetSingleManagerAppoints(appointer.getUserName(), DemoteOwner.getUserName(), store.Id);

            DbManager.Instance.DeleteSingleManager(stap);
            int[] pm = DemoteOwner.Store_options[store.Id];
            DemoteOwner.RemovePermission(store.GetStoreId());
            //Remove Permissions From DB
            List <UserStorePermissions> perms = DbManager.Instance.GetUserStorePermissionSet(store.Id, DemoteOwner.getUserName());

            DbManager.Instance.DeletePermission(perms);
            Publisher.Instance.Notify(DemoteOwner.getUserName(), new NotifyData(Message));
            Publisher.Instance.Unsubscribe(DemoteOwner.getUserName(), store.GetStoreId());
            List <string> Managers = store.managers;

            foreach (string managerName in Managers)
            {
                User manager = UserManager.Instance.GetUser(managerName);
                if (manager.isAppointedByManager(DemoteOwner, store.GetStoreId()))
                {
                    ManagersToRemove.AddRange(RemoveManagerLoop(DemoteOwner, manager, store));
                }
            }
            return(ManagersToRemove);
        }
        public void RemoveStoreManagerAppoint()
        {
            StoreManagersAppoint test = new StoreManagersAppoint("liav", "yossi", 1);

            DbManager.Instance.InsertStoreManagerAppoint(test);
            DbManager.Instance.DeleteSingleManager(test);
        }
Esempio n. 3
0
        //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"));
        }
Esempio n. 4
0
        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."));
        }