Exemplo n.º 1
0
        public ActionResult Index()
        {
            IAssessmentsRepository   assessmentsRepository   = new AssessmentsRepository(db);
            ILegalEntitiesRepository legalEntitiesRepository = new LegalEntitiesRepository(db);
            IRisksRepository         risksRepository         = new RisksRepository(db);

            int    page       = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1;
            int    pageSize   = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]);
            string sortOrder  = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC";
            string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "AssessmentPK";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            IQueryable <AssessmentsView> assessments = AssessmentsView.GetHomeView(assessmentsRepository.GetValid(), legalEntitiesRepository.GetValidLegalEntities(), risksRepository.GetValid())
                                                       .OrderBy(ordering);

            //legalEntities ddl
            ViewBag.LegalEntities = new SelectList(legalEntitiesRepository.GetValidLegalEntities().OrderBy("Name ASC").ToList(), "LegalEntityPK", "Name", Request.QueryString["legalEntityFK"]);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["LegalEntityFK"]))
            {
                int legalEntityFK = Convert.ToInt32(Request.QueryString["LegalEntityFK"]);
                assessments = assessments.Where(a => a.LegalEntityFK == legalEntityFK);
            }

            int assessmentCount = 0;

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                assessments     = assessments.Where(c => c.AssessmentComment.Contains(searchString) || c.AssessmentDate.ToString().Contains(searchString) || c.LegalEntityName.Contains(searchString));
                assessmentCount = assessments.Count();
            }

            assessments = assessments.Page(page, pageSize);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                ViewData["numberOfRecords"] = assessmentCount;
            }
            else
            {
                ViewData["numberOfRecords"] = assessmentsRepository.GetValid().Count();
            }

            int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize;

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("Assessment?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", assessments.ToList()));
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            ILegalEntitiesRepository       legalEntitiesRepository       = new LegalEntitiesRepository(db);
            IContractsRepository           contractsRepository           = new ContractsRepository(db);
            ILegalEntityBranchesRepository legalEntityBranchesRepository = new LegalEntityBranchesRepository(db);
            IBanksRepository            banksRepository = new BanksRepository(db);
            ILegalEntityBanksRepository legalEntitiesBanksRepository = new LegalEntityBanksRepository(db);
            ILegalEntityLegalRepresentativesRepository legalEntityLegalRepresentativesRepository = new LegalEntityLegalRepresentativesRepository(db);
            ILegalEntityOwnersRepository legalEntityOwnersRepository = new LegalEntityOwnersRepository(db);
            IAssessmentsRepository       assessmentsRepository       = new AssessmentsRepository(db);

            int    page       = !String.IsNullOrWhiteSpace(Request.QueryString["page"]) ? Convert.ToInt32(Request.QueryString["page"]) : 1;
            int    pageSize   = !String.IsNullOrWhiteSpace(Request.QueryString["pageSize"]) ? Convert.ToInt32(Request.QueryString["pageSize"]) : Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["ResultsPerPage"]);
            string sortOrder  = !String.IsNullOrWhiteSpace(Request.QueryString["sortOrder"]) ? Request.QueryString["sortOrder"] : "DESC";
            string sortColumn = !String.IsNullOrWhiteSpace(Request.QueryString["sortColumn"]) ? Request.QueryString["sortColumn"] : "LegalEntityPK";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            IQueryable <LegalEntityView> legalEntities = LegalEntityView.GetLegalEntityView(legalEntitiesRepository.GetValid(),
                                                                                            legalEntityBranchesRepository.GetValid(),
                                                                                            contractsRepository.GetValid(),
                                                                                            banksRepository.GetValid(),
                                                                                            legalEntitiesBanksRepository.GetValid(),
                                                                                            legalEntityLegalRepresentativesRepository.GetValid(),
                                                                                            legalEntityOwnersRepository.GetValid(),
                                                                                            assessmentsRepository.GetValid())
                                                         .OrderBy(ordering);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"];
                legalEntities = legalEntities.Where(c => c.Name.Contains(searchString));
            }

            if (!String.IsNullOrWhiteSpace(Request.QueryString["company"]) && Request.QueryString["company"].Contains("true"))
            {
                legalEntities = legalEntities.Where(c => c.Company == true);
            }

            if (String.IsNullOrWhiteSpace(Request.QueryString["active"]))
            {
                legalEntities = legalEntities.Where(c => c.Active == true);
            }
            else
            {
                var active = Request.QueryString["active"].Contains("true");
                legalEntities = legalEntities.Where(c => c.Active == active);
            }

            ViewData["numberOfRecords"] = legalEntities.Count();

            legalEntities = legalEntities.Page(page, pageSize);

            int numberOfPages = ((int)ViewData["numberOfRecords"] + pageSize - 1) / pageSize;

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("LegalEntity?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", legalEntities.ToList()));
            }
        }