Exemplo n.º 1
0
        public ActionResult Index(int?page)
        {
            int pageNumber = (page ?? 1);

            IEnumerable <ComponentDTO> componentDTOs = ComponentService
                                                       .GetAll()
                                                       .ToList();
            IEnumerable <ComponentVM> componentVMs = Mapper.Map <IEnumerable <ComponentVM> >(componentDTOs);

            ViewBag.ComponentTypeId = GetComponentTypeIdSelectList();
            ViewBag.ModelName       = GetModelNameSelectList();
            ViewBag.Name            = GetComponentNameSelectList();

            FilterParamsDTO parameters = new FilterParamsDTO
            {
                ComponentTypeId = Request.QueryString["componentTypeId"],
                ModelName       = Request.QueryString["modelName"],
                Name            = Request.QueryString["Name"]
            };

            IEnumerable <ComponentDTO> filteredComponentDTOList = ComponentService.GetFilteredList(parameters).ToList();
            IEnumerable <ComponentVM>  filteredComponentVMList  = Mapper.Map <IEnumerable <ComponentVM> >(filteredComponentDTOList);

            return(View(filteredComponentVMList.ToPagedList(pageNumber, PageSize)));
        }
Exemplo n.º 2
0
        public IEnumerable <ComponentDTO> GetFilteredList(FilterParamsDTO parameters)
        {
            IEnumerable <ComponentDTO> filteredComponents = GetAll();

            if (!string.IsNullOrEmpty(parameters.ComponentTypeId))
            {
                Guid guidComponentTypeId = Guid.Parse(parameters.ComponentTypeId);
                filteredComponents = filteredComponents.Where(c => c.ComponentTypeId == guidComponentTypeId);
            }

            if (!string.IsNullOrEmpty(parameters.ModelName))
            {
                filteredComponents = filteredComponents.Where(c => c.ModelName == parameters.ModelName);
            }

            if (!string.IsNullOrEmpty(parameters.Name))
            {
                filteredComponents = filteredComponents.Where(c => c.Name != null && c.Name == parameters.Name);
            }

            return(filteredComponents.OrderBy(c => c.Name));
        }