public static void SynchronizeUpdating(this ITourCollection tourList, Excursion excursion) { if (excursion.ToursId == null) { return; } foreach (Tour tour in tourList.Tours) { Tour newTour = tour; if (excursion.ToursId.Contains(tour.Id) && !tour.ExcursionsId.Contains(excursion.Id)) { newTour.ExcursionsId.Add(excursion.Id); tourList.Update(newTour); } else if (!excursion.ToursId.Contains(tour.Id) && tour.ExcursionsId.Contains(excursion.Id)) { newTour.ExcursionsId.Remove(excursion.Id); tourList.Update(newTour); } } }
public static void SynchronizeUpdating(this ITourCollection tourList, TravelAgency agency) { if (agency.ToursId == null) { return; } foreach (Tour tour in tourList.Tours) { Tour newTour = tour; if (agency.ToursId.Contains(tour.Id) && !tour.AgenciesId.Contains(agency.Id)) { newTour.AgenciesId.Add(agency.Id); tourList.Update(newTour); } else if (!agency.ToursId.Contains(tour.Id) && tour.AgenciesId.Contains(agency.Id)) { newTour.AgenciesId.Remove(agency.Id); tourList.Update(newTour); } } }
public IActionResult OnPostOk() { if (ModelState.IsValid) { Tour.Country = Converter.GetCountry(); Tour.City = Converter.GetCity(); Tour.Accomodation = Converter.GetAccomodation(); Tour.AgenciesId = Converter.GetAgency(); Tour.ExcursionsId = Converter.GetExcursion(); _agencyList.SynchronizeUpdating(Tour); _excursionList.SynchronizeUpdating(Tour); _tourList.Update(Tour); return(RedirectToPage("Tours", new { userId = UserId })); } return(Page()); }