public async Task <Application> GetApplicationById(string appid) { if (ValidateQuery(await _applicationTable.SelectById(appid), out Application app)) // If the application exists { if (ValidateQuery(await _userTable.SelectById(app.UserId), out User author)) // If the application's author exists { app.Author = author; return(app); } else { throw new Exception("Author of provided application could not be found."); } } else { return(null); } }
public async Task <Connection> CreateConnection(Connection connection) { if ((await _userTable.SelectById(connection.User.Id)).Any()) // Check that provided user exists { if ((await _applicationTable.SelectById(connection.Application.Id)).Any()) // Check that provided application exists { connection.UserId = connection.User.Id; connection.AppId = connection.Application.Id; connection.AuthorizationCode = GenerateAuthCode(); if ((await _connectionTable.SelectByUserAndApplication(connection.User.Id, connection.Application.Id)).Any()) // If a connection between the provided user and application already exists { await _connectionTable.Update(connection); } else { await _connectionTable.Insert(connection); } if (ValidateQuery(await _connectionTable.SelectByUserAndApplication(connection.UserId, connection.AppId), out Connection output)) { return(output); } else { throw new Exception("Error occurred getting new connection."); } } else { throw new ArgumentException("Provided application ID could not be found."); } } else { throw new ArgumentException("Provided user ID could not be found."); } }