private void AddSearchKey(string searchKey) { using (var ctx = new RachnaDBContext()) { CustomerSearchKey _customerSearchKey = new CustomerSearchKey() { IpAddress = IpAddress.GetLocalIPAddress(), SearchKey = searchKey, DateCreated = DateTime.Now }; ctx.CustomerSearchKey.Add(_customerSearchKey); ctx.SaveChanges(); }; }
public ActionResult GetProductsSearchKey(string s, int loadItems) { List <Product> _product = null; List <HomePageProductModel> _prdModel = new List <HomePageProductModel>(); using (var ctx = new RachnaDBContext()) { CustomerSearchKey _seracKeys = ctx.CustomerSearchKey.Where(m => m.SearchKey == s).FirstOrDefault(); if (_seracKeys == null) { AddSearchKey(s); } _product = ctx.Product .Where(p => (p.Product_Title.Contains(s) || p.Product_Description.Contains(s)) && p.Product_Status == eProductStatus.Published.ToString()) .Take(loadItems).ToList(); //_product = ctx.Product.Where(m => (m.Product_Title == s || m.Product_Description== s) && m.Product_Status.ToLower() == "published").Take(loadItems).ToList(); foreach (var item in _product) { item.ProductBanner = ctx.ProductBanner.Where(m => m.Product_Id == item.Product_Id).ToList(); } } foreach (var item in _product.Take(8).ToList()) { if (item.ProductBanner.Count > 0) { _prdModel.Add(new HomePageProductModel { Id = item.Product_Id, Title = item.Product_Title, Description = (item.Product_Description.Length > 500) ? item.Product_Description.Substring(0, 500) + "..." : item.Product_Description, Banner1 = item.ProductBanner.Where(x => x.Product_Banner_Default == 1).FirstOrDefault().Product_Banner_Photo.ToString(), Banner2 = (item.ProductBanner.Count > 1) ? item.ProductBanner.Where(x => x.Product_Banner_Default != 1).FirstOrDefault().Product_Banner_Photo.ToString() : item.ProductBanner.Where(x => x.Product_Banner_Default == 1).FirstOrDefault().Product_Banner_Photo.ToString(), OldPrice = item.Product_Mkt_Price, TotalPrice = item.Product_Our_Price, DiscountPrice = item.Product_Discount, Rating = item.Store_Rating }); } } return(Json(_prdModel, JsonRequestBehavior.AllowGet)); }