Monday, June 22, 2015

Find Gridview Row From List and check it.

foreach (var item in listPeople)
{
 var row = gvAddPeople.Rows.Cast<GridViewRow>()
.Where(x => ((HiddenField)x.Cells[0].Controls[3]).Value == item.PeopleID.ToString()).Single();

 ((CheckBox)row.Cells[0].Controls[1]).Checked = true;
}

Monday, June 1, 2015

Advanced LINQ

Get same attribute between 2 List

var listPerson = AlllistPerson.Where(x => listPhone
 .Any(y => x.PersonPhone.Contains(y.PhoneNmbers).ToList();

Remove from another List (duplicate)

var result = personList.Where(c => !transactionList.Exists(b => c.phone == b.phone)).ToList();

Remove from another List (duplicate) & Child List


List<long> phoneNumbers = sessionTelco.SelectMany
                            (x => x.PhoneList.Select(y => y.phone)).ToList();

coveragePrices = coveragePrices.Where(x => ! phoneNumbers.Contains(x. phone)).ToList();

Selecting First Item from every group

var grouped = personList.GroupBy(x => x.CountryName).Select(y => y.First()).ToList();

 var grouped = from x in personList
            group x by x.CountryName
            into y
            select y.First();


select many from child list.


List<long> routeClassIDList = _upc.SessionClientGroupList.SelectMany
         (x => x.ClientGroupCoverageList.Select(y => y.RouteClassID)).ToList();


filter all child list same with list


clientGroups = clientGroups.Where(x => !x.ClientGroupCoverageList.All(y => routeClassIDList.Contains(y.RouteClassID))).ToList();


ForEach Add if else


people.ForEach(x => { if (x.Balance.HasValue == false || x.Balance.Value == 0) x.Balance = null; });


INNER JOIN 
devicePerAccList = (from f in devicePerAccList
                    join s in Accounts on f.AccountId equals s.E2AccountId
                    select new DevicePerAcc
                    {
                        AccountId = f.AccountId,
                        AccCode = s.AccountCode,
                        NoOfDevice = f.NoOfDevice

                    }).ToList();

Select Many, Find Description, Filter Description = null, Order By 1A , 2B , 11A

preBookMealList = ssrReportList.SelectMany(a => a.SSRCodes.Select(b => new PreBookMeal
{
SSRCode = b,
SSRDescription = ssrMealList.Where(c => c.SSRCode == b).Select(d => d.Name).FirstOrDefault()
})
.Where(e => e.SSRDescription != null))
.OrderBy(f => int.Parse(f.SeatNo.Remove(f.SeatNo.Length - 1)))
.ToList();


Dictionary put Key to object ID

result = peopleList.Select(x => { x.Value.peopleID = x.Key; return x.Value; }).ToList();