Пример #1
0
        public void ModifyUri(Guid clientUriId, ClientUriType type, string uri)
        {
            ClientUri.ValidateUri(uri);

            var toModify = _uris.FirstOrDefault(u => u.Id == clientUriId);

            if (null == toModify)
            {
                throw new EntityValidationException("This URI doesn't exist on this client.");
            }

            if (Active && toModify.Type == ClientUriType.Redirect && type != ClientUriType.Redirect &&
                !_uris.Any(u => u.Type == ClientUriType.Redirect && u.Id != clientUriId))
            {
                throw new EntityValidationException("Cannot change the type of this URI, an active client " +
                                                    "must have at least one Redirect URI.");
            }

            var e = new ModifiedClientUriEvent()
            {
                Uri         = uri,
                UriType     = type,
                ClientId    = Id,
                OccurredOn  = DateTime.UtcNow,
                ClientUriId = clientUriId
            };

            _changes.Add(e);
            EventHandler.UriModified(this, e);
        }
Пример #2
0
        public ClientUri AddUri(ClientUriType type, string uri)
        {
            ClientUri.ValidateUri(uri);

            if (_uris.Any(u => u.Type == type &&
                          string.Equals(u.Uri, uri, StringComparison.OrdinalIgnoreCase)))
            {
                throw new EntityValidationException("A URI with this URL and type already exists on the client!");
            }

            var e = new AddedClientUriEvent()
            {
                ClientUriId = Guid.NewGuid(),
                UriType     = type,
                Uri         = uri,
                ClientId    = Id,
                OccurredOn  = DateTime.UtcNow
            };

            _changes.Add(e);
            EventHandler.UriAdded(this, e);

            return(_uris.FirstOrDefault(u => u.Id == e.ClientUriId));
        }