コード例 #1
0
ファイル: Party.cs プロジェクト: hatefi-arman/Modules
        public virtual void UpdateCustomActions(Dictionary<ActionType, bool> customActionsParam)
        {
            var actions = customActionsParam.Keys;
            foreach (var action in actions)
            {
                var isGranted = customActionsParam[action];

                if (CustomActions.Count(p => p.ActionTypeId == action.Id) > 0)
                {
                    var actionType = CustomActions.Single(ca => ca.ActionTypeId == action.Id);
                    actionType.IsGranted = isGranted;
                }
                else
                {
                    var customAction = new PartyCustomAction(this.Id, action.Id, isGranted);

                    CustomActions.Add(customAction);
                }


                CustomActions.RemoveAll(ca => actions.Count(ac => ac.Id == ca.ActionTypeId) == 0);

            }

            #endregion

        }
コード例 #2
0
ファイル: Party.cs プロジェクト: hatefi-arman/Modules
        public virtual void AssignCustomActions(ActionType actionType, bool isGranted)
        {
            if (actionType == null)
                throw new FuelSecurityException(0, "عدم دسترسی مناسب");


            if (this.CustomActions.Count(p => p.ActionTypeId == actionType.Id) > 0)
            {
                CustomActions.RemoveAll(pa => pa.ActionTypeId == actionType.Id);
            }

            var customAction = new PartyCustomAction(this.Id, actionType.Id, isGranted);

            CustomActions.Add(customAction);

        }
コード例 #3
0
ファイル: SecurityTests.cs プロジェクト: hatefi-arman/Modules
        public void TestCustomActionToUserAssignmentLowLevel()
        {
            using (var ctx = new DataContainer())
            {
                foreach (var action in ActionType.GetAllActions())
                {
                    ctx.ActionTypes.Add(action);
                }

                ctx.SaveChanges();
            }

            var user = new User(1, "User", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "fueluser");

            var customAction = new PartyCustomAction(1, ActionType.AddCharterIn.Id, false);

            using (var ctx = new DataContainer())
            {
                ctx.Parties.Add(user);
                ctx.SaveChanges();

                ctx.PartyCustomActions.Add(customAction);
                ctx.SaveChanges();
            }

            using (var ctx = new DataContainer())
            {
                var insertedUser = ctx.Parties.OfType<User>().Single(u=>u.Id == 1);

                Assert.IsTrue(insertedUser.CustomActions.Count == 1 &&
                    insertedUser.CustomActions.Count(ca => ca.Id == customAction.Id) == 1);

                var addedCustomAction = insertedUser.CustomActions.Single(ca => ca.Id == customAction.Id);

                Assert.IsNotNull(addedCustomAction);

                Assert.IsTrue(addedCustomAction.ActionTypeId == customAction.ActionTypeId &&
                    addedCustomAction.IsGranted == customAction.IsGranted);
            }
        }