Exemplo n.º 1
0
        public Box(string name, User owner)
        {
            if (name.Empty())
            {
                throw new ArgumentException("Box name can not be empty.", nameof(name));
            }
            if (!name.IsValidName())
            {
                throw new ArgumentException($"Box name '{name}' is invalid.", nameof(name));
            }
            if (name.Length > 100)
            {
                throw new ArgumentException("Box name can not have more than 100 characters.", nameof(name));
            }

            Name  = name.Trim().ToLowerInvariant();
            Owner = owner.Username;

            var boxUser = new BoxUser(owner, BoxRole.BoxAdmin);

            boxUser.AddPermission(Permission.CreateEntry);
            boxUser.AddPermission(Permission.DeleteEntry);
            boxUser.AddPermission(Permission.ReadEntry);
            boxUser.AddPermission(Permission.ReadEntryKeys);

            if (owner.IsActive)
            {
                boxUser.Activate();
            }

            AddUser(boxUser);
            CreatedAt = DateTime.UtcNow;
            UpdatedAt = DateTime.UtcNow;
        }
Exemplo n.º 2
0
        public void AddUser(BoxUser user)
        {
            if (_users.Contains(user))
            {
                return;
            }

            _users.Add(user);
            UpdatedAt = DateTime.UtcNow;
        }