public void HasGetSet() { var value = new Establishment(); var entity = new RoleGrant { ForEstablishment = value }; entity.ShouldNotBeNull(); entity.ForEstablishment.ShouldEqual(value); }
public void HasGetSet() { var value = new User(); var entity = new RoleGrant { User = value }; entity.ShouldNotBeNull(); entity.User.ShouldEqual(value); }
public void HasGetSet() { var value = new Role(); var entity = new RoleGrant { Role = value }; entity.ShouldNotBeNull(); entity.Role.ShouldEqual(value); }
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; }
public void HasGetSet() { var value = new Establishment(); var entity = new RoleGrant { ForEstablishment = value }; entity.ShouldNotBeNull(); entity.ForEstablishment.ShouldEqual(value); }
public void HasGetSet() { var value = new Role(); var entity = new RoleGrant { Role = value }; entity.ShouldNotBeNull(); entity.Role.ShouldEqual(value); }
public void HasGetSet() { var value = new User(); var entity = new RoleGrant { User = value }; entity.ShouldNotBeNull(); entity.User.ShouldEqual(value); }
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); }
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(); }