コード例 #1
0
        /// <summary>
        /// Method to return GridModel for watchlist grid.
        /// </summary>
        /// <param name="gridContext">The grid context containing search, sort and paging info.</param>
        /// <returns>The grid model required for grid construction.</returns>
        private GridModel CreateWatchListGridModel(GridContext gridContext)
        {
            var gridModelBuilder = new GridModelBuilder();

            // Create grid search criteria from the grid context and retrieve list of watch list entities from the DB.
            var gridSearchCriteria = this.CreateGridSearchCriteriaEntity(gridContext);

            IWatchListBusiness iWatchListBusiness = new WatchListBusiness();

            var watchListEntities = iWatchListBusiness.SearchWatchList(gridSearchCriteria, 0);
            var watchListModels = watchListEntities.Select(WatchListModel.ConvertWatchListEntityToModel).ToList();

            // Grid context is already available. Just set the number of records in it.
            gridContext.GridPager.TotalRecord = gridSearchCriteria.RecordCount;

            // Create list of columns in the grid.
            var columns = new List<GridColumnModel>
                              {
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "Name",
                                                               Label = "Name"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "BseSymbol",
                                                               Label = "BSE Symbol"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "NseSymbol",
                                                               Label = "NSE Symbol"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "AltNameOne",
                                                               Label = "Alt Name One"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "AltNameTwo",
                                                               Label = "Alt Name Two"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "AltNameThree",
                                                               Label = "Alt Name Three"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "TempName",
                                                               Label = "Temp Name"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               ColumnType = GridColumnType.Link,
                                                               Label = "Is Active?",
                                                               SortColumnName = "IsActive"
                                                           },
                                          Links = watchListModels.Select(x => new List<GridLinkModel>
                                                                                  {
                                                                                      new GridLinkModel
                                                                                          {
                                                                                              Action = "WatchList/ChangeActiveStatus/" + x.WatchListID,
                                                                                              Behaviour = GridActionBehaviour.PostSilent,
                                                                                              ImagePath = ConfigHelper.GetBooleanImage(x.IsActive)
                                                                                          }
                                                                                  }).ToList()
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               ColumnType = GridColumnType.Link,
                                                               Label = "Is Alert Required?",
                                                               SortColumnName = "AlertRequired"
                                                           },
                                          Links = watchListModels.Select(x => new List<GridLinkModel>
                                                                                  {
                                                                                      new GridLinkModel
                                                                                          {
                                                                                              Action = "WatchList/ChangeAlertStatus/" + x.WatchListID,
                                                                                              Behaviour = GridActionBehaviour.PostSilent,
                                                                                              ImagePath = ConfigHelper.GetBooleanImage(x.AlertRequired)
                                                                                          }
                                                                                  }).ToList()
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "ModifiedOn",
                                                               Label = "Modified On"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               BindingColumnName = "CreatedOn",
                                                               Label = "Created On"
                                                           }
                                      },
                                      new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               ColumnType = GridColumnType.Link
                                                           },
                                          Links = watchListModels.Select(x => new List<GridLinkModel>
                                                                                  {
                                                                                      new GridLinkModel
                                                                                          {
                                                                                              Action = "WatchList/EditWatchList/" + x.WatchListID,
                                                                                              Behaviour = GridActionBehaviour.Popup,
                                                                                              Text = "Edit"
                                                                                          },
                                                                                      new GridLinkModel
                                                                                          {
                                                                                              Action = "WatchList/DeleteWatchList/" + x.WatchListID,
                                                                                              Behaviour = GridActionBehaviour.PostSilent,
                                                                                              Text = "Delete"
                                                                                          }
                                                                                  }).ToList()
                                      }
                              };

            // Create grid model builder entity.
            var gridModelBuilderEntity = new GridModelBuilderEntity
            {
                Columns = columns,
                GridContext = gridContext
            };

            // Build the grid context to be returned.
            return gridModelBuilder.BuildGridModel(gridModelBuilderEntity, watchListModels, Url.Action(_DefaultGridAction));
        }
コード例 #2
0
ファイル: TestController.cs プロジェクト: omprsingh/CashCow
        private GridModel GetGridModel(IList<WatchListModel> watchListModels, int recordCount)
        {
            var columns = new List<GridColumnModel>
                              {
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               ColumnType = GridColumnType.CheckBox,
                                                               IsDisabled = false
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               ColumnType = GridColumnType.Image,
                                                               BindingColumnName = "AlertRequired",
                                                               Label = "Alert Required?"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               ColumnType = GridColumnType.Text,
                                                               BindingColumnName = "AlertRequired",
                                                               Label = "Alert Required?"
                                                           }
                                      },
                                  new GridColumnModel
                                      {
                                          HeaderCell = new GridHeaderCellModel
                                                           {
                                                               ColumnType = GridColumnType.Link,
                                                               Label = "Links"
                                                           },
                                          Links = watchListModels.Select(x => new List<GridLinkModel>
                                                                                  {
                                                                                      new GridLinkModel
                                                                                          {
                                                                                              Action = "test/test",
                                                                                              AlertMessage =
                                                                                                  "Are you sure?",
                                                                                              Behaviour =
                                                                                                  GridActionBehaviour.PostSilent,
                                                                                              ImagePath =
                                                                                                  ConfigHelper.
                                                                                                  GetBooleanImage(
                                                                                                      x.AlertRequired)
                                                                                          },
                                                                                      new GridLinkModel
                                                                                          {
                                                                                              Action = "http://google.com",
                                                                                              Behaviour = GridActionBehaviour.PostSilent,
                                                                                              Text = x.Name
                                                                                          }
                                                                                  }).ToList()
                                      }
                              };

            // Set the GridModelBuilderEntity
            var gridModelBuilderEntity = new GridModelBuilderEntity
                                             {
                                                 Columns = columns,
                                                 GridContext = new GridContext
                                                                   {
                                                                       SortInfo = new GridSortInfo
                                                                                      {
                                                                                          SortOn = "AlertRequired",
                                                                                          SortOrder = SortDirection.Descending
                                                                                      },
                                                                       SearchInfo = new GridSearchInfo
                                                                       {
                                                                           TextSearchKey = "Test search"
                                                                       }
                                                                   }
                                             };

            var gridModelBuilder = new GridModelBuilder();
            return gridModelBuilder.BuildGridModel(gridModelBuilderEntity, watchListModels, Url.Action(gridModelBuilderEntity.GridContext.DefaultAction));
        }