Inheritance: RevisableEntity
Exemplo n.º 1
0
 public void HasGetSet()
 {
     var value = new Establishment();
     var entity = new RoleGrant { ForEstablishment = value };
     entity.ShouldNotBeNull();
     entity.ForEstablishment.ShouldEqual(value);
 }
Exemplo n.º 2
0
 public void HasGetSet()
 {
     var value = new User();
     var entity = new RoleGrant { User = value };
     entity.ShouldNotBeNull();
     entity.User.ShouldEqual(value);
 }
Exemplo n.º 3
0
 public void HasGetSet()
 {
     var value = new Role();
     var entity = new RoleGrant { Role = value };
     entity.ShouldNotBeNull();
     entity.Role.ShouldEqual(value);
 }
Exemplo n.º 4
0
        public void Handle(GrantRoleToUserCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var role = command.Role ??
                       _entities.Get <Role>()
                       .EagerLoad(_entities, new Expression <Func <Role, object> >[]
            {
                r => r.Grants,
            })
                       .By(command.RoleGuid);

            var grant = role.Grants.ByUser(command.UserGuid);

            if (grant != null)
            {
                return;
            }

            var user = _entities.Get <User>().By(command.UserGuid);

            grant = new RoleGrant
            {
                Role = role,
                User = user,
            };
            _entities.Create(grant);
            command.IsNewlyGranted = true;
        }
Exemplo n.º 5
0
            public void HasGetSet()
            {
                var value  = new Establishment();
                var entity = new RoleGrant {
                    ForEstablishment = value
                };

                entity.ShouldNotBeNull();
                entity.ForEstablishment.ShouldEqual(value);
            }
Exemplo n.º 6
0
            public void HasGetSet()
            {
                var value  = new Role();
                var entity = new RoleGrant {
                    Role = value
                };

                entity.ShouldNotBeNull();
                entity.Role.ShouldEqual(value);
            }
Exemplo n.º 7
0
            public void HasGetSet()
            {
                var value  = new User();
                var entity = new RoleGrant {
                    User = value
                };

                entity.ShouldNotBeNull();
                entity.User.ShouldEqual(value);
            }
Exemplo n.º 8
0
        internal static string ToJsonAudit(this RoleGrant entity)
        {
            var state = JsonConvert.SerializeObject(new
            {
                Id = entity.RevisionId,
                ForEstablishmentId = entity.ForEstablishment != null ? entity.ForEstablishment.RevisionId : (int?)null,
                UserId             = entity.User.RevisionId,
                RoleId             = entity.Role.RevisionId,
            });

            return(state);
        }
Exemplo n.º 9
0
        public void Handle(GrantRoleToUser command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var role = _entities.Get <Role>()
                       .EagerLoad(_entities, new Expression <Func <Role, object> >[]
            {
                r => r.Grants,
            })
                       .Single(x => x.RevisionId == command.RoleId);

            var grant = role.Grants.SingleOrDefault(x => x.User.RevisionId == command.UserId);

            if (grant != null)
            {
                return;
            }

            var user = _entities.Get <User>().Single(x => x.RevisionId == command.UserId);

            grant = new RoleGrant
            {
                Role = role,
                User = user,
            };

            // log audit
            var audit = new CommandEvent
            {
                RaisedBy = command.Principal.Identity.Name,
                Name     = command.GetType().FullName,
                Value    = JsonConvert.SerializeObject(new
                {
                    command.UserId,
                    command.RoleId,
                }),
                NewState = grant.ToJsonAudit(),
            };

            _entities.Create(audit);
            _entities.Create(grant);
            _unitOfWork.SaveChanges();
        }