public ActionResult BuildPaganationPromotionList(PromotionListModel model) { try { return(Json(new { NOP = (new PromotionModel()).BuildPaganationPromotionList(model) }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { error = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public ActionResult FillPromotionSearchGrid(PromotionListModel model) { try { return(Json((new PromotionModel()).FillPromotionSearchGrid(model), JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { error = ex.Message }, JsonRequestBehavior.AllowGet)); } }
// GET: Promotion public async Task <IActionResult> Index(string sortOrder, string currentFilter, string searchString, int?page) { ViewBag.CurrentSort = sortOrder; ViewBag.IdSortParm = string.IsNullOrEmpty(sortOrder) ? "id" : ""; ViewBag.DstartSortParm = string.IsNullOrEmpty(sortOrder) ? "date_start" : ""; ViewBag.DendSortParm = string.IsNullOrEmpty(sortOrder) ? "date_end" : ""; ViewBag.DescriptionSortParm = string.IsNullOrEmpty(sortOrder) ? "description" : ""; ViewBag.NameSortParm = string.IsNullOrEmpty(sortOrder) ? "name" : ""; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var list = await GetPromotionQueryable(); if (!string.IsNullOrEmpty(searchString)) { list = list.Where(s => s.Name.Contains(searchString)); } switch (sortOrder) { case "id": list = list.OrderByDescending(p => p.Id); break; case "date_start": list = list.OrderByDescending(p => p.Date_start); break; case "date_end": list = list.OrderByDescending(p => p.Date_end); break; case "description": list = list.OrderByDescending(p => p.Description); break; case "name": list = list.OrderByDescending(p => p.Name); break; default: list = list.OrderBy(s => s.Id); break; } var pageNumber = page ?? 1; var productlist = new PromotionListModel { Promotions = list.ToPagedList(pageNumber, 15) }; return(View(productlist)); }