示例#1
0
        public async Task <Pagination <Project> > ProjectsIndexCallJson(int?page)
        {
            var crowdfundingContext = _context.Project;
            var pageSize            = 2;

            return(await Pagination <Project> .CreateAsync(crowdfundingContext.AsNoTracking(), page ?? 1, pageSize));
        }
示例#2
0
        public async Task <IResponse> Handle(GetProductsByCategoryQuery request, CancellationToken cancellationToken)
        {
            var query = _dbContext.Products
                        .Include(c => c.Category)
                        .Include(c => c.Vendor)
                        .Include(c => c.MeasureUnit)
                        .Where(c => c.CategoryId == request.Id)
                        .Select(c => new ProductVM
            {
                CategoryId   = c.CategoryId,
                CategoryName = c.Category.Name,
                Name         = c.Name,
                Description  = c.Description,
                ImagePath    = c.ImagePath,
                Price        = c.Price,
                Qty          = c.Qty,
                MeasureUnit  = c.MeasureUnit.Name,
                Vendor       = $"{c.Vendor.FirstName} {c.Vendor.LastName}",
                Id           = c.Id
            })
                        .AsQueryable();

            if (query == null || !query.Any())
            {
                return(new NotFoundResponse());
            }

            var result = await Pagination <ProductVM> .CreateAsync(query, request.PageNumber, request.PageSize);

            var pagedResponse = new PagedResponse <List <ProductVM> >(result, result.PageIndex,
                                                                      result.TotalPages, result.HasPreviousPage, result.HasNextPage);

            return(pagedResponse);
        }
示例#3
0
        public async Task <IActionResult> Index(string sortOrder, string currentSearchString, string SearchString, int BookConditionFilter, int?Page)
        {
            int PageSize      = 14;                                 // How many listed items per page definition
            var seboDbContext = _context.BookCondition;
            var BodyList      = (from p in seboDbContext select p); // Item to be listed on the view

            if (!String.IsNullOrEmpty(sortOrder))
            {
                string[] parameter = sortOrder.Split(".");
                sortOrder           = parameter[0];
                BookConditionFilter = Int32.Parse(parameter[1]);
            }


            if (!String.IsNullOrEmpty(SearchString))
            {
                Page     = 1;
                BodyList = BodyList.Where(p => p.Condition.Contains(SearchString));
            }
            else
            {
                currentSearchString = SearchString;
            }

            // Applying text filters on the table - It impacts in all dropboxes and lists

            //Initializing the queries that belong to the dropboxes
            var _BookConditionFiltered = BodyList;

            // Applying filter over the dropbox query base
            if (BookConditionFilter != 0)
            {
                _BookConditionFiltered = from s in _BookConditionFiltered where (s.BookConditionId == BookConditionFilter) select s;
            }

            /*
             *  Adjusts the BodyList according to the Institution selection
             *  and the BranchName selection
             */
            BodyList = _BookConditionFiltered;

            /* Ordering before list on the view */
            BodyList = sortOrder == "BookCondition_asc" ? BodyList.OrderByDescending(s => s.Condition) : BodyList.OrderBy(s => s.Condition);

            /*
             *  Preparing DROPBOXLISTs
             */
            var _BookCondition = _BookConditionFiltered.ToList();

            ViewData["BookConditionFilter"] = new SelectList(_BookCondition, "BookConditionId", "Condition");
            ViewData["SearchString"]        = SearchString;

            /*
             * Adding actual dropboxes selection because in case of a column ordering (by clicking on the column name)
             * the dropbox filtering values would be lost.
             */
            ViewData["BookConditionOrder"] = (sortOrder == "BookCondition_asc" ? "BookCondition_desc" : "BookCondition_asc") + "." + BookConditionFilter;

            return(View(await Pagination <BookCondition> .CreateAsync(BodyList.AsNoTracking(), Page ?? 1, PageSize)));
        }
示例#4
0
        public async Task <Pagination <Market> > FilterAsync(int pageIndex, int pageSize, string name = null)
        {
            var Markets = this.context.Markets.Where(x =>
                                                     (name == null || x.Name == name)
                                                     );

            return(await Pagination <Market> .CreateAsync(Markets, pageIndex, pageSize));
        }
示例#5
0
        public async Task <Pagination <CompanyMarket> > FilterAsync(int pageIndex, int pageSize, string CompanyName, string MarketName)
        {
            var CompanyMarkets = this.Including.Where(x =>
                                                      (CompanyName == null || x.Company.Name == CompanyName) &&
                                                      (MarketName == null || x.Market.Name == MarketName)
                                                      );

            return(await Pagination <CompanyMarket> .CreateAsync(CompanyMarkets, pageIndex, pageSize));
        }
