public ActionResult AddPlace(PlaceAddForm model) { List<ShortPlace> places = new List<ShortPlace>(); using (var db = new RazomContext()) { PlaceSearchEngine.PlaceSearchEngine engine = new PlaceSearchEngine.PlaceSearchEngine(); List<int> placeIDs = engine.searchPlaces(model.Token); List<int> placeInThisTrip = (from pl in db.Places join tp in db.TravelPlaces on pl.PlaceID equals tp.PlaceID join tr in db.Travels on tp.TravelID equals tr.TravelID where tr.TravelID == model.TripID select pl.PlaceID).ToList(); foreach (var item in placeIDs) { if (!placeInThisTrip.Contains(item)) { places.Add(db.Places.Where(p => p.PlaceID == item).Select(p => new ShortPlace { ID = p.PlaceID, Name = p.Name }).FirstOrDefault()); } } } int pageSize = 6; int pCount = 0; if (places.Count % pageSize == 0) { pCount = places.Count / pageSize; } else pCount = places.Count / pageSize + 1; places = places.Take(pageSize).ToList(); PlaceAddForm paf = new PlaceAddForm() { Token = model.Token, TripID = model.TripID, PlacesInfo = new PlaceCollection() { Places = places, CurrentPage = 1, PagesCount = pCount } }; return View(paf); }
public ActionResult PagerAddPlace(FormCollection form) { List<ShortPlace> places = new List<ShortPlace>(); int page = int.Parse(form["page"].ToString()); int travel_id = int.Parse(form["t_id"].ToString()); string token = form["id"].ToString(); using (var db = new RazomContext()) { PlaceSearchEngine.PlaceSearchEngine engine = new PlaceSearchEngine.PlaceSearchEngine(); List<int> placeIDs = engine.searchPlaces(token); List<int> placeInThisTrip = (from pl in db.Places join tp in db.TravelPlaces on pl.PlaceID equals tp.PlaceID join tr in db.Travels on tp.TravelID equals tr.TravelID where tr.TravelID == travel_id select pl.PlaceID).ToList(); foreach (var item in placeIDs) { if (!placeInThisTrip.Contains(item)) { places.Add(db.Places.Where(p => p.PlaceID == item).Select(p => new ShortPlace { ID = p.PlaceID, Name = p.Name }).FirstOrDefault()); } } } int pageSize = 6; int pCount = 0; if (places.Count % pageSize == 0) { pCount = places.Count / pageSize; } else pCount = places.Count / pageSize + 1; places = places.Skip((page - 1) * pageSize).Take(pageSize).ToList(); PlaceAddForm paf = new PlaceAddForm() { Token = token, TripID = travel_id, PlacesInfo = new PlaceCollection() { Places = places, CurrentPage = page, PagesCount = pCount } }; return View("AddPlace",paf); }