Exemplo n.º 1
0
        public ActionResult Index(string sortingAttribute)
        {
            if (sortingAttribute == null)
            {
                sortingAttribute = "Status";
            }

            using (var dataContext = new DataContext())
            {
                var sortableAttributes = dataContext.Attributes
                                         .Select(a => a.Key)
                                         .Distinct()
                                         .OrderBy(a => a)
                                         .ToArray();

                var cards = dataContext.Cards
                            .Select(c => new
                {
                    Key = c.Attributes
                          .Where(a => a.Key == sortingAttribute)
                          .FirstOrDefault(),
                    Card = c,
                })
                            .OrderBy(o => o.Key.DisplayOrder)
                            .ToLookup(
                    o => o.Key == null ? null : o.Key.Value,
                    o => o.Card
                    );

                var viewModel = new Models.Cards.Index <string>
                {
                    SortingAttribute   = sortingAttribute,
                    SortableAttributes = sortableAttributes,
                    Cards = cards,
                };

                return(View(viewModel));
            }
        }
Exemplo n.º 2
0
        public ActionResult Index(string sortingAttribute)
        {
            if(sortingAttribute == null)
                sortingAttribute = "Status";

            using(var dataContext = new DataContext())
            {
                var sortableAttributes = dataContext.Attributes
                    .Select(a => a.Key)
                    .Distinct()
                    .OrderBy(a => a)
                    .ToArray();

                var cards = dataContext.Cards
                    .Select(c => new
                    {
                        Key = c.Attributes
                            .Where(a => a.Key == sortingAttribute)
                            .FirstOrDefault(),
                        Card = c,
                    })
                    .OrderBy(o => o.Key.DisplayOrder)
                    .ToLookup(
                        o => o.Key == null ? null : o.Key.Value,
                        o => o.Card
                    );

                var viewModel = new Models.Cards.Index<string>
                {
                    SortingAttribute = sortingAttribute,
                    SortableAttributes = sortableAttributes,
                    Cards = cards,
                };

                return View(viewModel);
            }
        }