示例#6
0
        public async Task <Pagination <Company> > FilterAsync(int pageIndex, int pageSize, string name = null, string adress = null)
        {
            var Companies = this.context.Companies.Where(x =>
                                                         (name == null || x.Name == name) &&
                                                         (adress == null || x.Address == adress)
                                                         );

            return(await Pagination <Company> .CreateAsync(Companies, pageIndex, pageSize));
        }
示例#7
0
        public async Task <IActionResult> Index(string sort,
                                                string currentFilter,
                                                string searchFilter,
                                                int?page)
        {
            ViewData["CodeSortparam"] = string.IsNullOrEmpty(sort) ? "code_desc" : "";
            ViewData["NameSortparam"] = sort == "name_asc" ? "name_desc" : "name_asc";

            if (searchFilter != null)
            {
                page = 1;
            }
            else
            {
                searchFilter = currentFilter;
            }


            ViewData["CurrentFilter"] = searchFilter;
            ViewData["CurrentSort"]   = sort;

            var origins = from s in _context.Origins select s;

            if (!string.IsNullOrEmpty(searchFilter))
            {//alt + 124
                origins = origins.Where(s => s.Code.Contains(searchFilter) || s.Name.Contains(searchFilter));
            }

            switch (sort)
            {
            case "code_desc":
                origins = origins.OrderByDescending(s => s.Code);
                break;

            case "name_desc":
                origins = origins.OrderByDescending(s => s.Name);
                break;

            case "name_asc":
                origins = origins.OrderBy(s => s.Name);
                break;

            default:
                origins = origins.OrderBy(s => s.Code);
                break;
            }

            int pageSize = 2;

            return(View(await Pagination <Origin> .CreateAsync(origins.AsNoTracking(), page ?? 1, pageSize)));

            // return View( await origins.AsNoTracking().ToListAsync());
            // return View(await _context.Origins.ToListAsync());
        }
        public async Task <IActionResult> Get(string userTimezoneId)
        {
            TimeZoneInfo getTimeZoneId = TimeZoneInfo.FindSystemTimeZoneById(userTimezoneId);

            var utcTime    = DateTime.UtcNow;
            var serverTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, getTimeZoneId);
            var ip         = this.HttpContext.Connection.RemoteIpAddress.ToString();

            int pageNo   = 1;
            int pageSize = 10;
            //adding page to my data.
            Pagination <CurrentTimeQuery> paginationData;



            var returnVal = new CurrentTimeQuery
            {
                UTCTime  = utcTime,
                ClientIp = ip,
                Time     = serverTime
            };

            using (var db = new ClockworkContext())
            {
                db.CurrentTimeQueries.Add(returnVal);
                var count = db.SaveChanges();
                Console.WriteLine("{0} records saved to database", count);

                Console.WriteLine();
                foreach (var CurrentTimeQuery in db.CurrentTimeQueries)
                {
                    Console.WriteLine(" - {0}", CurrentTimeQuery.UTCTime);
                }

                //default to desc so new entry can be easily see
                var data = db.CurrentTimeQueries.AsNoTracking().OrderByDescending(x => x.CurrentTimeQueryId);
                paginationData = await Pagination <CurrentTimeQuery> .CreateAsync(data, pageNo, pageSize);
            }

            return(Ok(new
            {
                currentData = returnVal
                ,
                displayedData = paginationData
                ,
                pageNumber = 1
                ,
                pageNext = paginationData.HasNextPage
                ,
                pagePrev = paginationData.HasPreviousPage
                ,
                totalPage = paginationData.TotalPages
            }));
        }
    public async Task <Pagination <Employee> > FilterAsync(int pageIndex, int pageSize, string?privateNumber = null, string?firstName = null, string?lastName = null, Gender?gender = null, Language?language = null)
    {
        var employees = this.Including().Where(x =>
                                               (privateNumber == null || x.PrivateNumber == privateNumber) &&
                                               (firstName == null || x.FirstName == firstName) &&
                                               (lastName == null || x.LastName == lastName) &&
                                               (gender == null || x.Gender == gender) &&
                                               (language == null || x.Language.HasFlag(language))
                                               );

        return(await Pagination <Employee> .CreateAsync(employees, pageIndex, pageSize));
    }
        //public async Task<List<ProductVM>> Handle(GetAllProductsQuery request, CancellationToken cancellationToken)
        public async Task <IResponse> Handle(GetAllProductsQuery request, CancellationToken cancellationToken)
        {
            //var skip = (request.PageNumber - 1) * request.PageSize;
            //var take = request.PageSize;

            //var response = await dbContext.Products
            //                .Include(c => c.MeasureUnit)
            //                .Include(c => c.Vendor)
            //                .Skip(skip)
            //                .Take(take)
            //                .Select(c => new ProductVM
            //                {
            //                    Id = c.Id,
            //                    Name = c.Name,
            //                    Description = c.Description,
            //                    Price = c.Price,
            //                    Qty = c.Qty,
            //                    MeasureUnit = c.MeasureUnit.Name,
            //                    Vendor = $"{c.Vendor.FirstName} {c.Vendor.LastName}"
            //                }).ToListAsync();

            //return response;

            var query = dbContext.Products
                        .Include(c => c.MeasureUnit)
                        .Include(c => c.Vendor)
                        .Include(c => c.Category)
                        .Select(c => new ProductVM
            {
                Id           = c.Id,
                Name         = c.Name,
                Description  = c.Description,
                Price        = c.Price,
                Qty          = c.Qty,
                MeasureUnit  = c.MeasureUnit.Name,
                Vendor       = $"{c.Vendor.FirstName} {c.Vendor.LastName}",
                IsFeatured   = c.IsFeatured,
                ImagePath    = c.ImagePath,
                CategoryId   = c.CategoryId,
                CategoryName = c.Category.Name
            }).AsQueryable();


            var result = await Pagination <ProductVM> .CreateAsync(query, request.PageNumber, request.PageSize);

            var pagedResponse = new PagedResponse <List <ProductVM> >(result, result.PageIndex,
                                                                      result.TotalPages, result.HasPreviousPage, result.HasNextPage);

            return(pagedResponse);
        }
