public List <KeyValuePair <int, string> > GetCategoriesList() { List <KeyValuePair <int, string> > LstKeyValues = new List <KeyValuePair <int, string> >(); List <Category> lstcust = client.GetAllCategories().ToList(); foreach (Category q in lstcust) { KeyValuePair <int, string> kvp = new KeyValuePair <int, string>(q.CategoryID_N, q.CategoryName_V); LstKeyValues.Add(kvp); } return(LstKeyValues); }
private void UpdateCategoryID() { try { using (var model = new Ad_ConnectionString()) { clsCommonMethods _modelCat = new clsCommonMethods(); var catList = _modelCat.GetAllCategories(); var catIDs = (from ct in catList select ct.CategoryName_V).ToList(); foreach (Category cat in catList) { if (cat.SubCategory.Count > 0) { var orginalCat = model.Adv_Product_Commons.Where(nc => nc.CategoryID_N == null && nc.ProductCategoryName != null && nc.Ad_For > 0).Where(p => p.ProductCategoryName.Equals(cat.CategoryName_V)).ToList(); // p.cat.CategoryName.Contains(cat.CategoryName_V)).ToList(); orginalCat.ForEach(aa => aa.CategoryID_N = cat.CategoryID_N); //a=>a..c.CategoryID_N=cat.CategoryID_N); model.SaveChanges(); var orginal = model.Adv_Product_Commons.Where(nc => nc.CategoryID_N == null && nc.ProductCategoryName != null && nc.Ad_For > 0).Where(p => cat.SubCategory.Select(s => s.SubCategoryName_V).ToList().Equals(p.ProductCategoryName)).ToList(); // p.cat.CategoryName.Contains(cat.CategoryName_V)).ToList(); orginal.ForEach(aa => aa.CategoryID_N = cat.CategoryID_N); //a=>a..c.CategoryID_N=cat.CategoryID_N); model.SaveChanges(); } else { var orginal = model.Adv_Product_Commons.Where(nc => nc.CategoryID_N == null && nc.ProductCategoryName != null && nc.Ad_For > 0).Where(p => p.ProductCategoryName.Equals(cat.CategoryName_V)).ToList(); // p.cat.CategoryName.Contains(cat.CategoryName_V)).ToList(); orginal.ForEach(aa => aa.CategoryID_N = cat.CategoryID_N); //a=>a..c.CategoryID_N=cat.CategoryID_N); model.SaveChanges(); if (cat.CategoryName_V == "Mobile Phones") { var cateNewMap = model.Adv_Product_Commons.Where(nc => nc.CategoryID_N == null && nc.ProductCategoryName != null && nc.Ad_For > 0).Where(p => p.ProductCategoryName.Equals("Mobiles & Accessories>Mobiles")).ToList(); // p.cat.CategoryName.Contains(cat.CategoryName_V)).ToList(); cateNewMap.ForEach(aa => aa.CategoryID_N = cat.CategoryID_N); //a=>a..c.CategoryID_N=cat.CategoryID_N); model.SaveChanges(); } } } model.Dispose(); } } catch (Exception ex) { } }