public async Task <IEnumerable <Investment> > GetInvestmentsByAccount(Guid userId, Guid accountId, int page, int size) { var sql = new StringBuilder(); sql.Append($"SELECT Id, Value, Description, [Type], MovementId, AccountId, UserId, CreatedOn, UpdatedOn"); sql.Append($" FROM {table} WHERE AccountId = @accountId AND UserId = @userId"); sql.Append($" ORDER BY CreatedOn DESC"); sql.Append($" OFFSET @offset ROWS FETCH NEXT @next ROWS ONLY"); await using var connection = new SqlConnection(_configuration.GetConnectionString("DatabaseConnection")); connection.Open(); var dictionary = new Dictionary <string, object> { { "@userId", userId }, { "@accountId", accountId }, { "@offset", (page - 1) * size }, { "@next", size } }; var parameters = new DynamicParameters(dictionary); var investment = await connection.QueryAsync <FS.Data.Entities.Investment>(sql.ToString(), parameters); return(InvestmentEntityToInvestmentDomainMapper.MapFrom(investment)); }
public async Task <Investment> Get(Guid id) { var sql = new StringBuilder(); sql.Append($"SELECT Id, Value, Description, [Type], AccountId, UserId, MovementId, CreatedOn, UpdatedOn"); sql.Append($" FROM {table} WHERE Id = @id"); await using var connection = new SqlConnection(_configuration.GetConnectionString("DatabaseConnection")); connection.Open(); var dictionary = new Dictionary <string, object> { { "@id", id } }; var parameters = new DynamicParameters(dictionary); var investment = await connection.QueryFirstAsync <FS.Data.Entities.Investment>(sql.ToString(), parameters); return(InvestmentEntityToInvestmentDomainMapper.MapFrom(investment)); }