Пример #1
0
        public async Task <ActionResult> LoadExams()
        {
            try
            {
                if (Request.Form != null)
                {
                    var draw       = Request.Form.GetValues("draw").FirstOrDefault();
                    var start      = Request.Form.GetValues("start").FirstOrDefault();
                    var length     = Request.Form.GetValues("length").FirstOrDefault();
                    var sortColumn =
                        Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault();
                    var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault();
                    var searchValue   = Request.Form.GetValues("search[value]").FirstOrDefault();


                    //Paging Size (10,20,50,100)
                    int pageSize = length != null?Convert.ToInt32(length) : 0;

                    int skip = start != null?Convert.ToInt32(start) : 1;

                    int recordsTotal = 0;

                    var educationTypeList = await _examservice.GetAllAsync(
                        skip,
                        pageSize,

                        //sorting
                        // x => sortColumn == "Name" ? x.Name : null,
                        x => sortColumn == "Name"?x.Name : (sortColumn == "ExamType" ? x.ExamType.Name : (sortColumn == "SubCategory" ? x.SubCategory.Name : (sortColumn == "Passmark"?x.Passmark.ToString() : null))),
                        //filtering
                        x => searchValue != ""?x.Name.Contains(searchValue) : x.Id != 0,

                        //sort by
                        (sortColumnDir == "desc" ? OrderBy.Descending : OrderBy.Ascending),

                        //Include ExamType
                        x => x.ExamType,
                        x => x.SubCategory
                        );

                    var resp = Mapper.Map <List <Exam>, List <ExamResource> >(educationTypeList);

                    //total number of rows count
                    recordsTotal = educationTypeList.TotalCount;
                    return(Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = resp }));
                }
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString()));
            }
            return(Content("Error"));
        }
        //POST: Search

        public async Task <JsonResult> SearchExam(ExamList examList)
        {
            int subCategoryId = 0, examtypeid = 0, categoryId = 0;

            if (examList.CategoryId != null && examList.CategoryId != "0")
            {
                categoryId = Convert.ToInt32(examList.CategoryId);
            }
            if (examList.SubcategoryId != null && examList.SubcategoryId != "0")
            {
                subCategoryId = Convert.ToInt32(examList.SubcategoryId);
            }
            if (examList.Examtypeid != null)
            {
                examtypeid = Convert.ToInt32(examList.Examtypeid);
            }

            var examlist = await _examservice.GetAllAsync(

                examList.skip,
                examList.pageSize,

                //sorting

                x => x.Name,

                //filtering
                x => (categoryId != 0 ? x.SubCategory.CategoryId == categoryId : x.Status) &&
                (subCategoryId != 0 ? x.SubcategoryId == subCategoryId : x.Status) &&
                (examtypeid != 0 ? x.ExamtypeId == examtypeid : x.Status) &&
                (examList.KeyWord != null ? x.Name.Contains(examList.KeyWord) : x.Status),

                //sort by
                OrderBy.Descending


                );

            var recordsTotal = examlist.TotalCount;
            var totalItem    = examlist.Count();
            var resp         = Mapper.Map <List <Exam>, List <ExamResource> >(examlist);

            return(Json(new { exam = resp, total = recordsTotal, totalItem = totalItem }));
        }