Esempio n. 1
0
        public ActionResult Voucher()
        {
            var lsVoucher = VoucherService.GetVoucherVIewStore();

            ViewBag.lsVoucher = lsVoucher;
            return(View());
        }
Esempio n. 2
0
        public ActionResult AjaxHandler(JQueryDataTableParamModel param)
        {
            var allVoucher = VoucherService.GetVoucherVIewStore();
            IEnumerable <VoucherModel> filteredVoucher;

            //Check whether the Voucher should be filtered by keyword
            if (!string.IsNullOrEmpty(param.sSearch))
            {
                //Used if particulare columns are filtered
                var nameFilter    = Convert.ToString(Request["sSearch_1"]);
                var addressFilter = Convert.ToString(Request["sSearch_2"]);
                var townFilter    = Convert.ToString(Request["sSearch_3"]);

                //Optionally check whether the columns are searchable at all
                var isNameSearchable    = Convert.ToBoolean(Request["bSearchable_1"]);
                var isAddressSearchable = Convert.ToBoolean(Request["bSearchable_2"]);
                var isTownSearchable    = Convert.ToBoolean(Request["bSearchable_3"]);

                filteredVoucher = VoucherService.GetVoucherVIewStore()
                                  .Where(c => isNameSearchable && (c.VoucherName.ToLower().Contains(param.sSearch.ToLower()) || c.Body.ToLower().Contains(param.sSearch.ToLower())));
            }
            else
            {
                filteredVoucher = allVoucher;
            }

            var isNameSortable    = Convert.ToBoolean(Request["bSortable_1"]);
            var isAddressSortable = Convert.ToBoolean(Request["bSortable_2"]);
            var isTownSortable    = Convert.ToBoolean(Request["bSortable_3"]);
            var sortColumnIndex   = Convert.ToInt32(Request["iSortCol_0"]);
            Func <VoucherModel, string> orderingFunction = (c => sortColumnIndex == 1 && isNameSortable ? c.Id.ToString() :
                                                            sortColumnIndex == 2 && isAddressSortable ? c.SiteName.ToString() :
                                                            sortColumnIndex == 3 && isAddressSortable ? c.LinkAffiliate.ToString() :
                                                            sortColumnIndex == 4 && isAddressSortable ? c.VoucherName.ToString() :
                                                            sortColumnIndex == 5 && isAddressSortable ? c.Body.ToString() :
                                                            sortColumnIndex == 6 && isTownSortable ? c.CreateDate.ToString() :
                                                            sortColumnIndex == 7 && isTownSortable ? c.EndDate.ToString() :
                                                            "");

            var sortDirection = Request["sSortDir_0"]; // asc or desc

            if (sortDirection == "asc")
            {
                filteredVoucher = filteredVoucher.OrderBy(orderingFunction);
            }
            else
            {
                filteredVoucher = filteredVoucher.OrderByDescending(orderingFunction);
            }

            var displayedVoucher = filteredVoucher.Skip(param.iDisplayStart).Take(param.iDisplayLength);
            var result           = from c in displayedVoucher select new[] { Convert.ToString(c.Id), c.SiteName, c.VoucherName, c.Body, Convert.ToString(c.EndDate), Convert.ToString(c.Flag) };

            return(Json(new
            {
                sEcho = param.sEcho,
                iTotalRecords = allVoucher.Count(),
                iTotalDisplayRecords = filteredVoucher.Count(),
                aaData = result
            },
                        JsonRequestBehavior.AllowGet));
        }