Esempio n. 1
0
        public ActionResult GridSorting(SortingViewModel model, string submitType)
        {
            //if (model.DummyID.HasValue)
            //    model.Content = new ContentViewModel().AddTitle(dummyID.Value.ToString()).AddText("you clicked " + dummyID.Value.ToString());

            if (ModelState.IsValid)
            {
                if ("Search".Equals(submitType, StringComparison.OrdinalIgnoreCase))
                {
                    // Get PageMetadata from view model.
                    SortingGridMetadata metadata = ExampleMapper.MapToSortingGridMetadata(model);//   MappingEngine.Map<SortingGridMetadata>(model);

                    // Use this page metadata to retrieve data via service.
                    IEnumerable <SortModel> results = DummyService.GetAllForSorting(metadata.Name);

                    // Map these results for paging.
                    // Populate Grid property with data and pageMetata.
                    // NOTE: Mapping contains both Source and Destination types. New Pageable instance is created with page Metadata for use with the destination object, to keep pageMetadata.
                    model.Results = results.ToGridSortingViewModelList(new Pageable <GridSortingViewModel>(metadata));// MappingEngine.Map<IEnumerable<SortModel>, IPageable<GridSortingViewModel>>(results, new Pageable<GridSortingViewModel>(metadata));
                }
                else
                {
                    var selectedValues = model.Results.FirstOrDefault(x => x.SortingID == model.SelectedKeys);
                    if (selectedValues != null)
                    {
                        model.SelectedContent = new ContentViewModel().AddTitle("Selected").AddParagraph(selectedValues.Address);
                    }
                }
            }
            return(View(model));
        }