示例#11
0
        // GET: Categories
        public async Task <IActionResult> Index(string sortOrder, string searchString, string currentFilter, int?page)
        {
            ViewData["NameSortParams"]        = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewData["DescriptionSortParams"] = sortOrder == "description_asc" ? "description_desc" : "description_asc";
            if (searchString != null)
            {
                page = 1;
            }
            else
            {
                searchString = currentFilter;
            }
            ViewData["CurrentFilter"] = searchString;
            ViewData["CurrentSort"]   = sortOrder;

            var categories = from s in _context.Categories select s;

            if (!String.IsNullOrEmpty(searchString))
            {
                categories = categories.Where(s => s.Name.Contains(searchString) || s.Description.Contains(searchString));
            }

            switch (sortOrder)
            {
            case "name_desc":
                categories = categories.OrderByDescending(s => s.Name);
                break;

            case "description_desc":
                categories = categories.OrderByDescending(s => s.Description);
                break;

            case "description_asc":
                categories = categories.OrderBy(s => s.Description);
                break;

            default:
                categories = categories.OrderBy(s => s.Name);
                break;
            }
            int pageSize = 3;

            return(View(await Pagination <Categories> .CreateAsync(categories.AsNoTracking(), page ?? 1, pageSize)));
            //return View(await categories.AsNoTracking().ToListAsync());
            //return View(await _context.Categories.ToListAsync());
        }
示例#12
0
        public async Task <IActionResult> GetPageNo(int pageNo)
        {
            var db = new ClockworkContext();
            Pagination <CurrentTimeQuery> paginationData;
            int pageSize = 10;
            var data     = db.CurrentTimeQueries.AsNoTracking().OrderByDescending(x => x.CurrentTimeQueryId);

            paginationData = await Pagination <CurrentTimeQuery> .CreateAsync(data, pageNo, pageSize);

            return(Ok(new
            {
                displayedData = paginationData
                ,
                pageNumber = pageNo
                ,
                pageNext = paginationData.HasNextPage
                ,
                pagePrev = paginationData.HasPreviousPage
                ,
                totalPage = paginationData.TotalPages
            }));
        }
示例#13
0
        public async Task <Pagination <Project> > ProjectsIndexCall(string searchString, string categorySelection, int?page)
        {
            var crowdfundingContext = _context.Project.Include(p => p.Category).Include(p => p.User);
            var pageSize            = 4;

            if (!String.IsNullOrEmpty(searchString))
            {
                page = 1;
                return(await Pagination <Project> .CreateAsync(crowdfundingContext.Where(s => s.ProjectName.ToUpper().Contains(searchString.ToUpper())).AsNoTracking(), page ?? 1, pageSize));
            }
            else if (!String.IsNullOrEmpty(categorySelection))
            {
                bool isCategoryNameInt = int.TryParse(categorySelection, out int categorySelectionInt);
                if (isCategoryNameInt && categorySelectionInt != 0)
                {
                    return(await Pagination <Project> .CreateAsync(crowdfundingContext.Where(s => s.CategoryId == categorySelectionInt).AsNoTracking(), page ?? 1, pageSize));
                }
                else
                {
                    return(await Pagination <Project> .CreateAsync(crowdfundingContext.AsNoTracking(), page ?? 1, pageSize));
                }
            }
            return(await Pagination <Project> .CreateAsync(crowdfundingContext.AsNoTracking(), page ?? 1, pageSize));
        }
