public CountryPricelistB GetCountryPricelist(int CustomerID, int LineTypeID) { using (var dbContext = new OTERTConnStr()) { try { dbContext.Configuration.ProxyCreationEnabled = false; CountryPricelistB data = (from us in dbContext.CountryPricelist select new CountryPricelistB { ID = us.ID, CustomerID = us.CustomerID, Customer = new CustomerDTO { ID = us.Customers.ID, CountryID = us.Customers.CountryID, NameGR = us.Customers.NameGR, NameEN = us.Customers.NameEN, NamedInvoiceGR = us.Customers.NamedInvoiceGR, NamedInvoiceEN = us.Customers.NamedInvoiceEN, ZIPCode = us.Customers.ZIPCode, CityGR = us.Customers.CityGR, CityEN = us.Customers.CityEN, ChargeTelephone = us.Customers.ChargeTelephone, Telephone1 = us.Customers.Telephone1, Telephone2 = us.Customers.Telephone2, FAX1 = us.Customers.FAX1, FAX2 = us.Customers.FAX2, Address1GR = us.Customers.Address1GR, Address1EN = us.Customers.Address1EN, Address2GR = us.Customers.Address2GR, Address2EN = us.Customers.Address2EN, ContactPersonGR = us.Customers.ContactPersonGR, ContactPersonEN = us.Customers.ContactPersonEN, CustomerTypeID = us.Customers.CustomerTypeID, LanguageID = us.Customers.LanguageID, Email = us.Customers.Email, URL = us.Customers.URL, AFM = us.Customers.AFM, DOY = us.Customers.DOY, SAPCode = us.Customers.SAPCode, UserID = us.Customers.UserID, Comments = us.Customers.Comments, IsProvider = us.Customers.IsProvider, IsOTE = us.Customers.IsOTE }, LineTypeID = us.LineTypeID, LineType = new LineTypeDTO { ID = us.LineTypes.ID, Name = us.LineTypes.Name }, InstallationCost = us.InstallationCost, MonthlyCharges = us.MonthlyCharges, Internet = us.Internet, MSN = us.MSN, PaymentIsForWholeMonth = us.PaymentIsForWholeMonth }).Where(o => o.CustomerID == CustomerID && o.LineTypeID == LineTypeID).FirstOrDefault(); return(data); } catch (Exception) { return(null); } } }
protected void gridMain_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridEditableItem && e.Item.IsInEditMode) { CustomerID = -1; Session.Remove("CustomerID"); LineTypeID = -1; Session.Remove("LineTypeID"); GridEditableItem item = e.Item as GridEditableItem; RadDropDownList ddlCustomer = item.FindControl("ddlCustomer") as RadDropDownList; RadDropDownList ddlLineType = item.FindControl("ddlLineType") as RadDropDownList; try { CountryPricelistB currPricelist = e.Item.DataItem as CountryPricelistB; CustomersController cont = new CustomersController(); ddlCustomer.DataSource = cont.GetProviders(); ddlCustomer.DataTextField = "NameGR"; ddlCustomer.DataValueField = "ID"; ddlCustomer.DataBind(); LineTypesController cont2 = new LineTypesController(); ddlLineType.DataSource = cont2.GetLineTypes(); ddlLineType.DataTextField = "Name"; ddlLineType.DataValueField = "ID"; ddlLineType.DataBind(); if (currPricelist != null) { ddlCustomer.SelectedIndex = ddlCustomer.FindItemByValue(currPricelist.CustomerID.ToString()).Index; Session["CustomerID"] = currPricelist.CustomerID; ddlLineType.SelectedIndex = ddlLineType.FindItemByValue(currPricelist.LineTypeID.ToString()).Index; Session["LineTypeID"] = currPricelist.LineTypeID; } else { ddlCustomer.SelectedIndex = 0; Session["CustomerID"] = ddlCustomer.SelectedItem.Value; ddlLineType.SelectedIndex = 0; Session["LineTypeID"] = ddlLineType.SelectedItem.Value; } } catch (Exception) { } } }