예제 #1
0
        // GET: /News/Create
        public async Task <ActionResult> Create()
        {
            var news = new News();

            news.NewsTypeList = await _newsTypeDal.QueryAllAsync();

            return(View(news));
        }
예제 #2
0
        // GET: NewsTypes
        public async Task <ActionResult> Index(string sortOrder, string currentFilter, string searchString, int?page)
        {
            ViewBag.CurrentSort  = sortOrder;
            ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";

            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }

            ViewBag.CurrentFilter = searchString;

            IEnumerable <NewsType> entityList = await _newsTypeDal.QueryAllAsync();

            if (entityList.Any())
            {
                if (!String.IsNullOrEmpty(searchString))
                {
                    entityList = entityList.Where(s => s.Name != null && s.Name.Contains(searchString));
                }
                switch (sortOrder)
                {
                case "name_desc":
                    entityList = entityList.OrderByDescending(s => s.Name);
                    break;

                default:     // Name ascending
                    entityList = entityList.OrderBy(s => s.Name);
                    break;
                }
            }
            int pageSize   = 20;
            int pageNumber = (page ?? 1);

            return(View(entityList.ToPagedList(pageNumber, pageSize)));
        }