protected void butLogin_Click(object sender, ImageClickEventArgs e) { try { AdminHelper adminHelper = new AdminHelper(); double tempPrice; double? nullPrice = null; int tempID = 0; CompanyCityPrice companyCityPriceTemp; List <CompanyCityPrice> tempCCPL = new List <CompanyCityPrice>(); for (int i = 0; i < GridView1.Rows.Count; i++) { double.TryParse(((TextBox)GridView1.Rows[i].Cells[2].FindControl("txtPrice")).Text, out tempPrice); int.TryParse(((HiddenField)GridView1.Rows[i].Cells[2].FindControl("hfID")).Value, out tempID); companyCityPriceTemp = CitiesList.Where(xx => xx.CompanyCityPriceID == tempID).FirstOrDefault(); if (companyCityPriceTemp != null) { companyCityPriceTemp.Price = tempPrice > 0 ? tempPrice : nullPrice; tempCCPL.Add(companyCityPriceTemp); } } using (var dc = new LimoEntitiesEntityFremwork()) { List <int> tempIDsList = tempCCPL.Select(yy => yy.CompanyCityPriceID).ToList(); List <CompanyCityPrice> dbList = dc.CompanyCityPrices.Where(xx => tempIDsList.Contains(xx.CompanyCityPriceID)).ToList(); foreach (var companyCityPrice in dbList) { CompanyCityPrice tempTemp = tempCCPL.Where(xx => xx.CompanyCityPriceID == companyCityPrice.CompanyCityPriceID).Single(); companyCityPrice.Price = tempTemp.Price; } dc.SaveChanges(); CitiesList = dc.CompanyCityPrices.Where( xx => xx.IsActive.HasValue && xx.CompanyID == adminHelper.CompanyObject.CompanyID && xx.IsActive.Value) .ToList (); foreach (var companyCityPrice in CitiesList) { companyCityPrice.CityName = companyCityPrice.cities_extended.CityName; companyCityPrice.StateName = companyCityPrice.cities_extended.State.StateName; } } int pageIndex = GridView1.PageIndex; GridView1.DataSource = CitiesList; GridView1.DataBind(); GridView1.PageIndex = pageIndex; divConfirmation.Visible = true; } catch (Exception) { divError.Visible = true; } }
public static void ExampleTwo() { var query = CitiesList.Where(c => c.StartsWith("L")) .OrderByDescending(c => c.Length); var comprehensionQuery = from city in CitiesList where city.StartsWith("L") orderby city.Length descending select city; query.WriteForEach(); comprehensionQuery.WriteForEach(); }