コード例 #1
0
        public ColumnGridDetailsDto GetDefaultGridInfo(string TableName)
        {
            UserEntities         db = new UserEntities();
            ColumnGridDetailsDto gridColumnsInfo = new ColumnGridDetailsDto();

            gridColumnsInfo.visibleColumns = db.ColumnSettings.Where(x => x.GridName == TableName && x.IsVisible == true).Select(x => new ColumnDto
            {
                ColumnId       = x.Id,
                ColumnText     = x.ColumnText,
                GridName       = x.GridName,
                ColumnFilterId = x.ColumnFilterId,
                ColumnType     = x.ColumnType,
                ColumnWidth    = x.ColumnWidth,
                OrderBy        = x.ColumnOrder
            }).OrderBy(x => x.OrderBy).ToList();

            gridColumnsInfo.hiddenColumns = db.ColumnSettings.Where(x => x.GridName == TableName && x.IsVisible == false).Select(x => new ColumnDto
            {
                ColumnId       = x.Id,
                ColumnText     = x.ColumnText,
                GridName       = x.GridName,
                ColumnFilterId = x.ColumnFilterId,
                ColumnType     = x.ColumnType,
                ColumnWidth    = x.ColumnWidth,
                OrderBy        = x.ColumnOrder
            }).OrderBy(x => x.OrderBy).ToList();
            return(gridColumnsInfo);
        }
コード例 #2
0
        public ColumnGridDetailsDto GetGridInfo(string TableName)
        {
            ColumnGridDetailsDto gridDetailsDto = new ColumnGridDetailsDto();
            UserEntities         db             = new UserEntities();
            var checkUserTableExists            = db.ColumnUsersSettings.Where(x => x.GridName == TableName).ToList();

            if (checkUserTableExists.Count > 0)
            {
                gridDetailsDto.visibleColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == true).AsEnumerable()
                                                .Select(x => new ColumnDto
                {
                    ColumnId       = x.Id,
                    ColumnText     = x.ColumnText,
                    GridName       = x.GridName,
                    ColumnFilterId = x.ColumnFilterId,
                    ColumnType     = x.ColumnType,
                    ColumnWidth    = x.ColumnWidth,
                    OrderBy        = x.ColumnOrder
                }).OrderBy(x => x.OrderBy).ToList();

                gridDetailsDto.hiddenColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == false).AsEnumerable()
                                               .Select(x => new ColumnDto
                {
                    ColumnId       = x.Id,
                    ColumnText     = x.ColumnText,
                    GridName       = x.GridName,
                    ColumnFilterId = x.ColumnFilterId,
                    ColumnType     = x.ColumnType,
                    ColumnWidth    = x.ColumnWidth,
                    OrderBy        = x.ColumnOrder
                }).OrderBy(x => x.OrderBy).ToList();
            }
            else
            {
                gridDetailsDto.visibleColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == true).AsEnumerable()
                                                .Select(x => new ColumnDto
                {
                    ColumnId       = x.Id,
                    ColumnText     = x.ColumnText,
                    GridName       = x.GridName,
                    ColumnFilterId = x.ColumnFilterId,
                    ColumnType     = x.ColumnType,
                    ColumnWidth    = x.ColumnWidth,
                    OrderBy        = x.ColumnOrder
                }).OrderBy(x => x.OrderBy).ToList();

                gridDetailsDto.hiddenColumns = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.IsVisible == false).AsEnumerable()
                                               .Select(x => new ColumnDto
                {
                    ColumnId       = x.Id,
                    ColumnText     = x.ColumnText,
                    GridName       = x.GridName,
                    ColumnFilterId = x.ColumnFilterId,
                    ColumnType     = x.ColumnType,
                    ColumnWidth    = x.ColumnWidth,
                    OrderBy        = x.ColumnOrder
                }).OrderBy(x => x.OrderBy).ToList();
            }
            return(gridDetailsDto);
        }
