public void OrderLedgers() { if (VchType != "Contra" && VchType != "Purchase" && VchType != "Receipt" && VchType != "Credit Note") { Ledgers.Sort((x, y) => y.LedgerName.CompareTo(x.LedgerName)); //First Sort Ledger list Using Ledger Names Ledgers.Sort((x, y) => y.Amount.CompareTo(x.Amount)); //Next sort Ledger List Using Ledger Amounts } else { Ledgers.Sort((x, y) => x.LedgerName.CompareTo(y.LedgerName)); //First Sort Ledger list Using Ledger Names Ledgers.Sort((x, y) => x.Amount.CompareTo(y.Amount)); //Next sort Ledger List Using Ledger Amounts } //Looop Through all Ledgers Ledgers.ForEach(c => { //Sort Bill Allocations c.BillAllocations.Sort((x, y) => x.Name.CompareTo(y.Name)); //First Sort BillAllocations Using Bill Numbers c.BillAllocations.Sort((x, y) => x.Amount.CompareTo(y.Amount)); //Next sort BillAllocationst Using Amounts c.CostCategoryAllocations.Sort((x, y) => x.CostCategoryName.CompareTo(y.CostCategoryName)); c.CostCategoryAllocations.ForEach(cc => { cc.CostCenterAllocations.Sort((x, y) => x.Name.CompareTo(y.Name)); cc.CostCenterAllocations.Sort((x, y) => x.Amount.CompareTo(y.Amount)); }); //sort Inventory Allocations c.InventoryAllocations.Sort((x, y) => x.ActualQuantity.CompareTo(y.ActualQuantity)); c.InventoryAllocations.Sort((x, y) => x.Amount.CompareTo(y.Amount)); c.InventoryAllocations.ForEach(inv => { inv.BatchAllocations.Sort((x, y) => x.GodownName.CompareTo(y.GodownName)); inv.BatchAllocations.Sort((x, y) => x.Amount.CompareTo(y.Amount)); inv.CostCategoryAllocations.Sort((x, y) => x.CostCategoryName.CompareTo(y.CostCategoryName)); inv.CostCategoryAllocations.ForEach(cc => { cc.CostCenterAllocations.Sort((x, y) => x.Name.CompareTo(y.Name)); cc.CostCenterAllocations.Sort((x, y) => x.Amount.CompareTo(y.Amount)); }); }); }); }