示例#14
0
        public async Task <Pagination <MemberDTO> > GetMembersAsync(UserParams userParams)
        {
            var query = _context.Users.AsQueryable();

            query = query.Where(u => u.UserName != userParams.CurrentUsername);
            query = query.Where(u => u.Gender == userParams.Gender);

            var minDateOfBirth = DateTime.Today.AddYears(-userParams.MaxAge - 1);
            var maxDateOfBirth = DateTime.Today.AddYears(-userParams.MinAge);

            query = query.Where(u => u.DateOfBirth >= minDateOfBirth && u.DateOfBirth <= maxDateOfBirth);

            query = userParams.OrderBy switch
            {
                "created" => query.OrderByDescending(u => u.Created),
                _ => query.OrderByDescending(u => u.LastActive)
            };

            return(await Pagination <MemberDTO> .CreateAsync(
                       query.ProjectTo <MemberDTO>(_mapper.ConfigurationProvider).AsNoTracking(),
                       userParams.PageNumber,
                       userParams.PageSize
                       ));
        }
示例#15
0
        public async Task <IActionResult> Index(string sortOrder, string currentSearchString, string SearchString, int ProvinceFilter, int PlaceNameFilter, int?Page)
        {
            int PageSize      = 14;                                 // How many listed items per page definition
            var seboDbContext = _context.Localization;
            var BodyList      = (from p in seboDbContext select p); // Item to be listed on the view

            if (!String.IsNullOrEmpty(sortOrder))
            {
                string[] parameter = sortOrder.Split(".");
                sortOrder       = parameter[0];
                ProvinceFilter  = Int32.Parse(parameter[1]);
                PlaceNameFilter = Int32.Parse(parameter[2]);
            }


            if (!String.IsNullOrEmpty(SearchString))
            {
                Page     = 1;
                BodyList = BodyList.Where(p => p.PostalCode.Contains(SearchString) || p.Province.Contains(SearchString) ||
                                          p.PlaceName.Contains(SearchString));
            }
            else
            {
                currentSearchString = SearchString;
            }

            // Applying text filters on the table - It impacts in all dropboxes and lists

            //Initializing the queries that belong to the dropboxes
            var _PlaceNamesFiltered = BodyList;
            var _ProvincesFiltered  = BodyList;

            // Applying filter over the dropbox query base
            if (ProvinceFilter != 0)
            {
                _PlaceNamesFiltered = from p1 in _PlaceNamesFiltered join p2 in _PlaceNamesFiltered on p1.Province equals p2.Province
                                      where (p1.LocalizationId == ProvinceFilter) select p2;
            }

            /*
             *  Adjusts the BodyList according to the Province selection
             *  and the PlaceName selection
             */
            BodyList = _PlaceNamesFiltered;
            if (PlaceNameFilter != 0)
            {
                BodyList = _PlaceNamesFiltered.Where(p => p.LocalizationId == PlaceNameFilter).Distinct();
            }
            if (BodyList.Count() < 1)
            {
                BodyList = _PlaceNamesFiltered;                       // In case no match for Province+PlaceName
            }
            //_PlaceNamesFiltered = OrderingPostalCodes.Do(_PlaceNamesFiltered, sortOrder);
            /* Ordering before list on the view */
            BodyList = OrderingPostalCodes.Do(BodyList, sortOrder);

            /*
             *  Preparing DROPBOXLISTs
             */
            var _Provinces  = (from p in _ProvincesFiltered group p by p.Province into pp select pp.First()).ToList();
            var _PlaceNames = (from p in _PlaceNamesFiltered orderby p.PlaceName select new { p.LocalizationId, p.PlaceName }).ToList().Distinct();

            ViewData["ProvinceFilter"]  = new SelectList(_Provinces, "LocalizationId", "Province");
            ViewData["PlaceNameFilter"] = new SelectList(_PlaceNames, "LocalizationId", "PlaceName");
            /* END of (Preparing DROPBOXLISTs) */

            ViewData["SearchString"] = SearchString;

            /*
             * Adding actual dropboxes selection because in case of a column ordering (by clicking on the column name)
             * the dropbox filtering values would be lost.
             */
            ViewData["ProvinceOrder"]   = OrderingPostalCodes.NewOrder(sortOrder, "Province") + "." + ProvinceFilter + "." + PlaceNameFilter;
            ViewData["PlaceNameOrder"]  = OrderingPostalCodes.NewOrder(sortOrder, "PlaceName") + "." + ProvinceFilter + "." + PlaceNameFilter;
            ViewData["PostalCodeOrder"] = OrderingPostalCodes.NewOrder(sortOrder, "PostalCode") + "." + ProvinceFilter + "." + PlaceNameFilter;

            return(View(await Pagination <Localization> .CreateAsync(BodyList.AsNoTracking(), Page ?? 1, PageSize)));
        }
    public async Task <Pagination <Employee> > SearchAsync(int pageIndex, int pageSize, string text)
    {
        var employees = this.Including().Where(x => x.PrivateNumber == text || x.FirstName == text || x.LastName == text);

        return(await Pagination <Employee> .CreateAsync(employees, pageIndex, pageSize));
    }
