Beispiel #1
0
        public IActionResult OnGet(string userId = null)
        {
            Place = new Place();
            if (userId == null)
            {
                var claimsIdentity = (ClaimsIdentity)User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                userId = claim.Value;
            }
            Place.UserId = userId;

            PlacesAndUserVM = new PlacesAndUserViewModel();


            IQueryable <TravelType> lstTravelType = from s in _db.TravelType select s;

            PlacesAndUserVM.TravelTypesList = lstTravelType.ToList();

            return(Page());
        }
Beispiel #2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Place = await _context.Place
                    .Include(p => p.ApplicationUser).Include(p => p.TravelType).FirstOrDefaultAsync(m => m.Id == id);

            PlacesAndUserVM = new PlacesAndUserViewModel();


            IQueryable <TravelType> lstTravelType = from s in _context.TravelType select s;

            PlacesAndUserVM.TravelTypesList = lstTravelType.ToList();

            if (Place == null)
            {
                return(NotFound());
            }
            ViewData["UserId"] = new SelectList(_context.ApplicationUser, "Id", "Id");
            return(Page());
        }
Beispiel #3
0
        public async Task <IActionResult> OnGet(int productPage = 1, string userId = null, string searchCountry = null, string searchLocality = null, string searchType = null)
        {
            if (userId == null)
            {
                var claimsIdentity = (ClaimsIdentity)User.Identity;
                var claim          = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier);
                userId = claim.Value;
            }

            PlacesAndUserVM = new PlacesAndUserViewModel()
            {
                Place           = await _db.Place.Where(t => t.UserId == userId).ToListAsync(),
                UserObj         = await _db.ApplicationUser.FirstOrDefaultAsync(u => u.Id == userId),
                TravelTypesList = await _db.TravelType.ToListAsync(),
                PlacesList      = await _db.Place.Where(t => t.Active == "YES").ToListAsync()
            };

            StringBuilder parm = new StringBuilder();

            parm.Append("/Places?productPage=:");
            parm.Append("&userId=");
            if (userId != null)
            {
                parm.Append(userId);
            }
            parm.Append("&searchCountry");
            if (searchCountry != null)
            {
                parm.Append(searchCountry);
            }
            parm.Append("&searchLocality");
            if (searchCountry != null)
            {
                parm.Append(searchLocality);
            }
            parm.Append("&searchType");
            if (searchCountry != null)
            {
                parm.Append(searchType);
            }

            if (searchCountry != null)
            {
                PlacesAndUserVM.PlacesList = await _db.Place.Where(u => u.Country.ToLower().Contains(searchCountry.ToLower())).ToListAsync();
            }
            else
            {
                if (searchLocality != null)
                {
                    PlacesAndUserVM.PlacesList = await _db.Place.Where(u => u.Locality.ToLower().Contains(searchLocality.ToLower())).ToListAsync();
                }
                else
                {
                    if (searchType != null)
                    {
                        PlacesAndUserVM.PlacesList = await _db.Place.Where(u => u.TravelType.Name.ToLower().Contains(searchType.ToLower())).ToListAsync();
                    }
                }
            }

            var count = PlacesAndUserVM.PlacesList.Count;

            PlacesAndUserVM.PagingInfo = new PagingInfo
            {
                CurrentPage  = productPage,
                ItemsPerPage = SD.PaginationUsersPageSize,
                TotalItems   = count,
                UrlParm      = parm.ToString()
            };

            PlacesAndUserVM.PlacesList = PlacesAndUserVM.PlacesList.OrderBy(p => p.Country)
                                         .Skip((productPage - 1) * SD.PaginationUsersPageSize)
                                         .Take(SD.PaginationUsersPageSize).ToList();

            return(Page());
        }