コード例 #3
0
        public JsonResult RestoreGrid(string TableName)
        {
            HomeService          homeService = new HomeService();
            ColumnGridDetailsDto gridInfo    = homeService.GetDefaultGridInfo(TableName);

            return(Json(gridInfo, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult AddRemoveColumn(string TableName, string ModalFor)
        {
            HomeService          homeService = new HomeService();
            ColumnGridDetailsDto gridInfo    = homeService.GetGridInfo(TableName);

            ViewBag.TableName = TableName;
            ViewBag.ModalFor  = ModalFor;
            return(PartialView("_ColumnGridSettings", gridInfo));
        }
コード例 #5
0
 public JsonResult SaveUpdateGridSettings(ColumnGridDetailsDto GridInfo, string TableName)
 {
     try
     {
         HomeService homeService = new HomeService();
         homeService.SaveUpdateGridInfo(GridInfo, TableName);
         return(Json(true));
     }
     catch (Exception ex)
     {
         return(Json(false));
     }
 }
コード例 #6
0
        public void SaveUpdateGridInfo(ColumnGridDetailsDto GridDetails, string TableName)
        {
            UserEntities db = new UserEntities();
            var          checkUserTableExists = db.ColumnUsersSettings.Where(x => x.GridName == TableName).ToList();

            try
            {
                // Update Entries if record found
                if (checkUserTableExists.Count() > 0 && checkUserTableExists != null)
                {
                    int ColumnOrder = 1;

                    // update visible columns properties
                    foreach (var item in GridDetails.visibleColumns)
                    {
                        var gridColumn = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.ColumnText == item.ColumnText).FirstOrDefault();

                        if (gridColumn == null)
                        {
                            SaveColumnData(ColumnOrder, item, TableName);
                        }
                        else
                        {
                            gridColumn.IsVisible       = true;
                            gridColumn.ColumnWidth     = item.ColumnWidth;
                            gridColumn.ColumnOrder     = item.OrderBy;
                            gridColumn.ColumnText      = item.ColumnText;
                            db.Entry(gridColumn).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        ColumnOrder = ColumnOrder + 1;
                    }

                    //update hidden columns properties
                    foreach (var item in GridDetails.hiddenColumns)
                    {
                        var gridColumn = db.ColumnUsersSettings.Where(x => x.GridName == TableName && x.ColumnText == item.ColumnText).FirstOrDefault();

                        if (gridColumn == null)
                        {
                            SaveColumnData(0, item, TableName);
                        }
                        else
                        {
                            gridColumn.IsVisible       = false;
                            gridColumn.ColumnWidth     = item.ColumnWidth;
                            gridColumn.ColumnOrder     = item.OrderBy;
                            gridColumn.ColumnText      = item.ColumnText;
                            db.Entry(gridColumn).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                    }
                }

                // Save Entries if record not found
                else
                {
                    int ColumnOrder = 1;

                    // save visible columns properties
                    foreach (var item in GridDetails.visibleColumns)
                    {
                        // get default column values against table name and matching column name
                        var defaultColumnValues       = db.ColumnUsersSettings.Where(x => x.ColumnText == item.ColumnText && x.GridName == TableName).FirstOrDefault();
                        ColumnUsersSetting gridColumn = new ColumnUsersSetting();
                        gridColumn.IsVisible      = true;
                        gridColumn.ColumnWidth    = item.ColumnWidth;
                        gridColumn.ColumnOrder    = ColumnOrder;
                        gridColumn.ColumnText     = item.ColumnText;
                        gridColumn.GridName       = TableName;
                        gridColumn.ColumnType     = defaultColumnValues.ColumnType;
                        gridColumn.ColumnFilterId = defaultColumnValues.ColumnFilterId;
                        db.ColumnUsersSettings.Add(gridColumn);
                        db.SaveChanges();

                        ColumnOrder = ColumnOrder + 1;
                    }


                    // save hidden columns properties
                    foreach (var item in GridDetails.hiddenColumns)
                    {
                        // get default column values against table name and matching column name
                        var defaultColumnValues       = db.ColumnUsersSettings.Where(x => x.ColumnText == item.ColumnText && x.GridName == TableName).FirstOrDefault();
                        ColumnUsersSetting gridColumn = new ColumnUsersSetting();
                        gridColumn.IsVisible      = false;
                        gridColumn.ColumnWidth    = item.ColumnWidth;
                        gridColumn.ColumnOrder    = 0;
                        gridColumn.ColumnText     = item.ColumnText;
                        gridColumn.GridName       = TableName;
                        gridColumn.ColumnType     = defaultColumnValues.ColumnType;
                        gridColumn.ColumnFilterId = defaultColumnValues.ColumnFilterId;
                        db.ColumnUsersSettings.Add(gridColumn);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }