Exemplo n.º 1
0
        /// <summary>
        /// Adds an airline item
        /// </summary>
        /// <param name="source">New item to be added.</param>
        /// <returns>The id of the newly created item.</returns>
        public async Task <Bm> AddAsync(Bm source)
        {
            const string sqlQuery = "INSERT INTO airlines (name, iata) VALUES (@Name, @Iata) RETURNING id AS Id";

            using var conn = _conn.GetConnection();
            source.Id      = await conn.QuerySingleAsync <int>(sqlQuery, source);

            return(source);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates content of an existed airline
        /// </summary>
        /// <param name="id">The id of an item to be updated.</param>
        /// <param name="source">The information to update content of an existed airline.</param>
        /// <returns>"0" if item was not updated, otherwise >"0".</returns>
        public async Task <Bm> UpdateAsync(int id, Bm source)
        {
            source.Id = id;

            const string sqlQuery = "UPDATE airlines SET name=@Name, iata=@Iata WHERE id=@Id RETURNING id AS Id, iata AS Iata, name AS Name;";

            using var conn = _conn.GetConnection();
            return(await conn.QuerySingleOrDefaultAsync <Bm>(sqlQuery, source));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Partial update of a record
        /// </summary>
        /// <param name="id">Id of a record.</param>
        /// <param name="property">Column name in a class.</param>
        /// <param name="model">New value.</param>
        /// <returns>Updated item.</returns>
        public async Task <Bm> PatchRecordAsync(int id, string property, Bm model)
        {
            var tablePropertyName = AllowedColumns.GetValueOrDefault(property);

            model.Id = id;

            string sqlQuery = $"UPDATE airlines SET {tablePropertyName}=@{property} WHERE id=@id RETURNING id AS Id, iata AS Iata, name AS Name;";

            using var conn = _conn.GetConnection();
            return(await conn.QuerySingleOrDefaultAsync <Bm>(sqlQuery, model));
        }