public async Task <IActionResult> AllByAuthor(int id = 1) { if (id <= 0) { return(this.NotFound()); } const int itemsPerPage = 10; var userId = this.userManager.GetUserId(this.User); var adverts = await this.sharedTravelsService.GetAllByAuthorId <SharedTravelsViewModel>(userId, id, itemsPerPage); if (adverts == null) { return(this.NoContent()); } var viewModel = new AdvertsListViewModel { Controller = "SearchAdverts", Action = "SearchForUserAdvertsDestination", IsUserAdverts = true, ItemsPerPage = itemsPerPage, PageNumber = id, AdvertsCount = await this.sharedTravelsService.GetAdvertsCountByUser(userId), Adverts = adverts, }; return(this.View(viewModel)); }
public async Task <IActionResult> All(int id = 1) { if (id <= 0) { return(this.NotFound()); } var adverts = await this.sharedTravelsService.GetAllApprovedAsync <SharedTravelsViewModel>(id, ControllersConstants.ItemsPerPage); if (adverts == null) { return(this.NoContent()); } var viewModel = new AdvertsListViewModel { Controller = "SearchAdverts", Action = "SearchByDestinations", IsUserAdverts = false, ItemsPerPage = ControllersConstants.ItemsPerPage, PageNumber = id, AdvertsCount = await this.sharedTravelsService.GetAllApprovedAdvertsCount(), Adverts = adverts, }; return(this.View(viewModel)); }
public async Task <IActionResult> SearchByDestinations(string search, int id = 1) { if (search == null) { return(this.RedirectToAction("All", "SharedTravels")); } this.ViewData["Getadvertsdetails"] = search; var adverts = await this.sharedTravelsService .GetByDestinationAsync <SharedTravelsViewModel>(search, id, ControllersConstants.ItemsPerPage); if (adverts == null) { return(this.NoContent()); } var viewModel = new AdvertsListViewModel { Controller = "SearchAdverts", Action = "SearchByDestinations", IsUserAdverts = false, ItemsPerPage = ControllersConstants.ItemsPerPage, PageNumber = id, AdvertsCount = await this.sharedTravelsService.GetSearchedAdvertsCount(search), Adverts = adverts, }; return(this.View("../SharedTravels/All", viewModel)); }
public async Task <IActionResult> SearchForUserAdvertsDestination(string search, int id = 1) { if (search == null) { return(this.RedirectToAction("AllByAuthor", "SharedTravels")); } this.ViewData["Getadvertsdetails"] = search; var userId = this.userManager.GetUserId(this.User); var adverts = await this.sharedTravelsService .GetUserAdvertByDestination <SharedTravelsViewModel>(search, userId, id, ControllersConstants.ItemsPerPage); if (adverts == null) { return(this.NoContent()); } var viewModel = new AdvertsListViewModel { Controller = "SearchAdverts", Action = "SearchForUserAdvertsDestination", IsUserAdverts = true, ItemsPerPage = ControllersConstants.ItemsPerPage, PageNumber = id, AdvertsCount = await this.sharedTravelsService.GetSearchedUserAdvertsCount(search, userId), Adverts = adverts, }; return(this.View("../SharedTravels/AllByAuthor", viewModel)); }
public async Task <IActionResult> Index(int id = 1) { var adverts = await this.sharedTravelsService.GetAllAsync <SharedTravelsViewModel>(id); if (adverts == null) { return(this.NoContent()); } var viewModel = new AdvertsListViewModel { ItemsPerPage = ItemsPerPage, PageNumber = id, AdvertsCount = await this.sharedTravelsService.GetAllAdvertsCount(), Adverts = adverts, }; return(this.View(viewModel)); }
public async Task <IEnumerable <AdvertsListVievModel> > Search(SearchModel s) { //treść if (!String.IsNullOrEmpty(s.Search)) { //treść,kategoria if (!s.Category.Equals("Brak")) { //treść,katgoria,miejsce if (!String.IsNullOrEmpty(s.Place)) { var address = await _context.Addresses.Where(m => m.City.Contains(s.Place)).ToArrayAsync(); AdvertsListViewModel adv = new AdvertsListViewModel(); var al = new List <AdvertsListVievModel>(); foreach (var h in address) { var p = await _context.Adverts .Where(m => m.Deactivate == false) .Where(m => m.Description.Contains(s.Search)) .Where(m => m.Category.Equals(s.Category)) .Where(m => m.AddressId == h.AdressId) .ToArrayAsync(); foreach (var j in p) { var user = _context.Users.Where(m => m.Id == j.UserId).FirstOrDefault(); var img = await _context.Photos.Where(m => m.AdvertId == j.AdvertId && m.IsMain == true).FirstOrDefaultAsync(); al.Add(new AdvertsListVievModel { Address = h, Advert = j, User = user, Photo = img }); } } return(al); } else//treść,kategoria,0 { var adv = await _context.Adverts .Where(m => m.Deactivate == false) .Where(m => m.Description.Contains(s.Search)) .Where(m => m.Category.Equals(s.Category)).ToArrayAsync(); var al = new List <AdvertsListVievModel>(); foreach (var i in adv) { var user = _context.Users.Where(m => m.Id == i.UserId).FirstOrDefault(); var img = _context.Photos.Where(m => m.AdvertId == i.AdvertId && m.IsMain == true).FirstOrDefault(); var add = _context.Addresses.Where(m => m.AdressId == i.AddressId).FirstOrDefault(); al.Add(new AdvertsListVievModel { Address = add, Advert = i, Photo = img, User = user }); } return(al); } } else//treść,0 { //treść,0,miejsce if (!String.IsNullOrEmpty(s.Place)) { var address = await _context.Addresses.Where(m => m.City.Contains(s.Place)).ToArrayAsync(); AdvertsListViewModel adv = new AdvertsListViewModel(); var al = new List <AdvertsListVievModel>(); foreach (var h in address) { var p = await _context.Adverts .Where(m => m.Deactivate == false) .Where(m => m.AddressId == h.AdressId) .Where(m => m.Description.Contains(s.Search)) .ToArrayAsync(); foreach (var j in p) { var user = _context.Users.Where(m => m.Id == j.UserId).FirstOrDefault(); var img = await _context.Photos.Where(m => m.AdvertId == j.AdvertId && m.IsMain == true).FirstOrDefaultAsync(); al.Add(new AdvertsListVievModel { Address = h, Advert = j, User = user, Photo = img }); } } return(al); } else //treść,0,0 { var adv = await _context.Adverts.Where(m => m.Description.Contains(s.Search)).ToArrayAsync(); var al = new List <AdvertsListVievModel>(); foreach (var i in adv) { var ads = await _context.Addresses.Where(x => x.AdressId == i.AddressId).FirstOrDefaultAsync(); var us = await _context.Users.Where(x => x.Id == i.UserId).FirstOrDefaultAsync(); var img = await _context.Photos.Where(x => x.AdvertId == i.AdvertId && x.IsMain == true) .FirstOrDefaultAsync(); al.Add(new AdvertsListVievModel { Address = ads, Advert = i, User = us, Photo = img }); } return(al); } } } else//0, { //0,kategoria if (!s.Category.Equals("Brak")) { //0,katgoria,miejsce if (!String.IsNullOrEmpty(s.Place)) { var address = await _context.Addresses.Where(m => m.City.Contains(s.Place)).ToArrayAsync(); AdvertsListViewModel adv = new AdvertsListViewModel(); var al = new List <AdvertsListVievModel>(); foreach (var h in address) { var p = await _context.Adverts .Where(m => m.Deactivate == false) .Where(m => m.Category.Equals(s.Category)) .Where(m => m.AddressId == h.AdressId) .ToArrayAsync(); foreach (var j in p) { var user = _context.Users.Where(m => m.Id == j.UserId).FirstOrDefault(); var img = await _context.Photos.Where(m => m.AdvertId == j.AdvertId && m.IsMain == true).FirstOrDefaultAsync(); al.Add(new AdvertsListVievModel { Address = h, Advert = j, User = user, Photo = img }); } } return(al); } else//0,kategoria,0 { var adv = await _context.Adverts .Where(m => m.Deactivate == false) .Where(m => m.Category.Equals(s.Category)).ToArrayAsync(); var al = new List <AdvertsListVievModel>(); foreach (var i in adv) { var user = _context.Users.Where(m => m.Id == i.UserId).FirstOrDefault(); var img = _context.Photos.Where(m => m.AdvertId == i.AdvertId && m.IsMain == true).FirstOrDefault(); var add = _context.Addresses.Where(m => m.AdressId == i.AddressId).FirstOrDefault(); al.Add(new AdvertsListVievModel { Address = add, Advert = i, Photo = img, User = user }); } return(al); } } else//0,0 { //0,0,miejsce if (!String.IsNullOrEmpty(s.Place)) { var address = await _context.Addresses.Where(m => m.City.Contains(s.Place)).ToArrayAsync(); AdvertsListViewModel adv = new AdvertsListViewModel(); var al = new List <AdvertsListVievModel>(); foreach (var h in address) { var p = await _context.Adverts .Where(m => m.Deactivate == false) .Where(m => m.AddressId == h.AdressId) .ToArrayAsync(); foreach (var j in p) { var user = _context.Users.Where(m => m.Id == j.UserId).FirstOrDefault(); var img = await _context.Photos.Where(m => m.AdvertId == j.AdvertId && m.IsMain == true).FirstOrDefaultAsync(); al.Add(new AdvertsListVievModel { Address = h, Advert = j, User = user, Photo = img }); } } return(al); } else //0,0,0 { var adv = await _context.Adverts.ToArrayAsync(); var al = new List <AdvertsListVievModel>(); foreach (var i in adv) { var ads = await _context.Addresses.Where(x => x.AdressId == i.AddressId).FirstOrDefaultAsync(); var us = await _context.Users.Where(x => x.Id == i.UserId).FirstOrDefaultAsync(); var img = await _context.Photos.Where(x => x.AdvertId == i.AdvertId && x.IsMain == true) .FirstOrDefaultAsync(); al.Add(new AdvertsListVievModel { Address = ads, Advert = i, User = us, Photo = img }); } return(al); } } } }