示例#17
0
        // GET: Courses
        public async Task <IActionResult> Index(string sortOrder, string currentSearchString, string SearchString, int StudyAreaFilter, int InstitutionFilter, int?Page)
        {
            var seboDbContext = _context.Course.Include(c => c.Institution).Include(c => c.StudyArea);
            var courses       = (from s in seboDbContext select s);

            if (currentSearchString != null)
            {
                string[] m = currentSearchString.Split(".");

                currentSearchString = m[0]; // preserves the current filter typed within the search textbox


                if (SearchString == null)
                {
                    SearchString = currentSearchString;
                }
                if (StudyAreaFilter == 0)
                {
                    InstitutionFilter = Int32.Parse(m[1]);   // preserves the select institution option in the dropdownlist
                }
                if (InstitutionFilter == 0)
                {
                    StudyAreaFilter = Int32.Parse(m[2]);     // preserves the select Study Area option in the dropdownlist
                }
            }


            // Applying filters on the table
            //if (!String.IsNullOrEmpty(SearchString)) courses = courses.Where(c => c.CourseName.Contains(SearchString));
            if (!String.IsNullOrEmpty(SearchString))
            {
                var myString = SearchString.Trim().Split(" ");
                //courses = courses.Where(c => myString.All(m => c.CourseName.ToLower().Contains(m.ToLower())));
                courses = StringSearch.SearchCourseName(_context, myString).Include(c => c.Institution).Include(c => c.StudyArea);
            }
            if (InstitutionFilter != 0)
            {
                courses = courses.Where(c => c.InstitutionId == InstitutionFilter);
            }
            if (StudyAreaFilter != 0)
            {
                courses = courses.Where(c => c.StudyAreaId == StudyAreaFilter);
            }


            courses = OrderingCourses.Do(courses, sortOrder);
            //////////////////////////////////////
            //Preparing Dropboxes
            //////////////////////////////////////
            var StudyAreas   = (from s in courses orderby s.StudyArea.StudyAreaName select new { s.StudyAreaId, s.StudyArea.StudyAreaName }).ToList().Distinct();
            var Institutions = (from i in courses orderby i.Institution.InstitutionName select new { i.InstitutionId, i.Institution.InstitutionName }).ToList().Distinct();

            ViewData["StudyAreaFilter"]   = new SelectList(StudyAreas, "StudyAreaId", "StudyAreaName");
            ViewData["InstitutionFilter"] = new SelectList(Institutions, "InstitutionId", "InstitutionName");
            //////////////////////////////////////

            ViewData["CurrentSearchString"] = SearchString + "." + InstitutionFilter + "." + StudyAreaFilter + "." + Page;
            ViewData["SearchString"]        = SearchString;
            ViewData["Institution"]         = OrderingCourses.NewOrder(sortOrder, "Institution");
            ViewData["StudyArea"]           = OrderingCourses.NewOrder(sortOrder, "StudyArea");
            ViewData["CourseName"]          = OrderingCourses.NewOrder(sortOrder, "CourseName");

            //return View(await courses.ToListAsync());
            int PageSize = 14;

            return(View(await Pagination <Course> .CreateAsync(courses.AsNoTracking(), Page ?? 1, PageSize)));
        }
 public async Task PaginateItems(IQueryable <Item> items)
 {
     Items = await Pagination <Item> .CreateAsync(items, PageNumber, PageSize);
 }
