/// <summary> /// Deletes a collection of T's from the database and sets the baskets AscentPayload to the number of records affected /// </summary> /// <param name="basket">A basket</param> /// <param name="visit">The visit the basket is currently making</param> /// <returns>A Task that may be awaited</returns> public async Task AddResultAsync(IDeleteCollectionBasket <T, int> basket, IVisit visit) { if (basket == null) { throw new ArgumentNullException(nameof(basket)); } var statement = GetDeleteDbStatement(basket.DescentPayload); visit.Log(statement.ToString()); basket.AscentPayload = await DbInterface.ExecuteNonQueryAsync(statement).ConfigureAwait(false); }
/// <summary> /// Inserts the requested T into the database and sets the baskets AscentPayload to new records identity /// </summary> /// <param name="basket">A basket</param> /// <param name="visit">The visit the basket is currently making</param> /// <returns>A Task that may be awaited</returns> public async Task AddResultAsync(IPostBasket <T, TId> basket, IVisit visit) { if (basket == null) { throw new ArgumentNullException(nameof(basket)); } var statement = GetInsertDbStatement(basket.DescentPayload); visit.Log(statement.ToString()); var id = await DbInterface.ExecuteScalarAsync(statement).ConfigureAwait(false); basket.AscentPayload = Descriptor.ProjectColumnValue <TId>(id); }
/// <summary> /// Retreives the requested T from the database and adds it to the baskets AscendPayload /// </summary> /// <param name="basket">A basket</param> /// <param name="visit">The visit the basket is currently making</param> /// <returns>A Task that may be awaited</returns> public async Task AddResultAsync(IGetBasket <TId, T> basket, IVisit visit) { if (basket == null) { throw new ArgumentNullException(nameof(basket)); } var statement = GetSelectDbStatement(basket.DescentPayload); visit.Log(statement.ToString()); using (var rdr = await DbInterface.GetReaderAsync(statement).ConfigureAwait(false)) { if (!await rdr.ReadAsync().ConfigureAwait(false)) { throw new InvalidOperationException($"No '{typeof(T)}' record found"); } basket.AscentPayload = Mapper.MapObject(rdr); } }
/// <summary> /// Retrieves the requested collection of T's from the database and adds them to the baskets AscendPayload /// </summary> /// <param name="basket">A basket</param> /// <param name="visit">The visit the basket is currently making</param> /// <returns>A Task that may be awaited</returns> public async Task AddResultAsync(IGetCollectionBasket <T> basket, IVisit visit) { if (basket == null) { throw new ArgumentNullException(nameof(basket)); } var statement = GetSelectDbStatement(basket.DescentPayload); visit.Log(statement.ToString()); using (var rdr = await DbInterface.GetReaderAsync(statement).ConfigureAwait(false)) { var objs = new List <T>(); while (await rdr.ReadAsync().ConfigureAwait(false)) { var obj = Mapper.MapObject(rdr); objs.Add(obj); } basket.AscentPayload = objs.ToArray(); } }