public bool Save() { using (OAuthDataContext context = OAuthContextHelper.GetContext()) { AuthorizationData data; if (AuthorizationId > 0) { data = context.AuthorizationDatas.FirstOrDefault(a => a.authorization_id == AuthorizationId); } else { data = new AuthorizationData(); data.date_created = DateTime.Now; } data.client_id = ClientId; data.login_id = LoginId; data.scope_id = ScopeId; data.active = Active; if (AuthorizationId == 0) { context.AuthorizationDatas.InsertOnSubmit(data); } context.SubmitChanges(); Load(data); return(AuthorizationId > 0); } }
public bool Save(string userId) { try { using (OAuthDataContext context = OAuthContextHelper.GetContext()) { ScopeData data; if (ScopeId > 0) { data = context.ScopeDatas.FirstOrDefault(s => s.scope_id == ScopeId); if (data == null) { throw new ArgumentException("Scope Id is not valid.", "ScopeId"); } } else { if (ScopeIdentifierInUse()) { throw new ArgumentException("Scope Identifier is already in use.", "ScopeIdentifier"); } data = new ScopeData(); data.created_by = userId; data.date_created = DateTime.Now; } data.scope_identifier = Identifier; data.scope_description = Description; data.modified_by = userId; data.date_modified = DateTime.Now; data.active = Active; if (ScopeId <= 0) { context.ScopeDatas.InsertOnSubmit(data); } context.SubmitChanges(); if (data.scope_id > 0) { Load(data); return(true); } return(false); } } catch (Exception ex) { throw new Exception("An error occurred while saving Scope", ex); } }
public bool Save(string userId) { try { using (OAuthDataContext context = OAuthContextHelper.GetContext()) { ClientData data; if (ClientId > 0) { data = context.ClientDatas.FirstOrDefault(c => c.client_id == ClientId); if (data == null) { throw new ArgumentOutOfRangeException("Client Not Found for ClientID"); } } else { data = new ClientData(); if (ApiKey == Guid.Empty) { GenerateApiKey(); } if (ApiSecret == Guid.Empty) { GenerateApiSecret(); } } data.client_name = Name; data.callback_url = Callback; data.api_key = ApiKey; data.api_secret = ApiSecret; data.modified_by = userId; data.date_modified = DateTime.Now; data.active = Active; if (data.client_id <= 0) { data.created_by = userId; data.date_created = DateTime.Now; if (Scopes != null) { foreach (var scope in Scopes) { data.ClientScopeDatas.Add(new ClientScopeData { scope_id = scope.ScopeId, created_by = userId, date_created = DateTime.Now, modified_by = userId, date_modified = DateTime.Now, active = true }); } } context.ClientDatas.InsertOnSubmit(data); } else { var scopeIDRemove = data.ClientScopeDatas.Select(cs => cs.scope_id).Where(cs => !Scopes.Select(s => s.ScopeId).Contains(cs)).ToArray(); foreach (var scopeId in scopeIDRemove) { var scopeToRemove = data.ClientScopeDatas.Where(cs => cs.scope_id == scopeId).FirstOrDefault(); if (scopeToRemove != null) { context.ClientScopeDatas.DeleteOnSubmit(scopeToRemove); } } var scopeIdAdd = Scopes.Select(s => s.ScopeId).Where(s => !data.ClientScopeDatas.Select(cs => cs.scope_id).Contains(s)); foreach (var scopeId in scopeIdAdd) { data.ClientScopeDatas.Add( new ClientScopeData { scope_id = scopeId, created_by = userId, modified_by = userId, date_created = DateTime.Now, date_modified = DateTime.Now, active = true } ); } } context.SubmitChanges(); if (data.client_id > 0) { Load(data); return(true); } return(false); } } catch (Exception ex) { throw new Exception("An error occurred when saving client.", ex); } }