public ViewResult Search(string name, Categories? categoty)
        {
            var lista = _business.GetActiveProducts();

            var model = new ProductList();

            if(lista != null)
            {
                if (!String.IsNullOrEmpty(name) && categoty != null)
                    model.Products =
                        lista.Where(
                            x =>
                            ((!String.IsNullOrEmpty(name) && x.Name.ToLower().Contains(name.ToLower())) && (x.Category.Equals(categoty)))).
                            Select(x => new Models.Product.Product().InjectFrom(x)).Cast<Models.Product.Product>().ToList();
                else if (!String.IsNullOrEmpty(name))
                    model.Products =
                        lista.Where(x => !String.IsNullOrEmpty(name) && x.Name.ToLower().Contains(name.ToLower())).Select(
                            x => new Models.Product.Product().InjectFrom(x)).Cast<Models.Product.Product>().ToList();
                else if (categoty != null)
                    model.Products =
                        lista.Where(x => x.Category.Equals(categoty)).Select(x => new Models.Product.Product().InjectFrom(x)).Cast
                            <Models.Product.Product>().ToList();
                else
                    model.Products = lista.Select(x => new Models.Product.Product().InjectFrom(x)).Cast<Models.Product.Product>().ToList();
            }
            else
            {
                model.Products = new List<Models.Product.Product>();
            }

            return View("Index",model);
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            try
            {
                var products = _business.GetActiveProducts();

                var model = new ProductList
                {
                    Products =
                        products != null
                            ? products.Select(x => new Models.Product.Product().InjectFrom(x)).Cast<Models.Product.Product>().ToList()
                            : new List<Models.Product.Product>()
                };

                return View("Index", model);
            }
            catch (Exception)
            {
                ViewData["Erro"] = "Ocorreu um erro durante o processamento. Tente novamente mais tarde.";

                var model = new ProductList
                {
                    Products = new List<Models.Product.Product>()
                };

                return View("Index", model);
            }
        }
Exemplo n.º 3
0
        public ActionResult Index()
        {
            var products = _productBusiness.GetAll();

            var model = new ProductList { Products = products.Select(x => new Models.Product.Product().InjectFrom(x)).Cast<Models.Product.Product>().ToList() };

            return View("Index", model);
        }