Esempio n. 1
0
        public JsonResult GetCampData(PagingOptions options, Int32 range)
        {
            //paging parameter
            var start  = options.Start;
            var length = options.Length;
            //sorting parameter
            var sortColumn    = options.ColumnName;
            var sortColumnDir = options.Direction ? "descending" : "ascending";
            //filter parameter
            var      searchValue  = options.SearchName;
            int      pageSize     = length;
            int      skip         = start;
            int      recordsTotal = 0;
            var      listCamp     = new List <Campaign>();
            DateTime enddate      = DateTime.Today.AddDays(-3);
            DateTime startdate    = enddate;

            GetStartDate(range, ref startdate);

            switch (range)
            {
            case 0:
                listCamp = dashboardData.GetCampaignData(SessionData.UserID);
                break;

            default:
                listCamp = dashboardData.GetCustCampaignData(SessionData.UserID, startdate, enddate);
                break;
            }

            //Database query
            var v = from a in listCamp select a;

            if (!string.IsNullOrEmpty(searchValue))
            {
                v = v.Where(a =>
                            a.CampaignName.ToLower().Contains(searchValue.ToLower())
                            );
            }

            //sort
            if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir)))
            {
                if (options.IsIgnoreZero)
                {
                    v = SkipZeroCampaigns(sortColumn, v);
                }
                //for make sort simpler we will add Syste.Linq.Dynamic reference
                v = v.OrderBy(sortColumn + " " + sortColumnDir);
            }

            recordsTotal = v.Count();
            listCamp     = v.Skip(skip).Take(pageSize).ToList();

            return(Json(new { recordsTotal = recordsTotal, data = listCamp }));
        }