public virtual ActionResult CustSegmentList(DataSourceRequest command, CustSegmentModel model, string sort, string sortDir)
        {
            var items = _dqQueService.GetAllCustSegments(model.ORGKEY, model.CUSTOMER_TYPE, model.ACCOUNT_NO, model.CUST_FIRST_NAME, model.CUST_MIDDLE_NAME, model.CUST_LAST_NAME, model.PRIMARY_SOL_ID,
                                                         model.SECTOR, model.SUBSECTOR, command.Page - 1, command.PageSize, string.Format("{0} {1}", sort, sortDir));
            //var logItems = _logger.GetAllLogs(createdOnFromValue, createdToFromValue, model.Message,
            //    logLevel, command.Page - 1, command.PageSize);
            DateTime _today    = DateTime.Now.Date;
            var      gridModel = new DataSourceResult
            {
                Data = items.Select(x => new CustSegmentModel
                {
                    Id                 = x.ID,
                    ORGKEY             = x.ORGKEY,
                    CUST_FIRST_NAME    = x.CUST_FIRST_NAME,
                    CUST_MIDDLE_NAME   = x.CUST_MIDDLE_NAME,
                    CUST_LAST_NAME     = x.CUST_LAST_NAME,
                    GENDER             = x.GENDER,
                    CUST_DOB           = x.CUST_DOB,
                    CUSTOMERMINOR      = x.CUSTOMERMINOR,
                    MAIDENNAMEOFMOTHER = x.MAIDENNAMEOFMOTHER,
                    NICK_NAME          = x.NICK_NAME,
                    PLACEOFBIRTH       = x.PLACEOFBIRTH,
                    PRIMARY_SOL_ID     = x.PRIMARY_SOL_ID,
                    SEGMENTATION_CLASS = x.SEGMENTATION_CLASS,
                    SECTOR             = x.SECTOR,
                    SECTORNAME         = x.SECTORNAME,
                    SUBSECTOR          = x.SUBSECTOR,
                    SUBSECTORNAME      = x.SUBSECTORNAME,
                    SUBSEGMENT         = x.SUBSEGMENT,
                    CORP_ID            = x.CORP_ID,
                    SCHEME_CODE        = x.SCHEME_CODE,
                    ACCOUNT_NO         = x.ACCOUNT_NO,
                    CUSTOMER_TYPE      = x.CUSTOMER_TYPE,
                    REASON             = x.REASON
                }),
                Total = items.TotalCount
            };

            return(Json(gridModel));
        }
        public virtual ActionResult ExportExcelAll(CustSegmentModel model)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(AccessDeniedView());
            }
            var items = _dqQueService.GetAllCustSegments(model.ORGKEY, model.CUSTOMER_TYPE, model.ACCOUNT_NO, model.CUST_FIRST_NAME,
                                                         model.CUST_MIDDLE_NAME, model.CUST_LAST_NAME, model.PRIMARY_SOL_ID, model.SECTOR, model.SUBSECTOR);

            try
            {
                byte[] bytes = _exportManager.ExportDocumentsToXlsx(items);
                identity = ((CustomPrincipal)User).CustomIdentity;
                _messagingService.SaveUserActivity(identity.ProfileId, "Downloaded Wrong Sector / Subsector Mapping Report", DateTime.Now);
                return(File(bytes, MimeTypes.TextXlsx, "wrongSectorSubsector.xlsx"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc);
                return(RedirectToAction("List"));
            }
        }
        public ActionResult List()
        {
            var model = new CustSegmentModel();

            if (!User.Identity.IsAuthenticated)
            {
                return(AccessDeniedView());
            }

            identity           = ((CustomPrincipal)User).CustomIdentity;
            _permissionservice = new PermissionsService(identity.Name, identity.UserRoleId);

            model.CustomerTypes.Add(new SelectListItem
            {
                Text  = "INDIVIDUAL",
                Value = "INDIVIDUAL"
            });
            model.CustomerTypes.Add(new SelectListItem
            {
                Text  = "CORPORATE",
                Value = "CORPORATE"
            });
            model.CustomerTypes.Add(new SelectListItem
            {
                Value    = "0",
                Text     = "All",
                Selected = true
            });
            model.SectorList.Add(new SelectListItem
            {
                Value = "Sector is null",
                Text  = "Sector is null"
            });
            model.SectorList.Add(new SelectListItem
            {
                Value = "Sector is not null",
                Text  = "Sector is not null"
            });
            model.SectorList.Add(new SelectListItem
            {
                Value    = "0",
                Text     = "All",
                Selected = true
            });
            model.SubsectorList.Add(new SelectListItem
            {
                Value = "Subsector is null",
                Text  = "Subsector is null"
            });
            model.SubsectorList.Add(new SelectListItem
            {
                Value = "Subsector is not null",
                Text  = "Subsector is not null"
            });
            model.SubsectorList.Add(new SelectListItem
            {
                Value    = "0",
                Text     = "All",
                Selected = true
            });

            IQueryable <CM_BRANCH> curBranchList = db.CM_BRANCH.OrderBy(x => x.BRANCH_NAME); //.Where(a => a.BRANCH_ID == identity.BranchId);

            if (_permissionservice.IsLevel(AuthorizationLevel.Enterprise))
            {
            }
            else if (_permissionservice.IsLevel(AuthorizationLevel.Regional))
            {
                curBranchList = curBranchList.Where(a => a.REGION_ID == identity.RegionId);
            }
            else if (_permissionservice.IsLevel(AuthorizationLevel.Zonal))
            {
                curBranchList = curBranchList.Where(a => a.ZONECODE == identity.ZoneId).OrderBy(a => a.BRANCH_NAME);
            }
            else if (_permissionservice.IsLevel(AuthorizationLevel.Branch))
            {
                curBranchList = curBranchList.Where(a => a.BRANCH_ID == identity.BranchId).OrderBy(a => a.BRANCH_NAME);
            }
            else
            {
                curBranchList = curBranchList.Where(a => a.BRANCH_ID == "-1");
            }

            model.Branches = new SelectList(curBranchList, "BRANCH_ID", "BRANCH_NAME").ToList();


            if (_permissionservice.IsLevel(AuthorizationLevel.Enterprise))
            {
                model.Branches.Add(new SelectListItem
                {
                    Value    = "0",
                    Text     = "All",
                    Selected = true
                });
            }

            _messagingService.SaveUserActivity(identity.ProfileId, "Viewed Wrong Sector / Subsector Mapping Report", DateTime.Now);

            return(View(model));
        }