public async Task <Trade> GetByIdSystemLanguageAsync(int id, int idSystems, int idLanguage) { using (IDbConnection dbConnection = GetConnection()) { var parameters = new DynamicParameters(); parameters.Add("@Id", id, DbType.Int64, ParameterDirection.Input); parameters.Add("@IdSystems", idSystems, DbType.Int64, ParameterDirection.Input); parameters.Add("@IdLanguages", idLanguage, DbType.Int64, ParameterDirection.Input); dbConnection.Open(); var query = await dbConnection.QueryAsync <Trade, User, User, Given, Desired, DonationName, Trade>( "USP_SEL_TradesByIdSystemLanguage", map : (trade, userGet, userLet, given, desired, donationName) => { trade.UserGet = userGet; trade.UserLet = userLet; var donation = new Donation() { Id = donationName.IdDonations, IdDonations = donationName.IdDonations, IdSystems = idSystems }; donation.AddName(donationName); given.Donation = donation; desired.Donation = donation; trade.Given = given; trade.Desired = desired; return(trade); }, param : parameters, commandType : CommandType.StoredProcedure ); return(await query.ToAsyncEnumerable().Distinct().FirstOrDefault()); } }
private async Task <IEnumerable <Trade> > ListByIdUserSystemLanguageAsync(int idUser, int idSystems, int idLanguages, string paramIdName, string uspName) { using (IDbConnection dbConnection = GetConnection()) { var parameters = new DynamicParameters(); parameters.Add(paramIdName, idUser, DbType.Int64, ParameterDirection.Input); parameters.Add("@IdSystems", idSystems, DbType.Int64, ParameterDirection.Input); parameters.Add("@IdLanguages", idLanguages, DbType.Int64, ParameterDirection.Input); dbConnection.Open(); return(await dbConnection.QueryAsync <Trade, User, User, Given, Desired, DonationName, Trade>( uspName, map : (trade, userGet, userLet, given, desired, donationName) => { trade.UserGet = userGet; trade.UserLet = userLet; var donation = new Donation() { Id = donationName.IdDonations, IdDonations = donationName.IdDonations, IdSystems = idSystems }; donation.AddName(donationName); given.Donation = donation; desired.Donation = donation; trade.Given = given; trade.Desired = desired; return trade; }, param : parameters, commandType : CommandType.StoredProcedure )); } }