tobbbe
2/3/2017 - 1:40 PM

Javascript lookup from web api

public List<CustomerMonthSales> CustomersMonthSalesCurrentPeriod { get; internal set; }
public List<CustomerMonthSales> CustomersMonthSalesPreviousPeriod { get; internal set; }

private SortedList<string, List<CustomerMonthSales>> _salesPerCustomerPerMonth = null;
public SortedList<string, List<CustomerMonthSales>> SalesPerCustomerPerMonth
{
    get
    {
        if (_salesPerCustomerPerMonth == null)
        {
            _salesPerCustomerPerMonth = CustomersMonthSalesCurrentPeriod.Concat(CustomersMonthSalesPreviousPeriod)
                .GroupBy(s => s.CustomerName)
                .ToSortedList(
                    g => g.Key,
                    g => g.OrderBy(e => e.Year).ThenBy(e => e.Month).ToList()
                );
        }

        return _salesPerCustomerPerMonth;
    }
}