public ActionResult Index() { ViewBag.Host = AuthorizeUser.IsHost() || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll); ViewBag.Add = AuthorizeUser.IsAction(Ultity.Constant.Add); ViewBag.Edit = AuthorizeUser.IsAction(Ultity.Constant.Edit); ViewBag.Delete = AuthorizeUser.IsAction(Ultity.Constant.Delete); var objRef = new object[5]; string sSort = "a.CreatedDate DESC"; objRef[0] = ""; objRef[1] = sSort; objRef[2] = 0; objRef[3] = 100; objRef[4] = 0; var modelList = _sysGroupAction.List(ref objRef); ViewBag.ListGroup = modelList; return(View()); }
public ActionResult GetData(int?page, int?pageSize, string key, int?sort, string usedState) { var list = new List <SysGroup>(); try { var objRef = new object[5]; int currentPageIndex = page.HasValue ? page.Value - 1 : 0; if (currentPageIndex < 0) { currentPageIndex = 0; } pageSize = pageSize.HasValue ? pageSize : rowInPage; string sWhere = (AuthorizeUser.IsHost() || AuthorizeUser.IsAction(Ultity.Constant.ViewEditAll)) ? " 1=1 " : " a.CreatedBy =" + WebSecurity.CurrentUserId; if (!string.IsNullOrEmpty(key)) { key = key.Trim(); ViewBag.Search = key; sWhere += "and ( a.Name like N'%" + key + "%' or dbo.ConvertToNoSigned(a.Name) like dbo.ConvertToNoSigned(N'%" + key + "%')) "; } if (!string.IsNullOrEmpty(usedState)) { if (!usedState.Equals(Ultity.Constant.All.ToString())) { ViewBag.UsedState = Ultity.TFunction.GetAllUsedStateSelected(CommonHelper.Convert.ConvertToInt32(usedState)); sWhere = string.IsNullOrEmpty(sWhere) ? " a.UsedState=" + usedState + "" : (sWhere + " AND a.UsedState=" + usedState + " "); } } string sSort = "a.CreatedDate DESC"; if (sort.HasValue) { switch (sort.Value) { case 0: sSort = "a.Name ASC"; ViewBag.SortName = "1"; break; case 1: sSort = "a.Name DESC"; ViewBag.SortName = "2"; break; case 2: ViewBag.SortName = "0"; sSort = "a.Orders ASC"; break; } } else { ViewBag.SortName = "0"; } objRef[0] = sWhere; objRef[1] = sSort; objRef[2] = currentPageIndex; objRef[3] = pageSize; objRef[4] = 0; var modelList = _sysAction.List(ref objRef); int totalRow = CommonHelper.Convert.ConvertToInt32(objRef[4]); //Check after deleted last item in page . Redirect page close have value smaller if (Request.IsAjaxRequest()) { return(Json(new { status = "success", Message = Ultity.Constant.Ajax_Success, Data = modelList, TotalPage = totalRow, CurrentPage = currentPageIndex, PageSize = pageSize })); } } catch (Exception exception) { Ultity.TFunction.WriteToLog(exception); return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail })); } return(Json(new { status = "fail", Message = Ultity.Constant.Ajax_Fail })); }