示例#19
0
        // GET: Devices
        public async Task <IActionResult> Index(string sortBy, string currentFilter, string searchString, int?pageNumber)
        {
            //The three sort methods: by name, by type, or by user.
            ViewData["NameSort"] = string.IsNullOrEmpty(sortBy) ? "name_desc" : "";
            ViewData["TypeSort"] = sortBy == "Type" ? "type_desc" : "Type";
            ViewData["UserSort"] = sortBy == "Username" ? "user_desc" : "Username";

            //Go back to the first page if we're searching; save the search either way
            if (searchString != null)
            {
                pageNumber = 1;
            }
            else
            {
                currentFilter = searchString;
            }
            ViewData["CurrentFilter"] = searchString;

            IEnumerable <Device> devices;

            if (!string.IsNullOrEmpty(searchString))
            {
                //Since we have a search string, use it!
                devices = await _context.Devices
                          .Include(x => x.DeviceType)
                          .Include(x => x.Images)
                          .Include(x => x.AddedBy)
                          .Where(x => x.DeviceName.Contains(searchString))
                          .ToListAsync();
            }
            else
            {
                //Otherwise, display everything just as it comes out of the database
                devices = await _context.Devices
                          .Include(x => x.DeviceType)
                          .Include(x => x.Images)
                          .Include(x => x.AddedBy)
                          .ToListAsync();
            }

            //Surely there's a better way to do this than a switch
            switch (sortBy)
            {
            case "name_desc":
                devices = devices.OrderByDescending(x => x.DeviceName);
                break;

            case "Type":
                devices = devices.OrderBy(x => x.DeviceType.TypeName);
                break;

            case "type_desc":
                devices = devices.OrderByDescending(x => x.DeviceType.TypeName);
                break;

            case "User":
                devices = devices.OrderByDescending(x => x.AddedBy.UserName);
                break;

            case "user_desc":
                devices = devices.OrderByDescending(x => x.AddedBy.UserName);
                break;

            default:
                devices = devices.OrderBy(x => x.DeviceName);
                break;
            }

            //Currently, pages are hard-set to 5. This would make a lovely setting somewhere.
            int pageSize = 5;

            return(View(Pagination <Device> .CreateAsync(devices, pageNumber ?? 1, pageSize)));
        }
示例#20
0
        public async Task <IActionResult> Index(string UserName, string sortOrder, string currentSearchString, string SearchString, int StudyAreaFilter, int BookConditionFilter, int?Page)
        {
            if (currentSearchString != null)
            {
                string[] m = currentSearchString.Split(".");
                currentSearchString = m[0]; // preserves the current filter typed within the search textbox
                if (SearchString == null)
                {
                    SearchString = currentSearchString;
                }
                if (StudyAreaFilter == 0)
                {
                    StudyAreaFilter = Int32.Parse(m[1]);   // preserves the select institution option in the dropdownlist
                }
                if (BookConditionFilter == 0)
                {
                    BookConditionFilter = Int32.Parse(m[2]);     // preserves the select Study Area option in the dropdownlist
                }
            }
            //Get the User ID
            if (String.IsNullOrEmpty(UserName))
            {
                UserName = this.User.Identity.Name;
            }
            int UserId = HelperUser.GetUserId(UserName, _context);

            // Cheks whether a search string was typed and prepares for search by each word
            string[] myString = SearchString != null?SearchString.Trim().Split(" ") : new string[0];

            var x = HelperUser.isAdministrator(UserName);
            // Get the seach's recordset already sorted applying filtering according to user role
            var books = StringSearch.SearchBook(_context, sortOrder, myString).Include(b => b.BookCondition).Include(b => b.StudyArea).Include(b => b.User)
                        .Where(b => !b.Blocked)
                        .Where(b => b.Quantity > b.QuantitySold)
                        .Where(b => !b.IsWaitList)
                        .Where(b => HelperUser.isAdministrator(UserName) ? b.UserId > 0 : b.UserId == UserId);

            //.Where(b => UserId > 0 || UserName != null ? b.UserId == UserId : b.UserId > 0)

            // Applying filters on the table
            if (StudyAreaFilter != 0)
            {
                books = books.Where(b => b.StudyAreaId == StudyAreaFilter);
            }
            if (BookConditionFilter != 0)
            {
                books = books.Where(b => b.BookConditionId == BookConditionFilter);
            }

            //
            // Preparing Dropboxes
            //
            var StudyAreas     = (from s in books orderby s.StudyArea.StudyAreaName select new { s.StudyAreaId, s.StudyArea.StudyAreaName }).ToList().Distinct();
            var BookConditions = (from b in books orderby b.BookCondition select new { b.BookConditionId, b.BookCondition.Condition }).ToList().Distinct();

            ViewData["StudyAreaFilter"]     = new SelectList(StudyAreas, "StudyAreaId", "StudyAreaName");
            ViewData["BookConditionFilter"] = new SelectList(BookConditions, "BookConditionId", "Condition");
            //////////////////////////////////////

            ViewData["CurrentSearchString"] = SearchString + "." + StudyAreaFilter + "." + BookConditionFilter + "." + Page;
            ViewData["SearchString"]        = SearchString;

            //
            // Just tracking which ordering column was trigged for setting the actual ordering
            //
            ViewData["Title"]         = OrderingBooks.NewOrder(sortOrder, "Title");
            ViewData["StudyArea"]     = OrderingBooks.NewOrder(sortOrder, "StudyArea");
            ViewData["BookCondition"] = OrderingBooks.NewOrder(sortOrder, "BookCondition");
            ViewData["ISBN"]          = OrderingBooks.NewOrder(sortOrder, "ISBN");
            ViewData["Price"]         = OrderingBooks.NewOrder(sortOrder, "Price");

            int PageSize = 14;

            return(View(await Pagination <Book> .CreateAsync(books.AsNoTracking(), Page ?? 1, PageSize)));
        }
