private void UpdateUrls(Data.Client entity, ClientUriType uriType, IEnumerable <ClientUri> urls) { foreach (var url in urls) { url.Value = url.Value.Trim(); if (url.Id > 0) { var target = entity.Urls.SingleOrDefault(u => u.Id == url.Id); if (target != null) { if (string.IsNullOrEmpty(url.Value) || url.Deleted) { entity.Urls.Remove(target); } else { target.Value = url.Value; } } } else { entity.Urls.Add(new Data.ClientUri { Type = uriType, Value = url.Value, }); } } }
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); }
private void UpdateUrl(Data.Client entity, ClientUriType uriType, string value) { var target = entity.Urls.FirstOrDefault(u => u.Type == uriType); if (target != null) { if (string.IsNullOrEmpty(value)) { entity.Urls.Remove(target); } else { target.Value = value; } } else { entity.Urls.Add(new Data.ClientUri { Type = uriType, Value = value }); } }
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)); }