public async Task <PagedList <Owner> > IndexRequest <T>(IndexRequestModel request) where T : class
        {
            var pagedList = new PagedList <Owner>();
            var list      = new List <Owner>();
            int count     = await _service.Count <Owner>();;


            var data     = Enumerable.Empty <Owner>();
            var query    = Enumerable.Empty <Owner>();
            var searched = false;

            // Search
            if (!string.IsNullOrEmpty(request.SearchString))
            {
                query = await OwnerDataFormatting.Search(_service.GetAll <Owner>(), request.SearchString);

                searched = true;
            }

            // Sort
            if (!string.IsNullOrEmpty(request.SortVariable))
            {
                if (searched)
                {
                    data = OwnerDataFormatting.Sort <Owner>(query, request.SortVariable);
                }
                else
                {
                    data = OwnerDataFormatting.Sort <Owner>(_service.GetAll <Owner>(), request.SortVariable);
                }

                foreach (var item in data)
                {
                    list.Add(item);
                }

                pagedList.Initialize(list.Skip(request.Page * request.PageSize).Take(request.PageSize), request, count);
            }
            // Index request without modifiers
            else
            {
                data = OwnerDataFormatting.Sort <Owner>(_service.GetAll <Owner>(), "Date_desc");

                foreach (var item in data)
                {
                    list.Add(item);
                }

                pagedList.Initialize(list.Skip(request.Page * request.PageSize).Take(request.PageSize), request, count);
            }

            return(pagedList);
        }
예제 #2
0
        public ActionResult Index()
        {
            ViewBag.StudentCount = studentService.Count();
            ViewBag.TeacherCount = teacherService.Count();
            ViewBag.LessonCount  = lessonService.Count();
            ViewBag.ParentCount  = parentService.Count();


            ViewBag.MostExpensiveLesson  = lessonService.GetAll().OrderByDescending(x => x.ücret).FirstOrDefault().dersAdi;
            ViewBag.MostCheapLesson      = lessonService.GetAll().OrderBy(x => x.ücret).FirstOrDefault().dersAdi;
            ViewBag.MostSelectionStudent = studentService.GetAll().OrderByDescending(x => x.dersSecimleri.Count).FirstOrDefault().ogrenciAdi;
            ViewBag.MostSelectionLesson  = lessonService.GetAll().OrderByDescending(x => x.dersSecimleri.Count).FirstOrDefault().dersAdi;
            return(View());
        }
예제 #3
0
 public IActionResult Count()
 {
     try
     {
         int count = _genericService.Count();
         return(Ok(new SingleResponseDto <int>
         {
             IsSuccessful = true,
             Message = "Data is successfully retrived.",
             Data = count,
             PropertyInfoListOfDto = null
         }));
     }
     catch (Exception)
     {
         return(BadRequest(new SingleResponseDto <int>
         {
             IsSuccessful = false,
             Message = "An error occurred while retriving total count of records.",
             Data = int.MinValue,
             PropertyInfoListOfDto = null
         }));
     }
 }
예제 #4
0
        public async Task <PagedList <EquipmentViewModel> > IndexRequest <T>(IndexRequestModel request) where T : class
        {
            var pagedList = new PagedList <EquipmentViewModel>();
            var list      = new List <EquipmentViewModel>();
            int count;

            if (string.IsNullOrEmpty(request.Type) is false)
            {
                Enum.TryParse(request.Type, out EquipmentType choiceType);
                count = await _service.Count <Equipment>(x => x.EquipType == choiceType);
            }
            else
            {
                count = await _service.Count <Equipment>();
            }

            var data     = Enumerable.Empty <Equipment>();
            var query    = Enumerable.Empty <Equipment>();
            var searched = false;

            // Search
            if (!string.IsNullOrEmpty(request.SearchString))
            {
                query = await EquipmentDataFormatting.Search(_service.GetAll <Equipment>(), request.SearchString);

                count    = query.Count();
                searched = true;
            }

            // Sort
            if (!string.IsNullOrEmpty(request.SortVariable))
            {
                if (searched)
                {
                    data = EquipmentDataFormatting.Sort <Equipment>(query, request.SortVariable);
                }
                else
                {
                    data = EquipmentDataFormatting.Sort <Equipment>(_service.GetAll <Equipment>(), request.SortVariable);
                }

                foreach (var item in data)
                {
                    list.Add(new EquipmentViewModel()
                    {
                        Equipment = item
                    });
                }

                pagedList.Initialize(list.Skip(request.Page * request.PageSize).Take(request.PageSize), request, count);
            }
            // Index request without modifiers
            else
            {
                data = EquipmentDataFormatting.Sort <Equipment>(_service.GetAll <Equipment>(), "Date_desc");

                foreach (var item in data)
                {
                    list.Add(new EquipmentViewModel()
                    {
                        Equipment = item
                    });
                }

                pagedList.Initialize(list.Skip(request.Page * request.PageSize).Take(request.PageSize), request, count);
            }

            return(pagedList);
        }