Esempio n. 1
0
        public async Task <int> CreateDashboard(string userId, DashboardInput input, NpgsqlConnection connection)
        {
            string queryString = UserQueryBuilder.CreateDashboardQueryString(input.name, input.description);

            await using NpgsqlCommand cmd = new NpgsqlCommand(queryString);
            cmd.Connection = connection;
            int dashboardId = (int)cmd.ExecuteScalar();

            cmd.Parameters.Clear();

            string accessQueryString =
                UserQueryBuilder.InsertUserAccessToDashboardQueryString(userId, dashboardId, input.accessLevel);

            await executeQuery(connection, accessQueryString);

            return(dashboardId);
        }
Esempio n. 2
0
        public async Task <int> UpdateCell(string userId, CellInput input)
        {
            string      jsonOptions = JsonSerializer.Serialize(input.options);
            JsonElement options     = JsonSerializer.Deserialize <JsonElement>(jsonOptions);
            string      jsonInput   = JsonSerializer.Serialize(input.input);
            JsonElement inputQuery  = JsonSerializer.Deserialize <JsonElement>(jsonInput);

            if (input.cellId != null)
            {
                int    id          = input.cellId.GetValueOrDefault();
                string queryString =
                    UserQueryBuilder.UpdateCellQueryString(userId, id, input.dashboardId, options, inputQuery);
                return(await executeQueryString(queryString));
            }
            else
            {
                return(await CreateCell(input.dashboardId, options, inputQuery));
            }
        }
Esempio n. 3
0
        public async Task <int> UpdateDashboard(string userId, DashboardInput input)
        {
            NpgsqlConnection npgsqlConnection = new NpgsqlConnection(_databaseSettings.DatabaseConnectionString);
            await npgsqlConnection.OpenAsync();

            int id = -1;

            if (input.dashboardId != null)
            {
                id = input.dashboardId.GetValueOrDefault();
                string queryString = UserQueryBuilder.UpdateDashboardQueryString(userId, id, input.name, input.description);
                await executeQuery(npgsqlConnection, queryString);
            }
            else
            {
                id = await CreateDashboard(userId, input, npgsqlConnection);
            }

            await npgsqlConnection.CloseAsync();

            return(id);
        }
Esempio n. 4
0
        private async Task <int> CreateCell(int dashboardId, JsonElement options, JsonElement input)
        {
            string queryString = UserQueryBuilder.CreateCellQueryString(dashboardId, options, input);

            return(await executeQueryString(queryString));
        }