rogue1 rogue1 - 2 months ago 7
C# Question

Combine two lists into one

I have two lists at present with a field different in each list one is called payment and the other is called contribution

public List<tblPortalContributionSchedule> getUserContributions(Guid _customerInfoId)
{
List<tblPortalContributionSchedule> _contributions = portalEntities.tblPortalContributionSchedules.Where(a => a.customerInfo == _customerInfoId && a.isDeleted == false).ToList();

return _contributions;
}


This is the second list it has a field called date which i want to restrict the first list to less than or equals to but I want to combine both these queries into one list as I am using a repeater to display the info I provide my html as well below in the hope someone can help me combine these two statements into one.

public List<tblPortalPayment> getUserPayments(Guid recordId)
{

List<tblPortalPayment> _payments = portalEntities.tblPortalPayments.Where(a => a.CustomerId == recordId && a.isDeleted == false).ToList();

return _payments;

}


Html Code for repeater

<asp:Repeater ID="rptPayments" runat="server" OnItemDataBound="rptPayments_ItemDataBound">
<ItemTemplate>



<div class="panel panel-default">
<div class="panel-heading pointer" data-toggle="collapse" data-parent="#accordion" href="#collapse<%#Container.ItemIndex %>">

<div class="alert-box notice">
<h4 class="panel-title">
<asp:HiddenField ID="isinArrears" runat="server" Value='<%#Eval("isinArrears") %>' />
<a><%# Convert.ToDateTime(Eval("paymentDate")).ToString("MMMM d yyyy") %> </a>
<asp:Label ID="lblStatus" runat="server" CssClass="fa fa-info-circle"></asp:Label>
</h4>
</div>

</div>
<div id="collapse<%#Container.ItemIndex %>" class="<%# GetItemClass(Container.ItemIndex) %>" style="height: auto;">
<div class="panel-body center">

<table id="paymentsummaryhistory">
<tbody>
<tr>
<td><strong>Payment Agreed: </strong></td>
<td><strong>Payment Date: </strong></td>

</tr>
<tr>
<td>
<dx:ASPxLabel ID="lblPaymentDUE" runat="server" Text='<%# "£" + Eval("paymentDue") %>'></dx:ASPxLabel>
<br />
</td>
<td>
<dx:ASPxLabel ID="lblPayemntDate" runat="server" Text='<%# Convert.ToDateTime(Eval("paymentDate")).ToString("dd/MM/yyyy") %>'></dx:ASPxLabel>
</td>


</tr>
</tbody>
</table>

<dx:ASPxLabel ID="lblArrearsInfo" ClientVisible="False" runat="server" Text='<%# Eval("isinArrears") %>'></dx:ASPxLabel>

</div>
</div>
</div>
</ItemTemplate>
</asp:Repeater>


Edit 1

I have modified my query slighty as I only want the top 5 contributions as the 6 payments is in the header record so it is can any one help me out there are two different fields first linq I want paymentDue and second linq I want contribution but I want these combined into one list so can bind to a repeater

public List<tblPortalContributionSchedule> getUserContributions(Guid _customerInfoId,DateTime _date)
{
List<tblPortalContributionSchedule> _contributions = portalEntities.tblPortalContributionSchedules.Where(a => a.customerInfo == _customerInfoId && a.isDeleted == false && a.DUE_DATE <= _date && a.DUE_DATE !=_date ).Take(5).ToList();

return _contributions;
}


Edit 2

Properties Contribution Schedule
I require Due Date and Contribution from this one
https://snag.gy/PhJgsA.jpg

Properties Payments
I require paymentdue and paymentdate out of this one

https://snag.gy/3wWEjb.jpg

The only values i need out of both are Due Date

Answer

Hope you like this :)

Note : please adjust model properties correctly according to your models .

var finalResult = _payments.Select(p=>new Payments{ DueDate = p. 
paymentdue}).Concat(_contributions.Select(c=>new Payments{ DueDate = c.dueDate });
Comments