예제 #1
0
        public ActionResult Create()
        {
            List <RootObject> roots    = InfoManipulation.GetRootList();
            List <Teacher>    teachers = InfoManipulation.GetTeacherList(roots);

            InfoManipulation.Create(teachers);
            List <Teacher> list = new List <Teacher>();

            list        = InfoManipulation.Get();
            ViewBag.num = list.Count;
            return(View(list[100]));
        }
예제 #2
0
        public JsonResult GetData(ServerSideParams ssp)
        {
            using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString))
            {
                List <Teacher> list = new List <Teacher>();
                list = InfoManipulation.Get();
                int    pageIndex    = ssp.page;
                int    pageSize     = ssp.rows;
                int    totalRecords = list.Count;
                var    totalPages   = (int)Math.Ceiling((float)totalRecords / (float)ssp.rows);
                string sortIndex    = null;
                string sortOrder    = null;
                switch (ssp.sidx)
                {
                case "Ranking":
                    sortIndex = "Ranking";
                    break;

                case "LessonsNumber":
                    sortIndex = "LessonsNumber";
                    break;

                case "StudentNumber":
                    sortIndex = "StudentNumber";
                    break;

                case "MinPrice":
                    sortIndex = "MinPrice";
                    break;

                case "MaxPrice":
                    sortIndex = "MaxPrice";
                    break;

                default:
                    sortIndex = "Name";
                    break;
                }
                sortOrder = ssp.sord == "asc" ? "asc" : "desc";
                list      = db.Query <Teacher>((@"SELECT Name, Ranking, LessonsNumber, StudentsNumber, MinPrice, MaxPrice
                FROM Teachers
                ORDER BY " + sortIndex + " " + sortOrder +
                                                @" OFFSET @rowsToSkip ROWS 
                FETCH NEXT @rowsToTake ROWS ONLY"), new
                {
                    rowsToSkip = ssp.page * ssp.rows,
                    rowsToTake = pageSize
                }).ToList();

                if (!string.IsNullOrEmpty(ssp.searchString))
                {
                    list = db.Query <Teacher>((@"SELECT Name, Ranking, LessonsNumber, StudentsNumber, MinPrice, MaxPrice
                    FROM Teachers
                    WHERE MinPrice = @value"), new { value = ssp.searchString }).ToList();
                }
                var jsonData = new
                {
                    total   = totalPages,
                    page    = pageIndex,
                    records = totalRecords,
                    rows    = ssp.rows,
                    root    = list
                };
                return(Json(jsonData, JsonRequestBehavior.AllowGet));
            }
        }