コード例 #1
0
        public ActionResult TicketViewGridOwner(jQueryDataTableParamModel param)
        {
            List <TicketModel> listdetails = new List <TicketModel>();

            try
            {
                if (TempData.Peek("TicketListOwner") == null)
                {
                    listdetails = objgetTicket.getAllTableDetailsOwner(Convert.ToInt32(Session["ApartmentID"]));
                    TempData["TicketListOwner"] = listdetails;
                }

                else
                {
                    listdetails = TempData.Peek("TicketListOwner") as List <TicketModel>;
                }


                IEnumerable <TicketModel> filteredItems;

                if (!string.IsNullOrEmpty(param.sSearch))
                {
                    var isRetSearchable       = Convert.ToBoolean(Request["bSearchable_1"]);
                    var isStoreInvSearchable  = Convert.ToBoolean(Request["bSearchable_2"]);
                    var isFromStoreSearchable = Convert.ToBoolean(Request["bSearchable_2"]);
                    filteredItems = listdetails
                                    .Where(c => isRetSearchable && c.TicketNo.ToLower().Contains(param.sSearch.ToLower()));
                }
                else
                {
                    filteredItems = listdetails;
                }

                var isRetSortable       = Convert.ToBoolean(Request["bSortable_1"]);
                var isStoreInvSortable  = Convert.ToBoolean(Request["bSortable_2"]);
                var isFromStoreSortable = Convert.ToBoolean(Request["bSortable_3"]);
                var sortColumnIndex     = Convert.ToInt32(Request["iSortCol_0"]);
                Func <TicketModel, string> orderingFunction = (c => sortColumnIndex == 2 && isRetSortable ? c.TicketNo :
                                                               "");

                var sortDirection = Request["sSortDir_0"]; // asc or desc
                if (sortDirection == "asc")
                {
                    filteredItems = filteredItems.OrderBy(orderingFunction);
                }
                else
                {
                    filteredItems = filteredItems.OrderByDescending(orderingFunction);
                }

                //var temp= filteredItems.Select(m=>m.)
                var displayedCompanies = filteredItems.Skip(param.iDisplayStart).Take(param.iDisplayLength);
                var result             = from c in displayedCompanies select new[] { Convert.ToString(c.TicketID), c.TicketNo, c.FIRSTNAME, c.LASTNAME, c.MOBILENO, c.H_Number, c.H_BLOCK, c.Type, c.Description, c.Raised_Date, c.Status };



                return(Json(new
                {
                    sEcho = param.sEcho,
                    iTotalRecords = listdetails.Count(),
                    iTotalDisplayRecords = filteredItems.Count(),
                    aaData = result,
                },
                            JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Json("Something went wrong..Try after some Time", JsonRequestBehavior.AllowGet));
            }
        }