/// <summary>
 /// Method to create GridSearchCriteriaEntity from grid context.
 /// </summary>
 /// <param name="gridContext">Grid context of the grid.</param>
 /// <returns>GridSearchCriteriaEntity</returns>
 public GridSearchCriteriaEntity CreateGridSearchCriteriaEntity(GridContext gridContext)
 {
     return new GridSearchCriteriaEntity
     {
         MaximumRows = gridContext.GridPager.PageSize,
         SearchAgainst = gridContext.SearchInfo.SearchAgainstCriteria,
         SearchCriteria = this.ConvertContextSearchCriteriaListToGridSearchCriteria(gridContext.SearchInfo.SearchCriteriaList),
         SearchWithOr = gridContext.SearchInfo.SearchWithOr,
         SortAscending = gridContext.SortInfo.SortAscending,
         SortColumn = gridContext.SortInfo.SortOn,
         StartRowIndex = gridContext.GridPager.StartRowIndex,
         TextSearchKey = gridContext.SearchInfo.TextSearchKey
     };
 }
Esempio n. 2
0
        public JsonResult Index(WatchListSearchModel watchListSearchModel)
        {
            // Construct the grid context.
            var gridContext = new GridContext
                                  {
                                      SearchInfo = new GridSearchInfo
                                                       {
                                                           SearchAgainstCriteria = watchListSearchModel.SearchAgainst,
                                                           SearchCriteriaList = this.CreateSearchCriteriaListForWatchListGrid(watchListSearchModel),
                                                           SearchWithOr = !watchListSearchModel.SearchWithAnd
                                                       },
                                      SortInfo = new GridSortInfo {SortOn = "Name"}
                                  };

            return Json(this.CreateWatchListGridModel(gridContext));
        }
        /// <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));
        }