Exemplo n.º 1
0
        public ActionResult DummiesMainframe(DummiesMainframeViewModel model, string submitType)
        {
            if (ModelState.IsValid)
            {
                // Execute search only when that action is selected
                if (String.Compare(submitType, "Search", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    // Get page metadata from view model
                    var metadata = ExampleMapper.MapToDummiesMainframePageMetadata(model); // MappingEngine.Map<DummiesMainframePageMetadata>(model);

                    // Use page metadata to retrieve data via service
                    var domainModel = DummyService.Find(metadata.StartsWith, metadata.NextSequenceID);

                    // Note when mainframe is paging, we need to update the page metadata that is specifically used by mainframe for paging
                    ExampleMapper.Map(domainModel, metadata);
                    //metadata = //   MappingEngine.Map<DummiesModel, DummiesMainframePageMetadata>(domainModel, metadata);

                    // Populate grid property with data and page metadata
                    // Note that in the mapping, both the source and destination types are specified,
                    // and a new Pageable instance (with page metadata) is created for use as the destination object (so page metadata is kept)
                    model.Dummies = ExampleMapper.ToPageableDummyViewModel(domainModel.Dummies, new Pageable <DummyViewModel>(metadata));//  MappingEngine.Map<IEnumerable<DummyModel>, IPageable<DummyViewModel>>(domainModel.Dummies, new Pageable<DummyViewModel>(metadata));
                }
                else
                {
                    // Get the selected item
                    var selected = model.Dummies.FirstOrDefault(m => m.DummyID == model.SelectedKey);

                    if (selected != null)
                    {
                        // Display its information
                        model.Content = new ContentViewModel()
                                        .AddTitle(selected.Name)
                                        .AddParagraph(selected.Description);
                    }
                }
            }

            return(View(model));
        }