示例#21
0
        // GET: Books
        public async Task <IActionResult> BooksCatalog(string UserName, string sortOrder, string currentSearchString, string SearchString, int StudyAreaFilter, int BookConditionFilter, int?Page)
        {
            if (currentSearchString != null)
            {
                string[] m = currentSearchString.Split(".");
                currentSearchString = m[0]; // preserves the current filter typed within the search textbox
                if (SearchString == null)
                {
                    SearchString = currentSearchString;
                }
                if (StudyAreaFilter == 0)
                {
                    StudyAreaFilter = Int32.Parse(m[1]);   // preserves the select institution option in the dropdownlist
                }
                if (BookConditionFilter == 0)
                {
                    BookConditionFilter = Int32.Parse(m[2]);     // preserves the select Study Area option in the dropdownlist
                }
            }
            //Get the User ID
            int UserId       = HelperUser.GetUserId(this.User.Identity.Name, _context);
            int UserBranchId = HelperUser.GetUserBranchId(this.User.Identity.Name, _context);

            // Cheks whether a search string was typed and prepares for search by each word
            string[] myString = SearchString != null?SearchString.Trim().Split(" ") : new string[0];

            // Get the seach's recordset already sorted
            var books = StringSearch.SearchBook(_context, sortOrder, myString).Include(b => b.BookCondition).Include(b => b.StudyArea).Include(b => b.User)
                        .Where(b => !b.Blocked)
                        .Where(b => b.Quantity > b.QuantitySold)
                        .Where(b => b.UserId != UserId)
                        .Where(b => !b.IsWaitList);

            var users = (from u in _context.User select u).Include(u => u.InstitutionBranch);
            //Getting the books from the same institution
            var books2 = (from b in books
                          join u in users on b.UserId equals u.UserId
                          select new
            {
                b.Blocked,
                b.BookCondition,
                b.BookConditionId,
                b.BookId,
                b.CreationDate,
                b.Description,
                b.Edition,
                b.ISBN,
                b.IsWaitList,
                b.Orders,
                b.PhotoFileName,
                b.Price,
                b.Publisher,
                b.Quantity,
                b.QuantitySold,
                b.StudyArea,
                b.StudyAreaId,
                b.Title,
                b.User,
                b.UserId,
                b.Visualizations,
                u.InstitutionBranchId,
                u.InstitutionBranch.InstitutionBranchName
            }).Where(b => b.InstitutionBranchId == UserBranchId);

            // Applying filters on the table
            if (StudyAreaFilter != 0)
            {
                books2 = books2.Where(b => b.StudyAreaId == StudyAreaFilter);
            }
            if (BookConditionFilter != 0)
            {
                books2 = books2.Where(b => b.BookConditionId == BookConditionFilter);
            }

            //
            // Preparing Dropboxes
            //
            var StudyAreas     = (from s in books2 orderby s.StudyArea.StudyAreaName select new { s.StudyAreaId, s.StudyArea.StudyAreaName }).ToList().Distinct();
            var BookConditions = (from b in books2 orderby b.BookCondition select new { b.BookConditionId, b.BookCondition.Condition }).ToList().Distinct();

            ViewData["StudyAreaFilter"]     = new SelectList(StudyAreas, "StudyAreaId", "StudyAreaName");
            ViewData["BookConditionFilter"] = new SelectList(BookConditions, "BookConditionId", "Condition");
            //////////////////////////////////////

            ViewData["CurrentSearchString"] = SearchString + "." + StudyAreaFilter + "." + BookConditionFilter + "." + Page;
            ViewData["SearchString"]        = SearchString;

            //
            // Just tracking which ordering column was trigged for setting the actual ordering
            //
            ViewData["Title"]         = OrderingBooks.NewOrder(sortOrder, "Title");
            ViewData["StudyArea"]     = OrderingBooks.NewOrder(sortOrder, "StudyArea");
            ViewData["BookCondition"] = OrderingBooks.NewOrder(sortOrder, "BookCondition");
            ViewData["ISBN"]          = OrderingBooks.NewOrder(sortOrder, "ISBN");
            ViewData["Price"]         = OrderingBooks.NewOrder(sortOrder, "Price");

            int PageSize = 14;

            return(View(await Pagination <Book> .CreateAsync(books.AsNoTracking(), Page ?? 1, PageSize)));
        }
