Ejemplo n.º 1
0
        public IActionResult All(int page, int showBy, string orderBy)
        {
            if (page <= 0)
            {
                return(Redirect("/Home/Index"));
            }

            int usersCount = userService.GetCount();

            if (showBy <= 0)
            {
                return(Redirect("/Home/Index"));
            }

            var lastPage = usersCount / showBy + 1;

            if (usersCount % showBy == 0 && lastPage > 1)
            {
                lastPage--;
            }

            if (page > lastPage)
            {
                return(Redirect("/Home/Index"));
            }

            var users = userService.GetAll(page, showBy, orderBy);

            var viewModel = new ListingPageViewModel
            {
                CurrentPage     = page,
                TotalUsersCount = usersCount,
                UsersPerPage    = showBy,
                LastPage        = lastPage,
                OrderParam      = "orderBy=" + orderBy,
                Users           = new List <ListingViewModel>()
            };

            foreach (var user in users)
            {
                viewModel.Users.Add(new ListingViewModel()
                {
                    Username    = user.UserName,
                    Address     = user.Address,
                    EGN         = user.EGN,
                    Email       = user.Email,
                    FirstName   = user.FirstName,
                    Id          = user.Id,
                    LastName    = user.LastName,
                    PhoneNumber = user.PhoneNumber
                });
            }

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public IActionResult All(int page)
        {
            if (page <= 0)
            {
                return(Redirect("/Home/Index"));
            }

            int reservationsCount = reservationService.Count();

            var lastPage = reservationsCount / 8 + 1;       // 8 reservations per page

            if (reservationsCount % 8 == 0 && lastPage > 1) // 8 reservations per page
            {
                lastPage--;
            }

            if (page > lastPage)
            {
                return(Redirect("/Home/Index"));
            }

            var reservations = reservationService.GetAll(page);

            var viewModel = new ListingPageViewModel
            {
                CurrentPage            = page,
                TotalReservationsCount = reservationsCount,
                LastPage     = lastPage,
                Reservations = new List <ReservationViewModel>()
            };

            foreach (var reservation in reservations)
            {
                viewModel.Reservations.Add(new ReservationViewModel()
                {
                    FirstName    = reservation.FirstName,
                    SecondName   = reservation.SecondName,
                    LastName     = reservation.LastName,
                    SSN          = reservation.SSN,
                    Email        = reservation.Email,
                    Id           = reservation.Id,
                    Confirmed    = reservation.Confirmed,
                    Nationality  = reservation.Nationality,
                    PhoneNumber  = reservation.PhoneNumber,
                    TicketType   = reservation.TicketType.ToString(),
                    TicketsCount = reservation.TicketsCount
                });
            }

            return(View(viewModel));
        }
Ejemplo n.º 3
0
        public IActionResult All(int page)
        {
            if (page <= 0)
            {
                return(Redirect("/Home/Index"));
            }

            int reservationsCount = trainService.GetCount();

            var lastPage = reservationsCount / GlobalConstants.TrainsPerPage + 1;

            if (reservationsCount % GlobalConstants.TrainsPerPage == 0 && lastPage > 1)
            {
                lastPage--;
            }

            if (page > lastPage)
            {
                return(Redirect("/Home/Index"));
            }

            var trains = trainService.GetAll(page);

            var viewModel = new ListingPageViewModel
            {
                CurrentPage      = page,
                TotalTrainsCount = trains.Count,
                LastPage         = lastPage,
                Trains           = new List <TrainViewModel>()
            };

            foreach (var train in trains)
            {
                viewModel.Trains.Add(new TrainViewModel()
                {
                    Id       = train.Id,
                    Name     = train.Name,
                    Capacity = train.Capacity,
                    Fast     = train.Fast
                });
            }

            return(View(viewModel));
        }
        private async Task <ListingPageViewModel> GetCategoriesAndSubCategoriesAsync(ListingPageViewModel result)
        {
            var categories = categoryService.GetAll();

            foreach (var category in categories)
            {
                var subCategories = await subCategoryService
                                    .GetAllByCategoryId(category.Id)
                                    .OrderBy(s => s.Name)
                                    .Select(s => new SubCategoryViewModel
                {
                    Name = s.Name,
                    Id   = s.Id
                })
                                    .ToListAsync();

                result.CategoiesAndSubCategories.CategoriesWithSubCategories
                .Add(new CategoryViewModel {
                    Name = category.Name, Id = category.Id, CssIconClass = category.CssIconClass
                }, subCategories);
            }

            return(result);
        }
Ejemplo n.º 5
0
        public ListingPage()
        {
            InitializeComponent();

            BindingContext = new ListingPageViewModel();
        }
        public async Task <IActionResult> GetBySearch(string search, string orderBy = "dateDesc", int page = 1)
        {
            if (page <= 0)
            {
                return(Redirect("/Home/Index"));
            }

            var adsCount = await advertisementService.GetCountBySearchAsync(search);

            var lastPage = adsCount / GlobalConstants.AdsOnPageCount + 1;

            if (adsCount % GlobalConstants.AdsOnPageCount == 0 && adsCount > 0)
            {
                lastPage -= 1;
            }

            if (page > lastPage)
            {
                return(Redirect("/Home/Index"));
            }

            var ads = await advertisementService.GetBySearchAsync(search, page, GlobalConstants.AdsOnPageCount, orderBy);

            ads = OrderAds(ads, orderBy);

            var result = new ListingPageViewModel();

            result = await GetCategoriesAndSubCategoriesAsync(result);

            foreach (var ad in ads)
            {
                var category = await categoryService.GetByIdAsync(ad.CategoryId);

                string subCategoryName = null;

                if (await subCategoryService.ContainsByIdAsync(ad.SubCategoryId))
                {
                    var subCategory = await subCategoryService.GetByIdAsync(ad.SubCategoryId);

                    subCategoryName = subCategory.Name;
                }

                var town = await townService.GetByIdAsync(ad.TownId);

                var adViewModel = new ListingViewModel
                {
                    Address         = ad.Address,
                    CategoryName    = category.Name,
                    CreatedOn       = ad.CreatedOn.ToString(GlobalConstants.DateTimeFormat),
                    Id              = ad.Id,
                    Name            = ad.Name,
                    Price           = ad.Price,
                    SubCategoryName = subCategoryName,
                    TownName        = town.Name,
                    Image           = ad.Images.FirstOrDefault(),
                    IsPromoted      = ad.IsPromoted,
                };

                result.Advertisements.Add(adViewModel);
            }

            result.CurrentPage   = page;
            result.LastPage      = lastPage;
            result.TotalAdsCount = adsCount;
            result.OrderParam    = "orderBy=" + orderBy;
            result.GetByParam    = "GetBySearch";
            result.PageParam     = "search=" + search;

            return(View("Listing", result));
        }