Beispiel #1
0
        public ActionResult Index()
        {
            IContractValiditiesRepository contractValiditiesRepository = new ContractValiditiesRepository(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"] : "ContractValidityPK";
            string ordering   = sortColumn + " " + sortOrder;

            ordering = ordering.Trim();

            IQueryable <ContractValidity> contractValidities = contractValiditiesRepository.GetValid()
                                                               .OrderBy(ordering);

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

            contractValidities = contractValidities.Page(page, pageSize);

            if (!String.IsNullOrWhiteSpace(Request.QueryString["searchString"]))
            {
                string searchString = Request.QueryString["searchString"].ToString();
                ViewData["numberOfRecords"] = contractValiditiesRepository.GetValid().Where(c => c.Name.Contains(searchString)).Count();
            }
            else
            {
                ViewData["numberOfRecords"] = contractValiditiesRepository.GetValid().Count();
            }

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

            if (page > numberOfPages)
            {
                string url = LinkHelper.getQueryStringArray(new string[] { "page" });
                return(Redirect("ContractValidity?" + url + "page=" + numberOfPages));
            }
            else
            {
                return(View("Index", contractValidities.ToList()));
            }
        }
Beispiel #2
0
        public void BindDDLs(ContractView contractView, ObjectContext db)
        {
            //contract validities ddl
            IContractValiditiesRepository contractValiditiesRepository = new ContractValiditiesRepository(db);

            contractView.ContractValidities = new SelectList(contractValiditiesRepository.GetValid().OrderBy("Name ASC").ToList(), "ContractValidityPK", "Name");

            //currencies ddl
            ICurrenciesRepository currenciesRepository = new CurrenciesRepository(db);

            contractView.Currencies = new SelectList(currenciesRepository.GetValid().OrderBy(c => c.Name).Select(c => new { value = c.CurrencyPK, text = c.Name + " (" + c.Sign + ")" }), "value", "text");
        }