Esempio n. 1
0
        public ActionResult List()
        {
            ListViewModel model = new ListViewModel();

            model.Filter      = new ListFilterViewModel();
            model.CurrentPage = 1;
            model.PageSize    = 10;
            BloodGroupSearchFilter searchFilter = new BloodGroupSearchFilter();

            searchFilter.CurrentPage   = model.CurrentPage.HasValue ? model.CurrentPage.Value : 1;
            searchFilter.PageSize      = model.PageSize.HasValue ? model.PageSize.Value : 10;
            searchFilter.SortOn        = model.SortOn;
            searchFilter.SortDirection = model.SortDirection;
            searchFilter.Filter_Name   = model.Filter.Filter_Name;

            try
            {
                model.DataList = _bloodGroupService.GetAllPaginatedWithDetailBySearchFilter(searchFilter);
            }
            catch
            {
                model.DataList       = new PaginatedList <BloodGroup>(new List <BloodGroup>(), 0, searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection);
                ViewBag.ErrorMessage = "Error";
            }
            return(View(model));
        }
Esempio n. 2
0
        public PaginatedList <BloodGroup> GetAllPaginatedWithDetailBySearchFilter(BloodGroupSearchFilter searchFilter)
        {
            PaginatedList <BloodGroup> resultList = new PaginatedList <BloodGroup>(new List <BloodGroup>(), 0, searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection);

            using (AppDBContext dbContext = new AppDBContext(_config))
            {
                var query = from a in dbContext.BloodGroup
                            select a;

                // filtering
                if (!string.IsNullOrEmpty(searchFilter.Filter_Name))
                {
                    query = query.Where(r => r.Name.Contains(searchFilter.Filter_Name));
                }

                // asnotracking
                query = query.AsNoTracking();

                //total count
                var totalCount = query.Count();

                //sorting
                if (!string.IsNullOrEmpty(searchFilter.SortOn))
                {
                    // using System.Linq.Dynamic.Core; nuget paketi ve namespace eklenmelidir, dynamic order by yapmak icindir
                    query = query.OrderBy(searchFilter.SortOn + " " + searchFilter.SortDirection.ToUpper());
                }
                else
                {
                    // deefault sıralama vermek gerekiyor yoksa skip metodu hata veriyor ef 6'da -- 28.10.2019 15:40
                    // https://stackoverflow.com/questions/3437178/the-method-skip-is-only-supported-for-sorted-input-in-linq-to-entities
                    query = query.OrderBy(r => r.Id);
                }

                //paging
                query = query.Skip((searchFilter.CurrentPage - 1) * searchFilter.PageSize).Take(searchFilter.PageSize);


                resultList = new PaginatedList <BloodGroup>(
                    query.ToList(),
                    totalCount,
                    searchFilter.CurrentPage,
                    searchFilter.PageSize,
                    searchFilter.SortOn,
                    searchFilter.SortDirection
                    );
            }

            return(resultList);
        }
Esempio n. 3
0
        public ActionResult List(ListViewModel model)
        {
            // filter bilgilerinin default boş değerlerle doldurulması sağlanıyor
            if (model.Filter == null)
            {
                model.Filter = new ListFilterViewModel();
            }

            if (!model.CurrentPage.HasValue)
            {
                model.CurrentPage = 1;
            }

            if (!model.PageSize.HasValue)
            {
                model.PageSize = 10;
            }

            BloodGroupSearchFilter searchFilter = new BloodGroupSearchFilter();

            searchFilter.CurrentPage   = model.CurrentPage.HasValue ? model.CurrentPage.Value : 1;
            searchFilter.PageSize      = model.PageSize.HasValue ? model.PageSize.Value : 10;
            searchFilter.SortOn        = model.SortOn;
            searchFilter.SortDirection = model.SortDirection;
            searchFilter.Filter_Name   = model.Filter.Filter_Name;

            try
            {
                model.DataList = _bloodGroupService.GetAllPaginatedWithDetailBySearchFilter(searchFilter);
            }
            catch
            {
                model.DataList       = new PaginatedList <BloodGroup>(new List <BloodGroup>(), 0, searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection);
                ViewBag.ErrorMessage = "Error";
            }
            return(View(model));
        }