Ejemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SearchOptions filter = new SearchOptions()
            {
                CategoryId = (this.Request["categoryId"] != null) ? Convert.ToInt32(this.Request["categoryId"]) : -1,
                Text = String.IsNullOrEmpty(this.Request["searchText"]) ? "" : this.Request["searchText"],
                OnlyInCategory = ((SiteMaster)this.Master).chkOnlyInCategory.Visible && ((SiteMaster)this.Master).chkOnlyInCategory.Checked
            };

            LoadCommerces(filter);
        }
Ejemplo n.º 2
0
        private void LoadCommerces(SearchOptions options)
        {
            Category category = new Category();

            if (options.CategoryId != -1)
            {
                category = (from cat in CommercesDataContext.Categories
                                 where cat.id == options.CategoryId
                                 select cat).ToList()[0];

                ((SiteMaster)this.Master).chkOnlyInCategory.Visible = true;
                ((SiteMaster)this.Master).chkOnlyInCategory.Text = "Sólo en " + category.name;
            }

            List<Commerces> commerces = (from com in CommercesDataContext.Commerces
                                         select com).ToList();

            if (!String.IsNullOrEmpty(options.Text))
            {
                ((SiteMaster)this.Master).lblTitle.Text = "Resultados de la búsqueda de " + options.Text;

                commerces = (from com in commerces
                             where com.name.Contains(options.Text)
                             select com).ToList();

                if ((options.OnlyInCategory) && (options.CategoryId != -1))
                {
                    ((SiteMaster)this.Master).lblTitle.Text += " en la categoría " + category.name;

                    commerces = (from com in commerces
                                 where com.parent_id == options.CategoryId
                                 select com).ToList();
                }
            }
            else
            {
                ((SiteMaster)this.Master).lblTitle.Text = category.name;

                commerces = (from com in commerces
                             where com.parent_id == options.CategoryId
                             select com).ToList();
            }

            this.gvCommerces.DataSource = commerces;
            this.gvCommerces.DataBind();
        }