public JsonNetResult ItemByBrandID(ref SearchHistory sHis, int id = -1, string properties = "", int vn0_en1 = 0)
        {
            string path = ConfigurationManager.AppSettings["BrandLogoLocation"].Replace("~", "");
            string c_path = ConfigurationManager.AppSettings["CategoryMarkerIconLocaion"].Replace("~", "");
            string b_path = ConfigurationManager.AppSettings["BrandMarkerIconLocation"].Replace("~", "");
            string i_path = ConfigurationManager.AppSettings["ItemMarkerIconLocation"].Replace("~", "");

            string[] list = properties.Split(',');
            List<int> items = new List<int>();
            foreach (var x in list)
                if (x != "")
                {
                    try
                    {
                        items.Add(Convert.ToInt32(x));
                    }
                    catch { }

                }

            var itemlist = (from i in db.ItemProperties
                            where items.Contains(i.PropertyID)// >= 0
                            select new { i.ItemID }).Distinct();

            var brandlist = (from i in db.tbl_Brand_Properties
                             join b in db.BrandItems on i.BrandID equals b.BrandID
                             where items.Contains(i.PropertyID)// >= 0
                             select new { b.ItemID }).Distinct();

            var brands = from i in db.BrandItems
                         join br in db.Brands on i.BrandID equals br.BrandID
                         join c in db.Categories on br.CategoryID equals c.CategoryID
                         where i.BrandID == id
                         select new
                         {
                             i.ItemID,
                             ItemName=i.ItemName.ToUpper(),
                             i.FullAddress,
                             i.Phone,
                             i.Website,
                             i.OpenTime,
                             i.Description_EN,
                             i.Description,
                             ItemName_EN = i.ItemName_EN.ToUpper(),
                             i.Longitude,
                             i.Latitude,
                             Logo = path + "/" + br.Logo,
                             MarkerIcon = i.MarkerIcon == null ? br.MarkerIcon == null ? c_path + "/" + c.MarkerIcon : b_path + "/" + br.MarkerIcon : i_path + "/" + i.MarkerIcon
                         };

            if (itemlist.Count() > 0)
                brands = from i in brands
                         join ip in itemlist on i.ItemID equals ip.ItemID
                         select i;

            else if (brandlist.Count() > 0)
                brands = from i in brands
                         join ip in brandlist on i.ItemID equals ip.ItemID
                         select i;

            JsonNetResult jsonNetResult = new JsonNetResult();
            jsonNetResult.Formatting = Formatting.Indented;
            jsonNetResult.Data = from a in brands
                                 select new { a.ItemID, a.ItemName, a.Description, a.Longitude, a.Latitude, a.FullAddress, a.Website, a.Logo, a.MarkerIcon, a.Phone };
            if (vn0_en1 == 1)
                jsonNetResult.Data = from a in brands
                                     select new { a.ItemID, ItemName = a.ItemName_EN, Description = a.Description_EN, a.Longitude, a.Latitude, a.FullAddress, a.Website, a.Logo, a.MarkerIcon, a.Phone };
            sHis.ResultCount = brands.Count();
            return jsonNetResult;
        }
        public ActionResult Search(int mode = 0, string keyword = "", string currentLocation = "", int categoryid = -1, int brandid = -1, int radious = 1, string properties = "", int vn0_en1 = 0)
        {
            ViewBag.Mode = mode;
            ViewBag.Keyword = keyword;
            ViewBag.CurrentLocaion = currentLocation;
            ViewBag.CategoryID = categoryid;
            ViewBag.BrandID = brandid;
            ViewBag.Radious = radious;
            ViewBag.CurrentLanguage = vn0_en1;

            SearchHistory sHis = new SearchHistory();
            sHis.CategoryID = categoryid;
            sHis.BrandID = brandid;
            sHis.Mode = mode;
            sHis.Keyword = keyword;
            sHis.CurrentLocation = currentLocation;
            sHis.VN0_En1 = vn0_en1;
            sHis.Radious = radious;
            sHis.Properties = properties;
            sHis.SearchDate = DateTime.Now.Date;
            sHis.SearchTime = DateTime.Now;

            JsonNetResult jsonNetResult = new JsonNetResult();
            if (mode == 0)//search basic
            {
                jsonNetResult= ItemByKeyword(ref sHis, keyword, properties, vn0_en1 );
            }
            else // advance search
            {
                if (brandid != -1)
                {
                    jsonNetResult = ItemByBrandID(ref sHis, brandid, properties, vn0_en1);
                }
                else
                {
                    jsonNetResult = ItemByCategoryID(ref sHis, categoryid, properties, vn0_en1);
                }
            }
            db.SearchHistory.Add(sHis);
            db.SaveChanges();
            return jsonNetResult;
        }