示例#22
0
        public async Task <Pagination <Company> > SearchAsync(int pageIndex, int pageSize, string text)
        {
            var Companies = this.context.Companies.Where(x => x.Name == text || x.Address == text);

            return(await Pagination <Company> .CreateAsync(Companies, pageIndex, pageSize));
        }
        public async Task <IActionResult> Index(string sortOrder, string currentSearchString, string SearchString, int InstitutionFilter, int BranchNameFilter, int?Page)
        {
            int PageSize      = 14;                                 // How many listed items per page definition
            var seboDbContext = _context.InstitutionBranch.Include(c => c.Institution);
            var BodyList      = (from p in seboDbContext select p); // Item to be listed on the view

            if (!String.IsNullOrEmpty(sortOrder))
            {
                string[] parameter = sortOrder.Split(".");
                sortOrder         = parameter[0];
                InstitutionFilter = Int32.Parse(parameter[1]);
                BranchNameFilter  = Int32.Parse(parameter[2]);
            }


            if (!String.IsNullOrEmpty(SearchString))
            {
                Page     = 1;
                BodyList = BodyList.Where(p => p.Institution.InstitutionName.Contains(SearchString) || p.InstitutionBranchName.Contains(SearchString));
            }
            else
            {
                currentSearchString = SearchString;
            }

            // Applying text filters on the table - It impacts in all dropboxes and lists

            //Initializing the queries that belong to the dropboxes
            var _InstitutionsFiltered = (from i in _context.Institution select i).OrderBy(i => i.InstitutionName);
            var _BranchNamesFiltered  = BodyList;

            // Applying filter over the dropbox query base
            if (InstitutionFilter != 0)
            {
                _BranchNamesFiltered = from p in _BranchNamesFiltered where (p.InstitutionId == InstitutionFilter) select p;
            }

            /*
             *  Adjusts the BodyList according to the Institution selection
             *  and the BranchName selection
             */
            BodyList = _BranchNamesFiltered;
            if (BranchNameFilter != 0)
            {
                BodyList = _BranchNamesFiltered.Where(p => p.InstitutionBranchId == BranchNameFilter).Distinct();
            }
            if (BodyList.Count() < 1)
            {
                BodyList = _BranchNamesFiltered;                       // In case no match for Institution+BranchName
            }
            //_BranchNamesFiltered = OrderingPostalCodes.Do(_BranchNamesFiltered, sortOrder);
            /* Ordering before list on the view */
            BodyList = OrderingInstitutionBranches.Do(BodyList, sortOrder);

            /*
             *  Preparing DROPBOXLISTs
             */
            var _Institutions = _InstitutionsFiltered.ToList();
            var _BranchNames  = (from p in _BranchNamesFiltered orderby p.InstitutionBranchName
                                 select new { p.InstitutionBranchId, p.InstitutionBranchName }).ToList().Distinct();

            ViewData["InstitutionFilter"] = new SelectList(_Institutions, "InstitutionId", "InstitutionName");
            ViewData["BranchNameFilter"]  = new SelectList(_BranchNames, "InstitutionBranchId", "InstitutionBranchName");
            /* END of (Preparing DROPBOXLISTs) */

            ViewData["SearchString"] = SearchString;

            /*
             * Adding actual dropboxes selection because in case of a column ordering (by clicking on the column name)
             * the dropbox filtering values would be lost.
             */
            ViewData["InstitutionOrder"] = OrderingInstitutionBranches.NewOrder(sortOrder, "Institution") + "." + InstitutionFilter + "." + BranchNameFilter;
            ViewData["BranchNameOrder"]  = OrderingInstitutionBranches.NewOrder(sortOrder, "BranchName") + "." + InstitutionFilter + "." + BranchNameFilter;

            return(View(await Pagination <InstitutionBranch> .CreateAsync(BodyList.AsNoTracking(), Page ?? 1, PageSize)));
        }