public static List <TripDestination> CalcCombinedTripDestinations(this Trip trip) { //create list to hold distinct trip destinations List <TripDestination> tripDestinations = new List <TripDestination>(); //iterate over regular trip destinations trip.TripDestinations.ToList().ForEach(curTD => { //seek trip destination in abandoned list with same sender/destination combination as in current trip destination TripDestination td = trip.PreviouslyAbandonedTripDestinations.FirstOrDefault(aTD => aTD.Sender == curTD.Sender && aTD.Destination == curTD.Destination); //if there is an previously abandoned trip destination... if (td != null) { //create a combined trip destination tripDestinations.Add(new ExecuteTripTripDestinationVM(curTD, td)); } else { //simply insert current trip destination tripDestinations.Add(curTD); } }); //add abandoned trip destinations which are not yet in list / which are not contained in regular trip destinations tripDestinations.AddRange(trip.PreviouslyAbandonedTripDestinations.Where(aTD => !tripDestinations.Any(td => td.Sender == aTD.Sender && td.Destination == aTD.Destination))); return(tripDestinations); }
public ExecuteTripTripDestinationVM(TripDestination tripDestination, TripDestination previouslyAbandonedTripDestination) : base(tripDestination.Trip, tripDestination.Sender, tripDestination.Destination) { TripDestination = tripDestination; PreviouslyAbandonedTripDestination = previouslyAbandonedTripDestination; //create combined visit purposes based on trip destinations TripDestination.VisitPurposes.ForEach(vp => AddCombinedVisitPurpose(vp)); PreviouslyAbandonedTripDestination.VisitPurposes.ForEach(vp => AddCombinedVisitPurpose(vp)); }
public IActionResult RemoveDestination(int tripId, int destinationMediaId) { TripDestination foundTd = db.TripDestinations.FirstOrDefault(td => td.TripId == tripId && td.DestinationMediaId == destinationMediaId); if (foundTd != null) { db.TripDestinations.Remove(foundTd); db.SaveChanges(); } return(RedirectToAction("Details", new { tripId = tripId })); }
public void add() { if (validateAll()) { TripDestination dest = new TripDestination(); dest.id_trip = textBox1.Text; dest.name = textBox2.Text; dest.id_region = getRegionId(comboBox1.Text); dest.address = textBox3.Text; dest.description = textBox6.Text; dest.localPrice = double.Parse(textBox5.Text); dest.internationalPrice = double.Parse(textBox8.Text); try { data.TripDestinations.Add(dest); data.SaveChanges(); Gallery photo = new Gallery(); photo.id_trip = textBox1.Text; photo.photo = textBox4.Text; try { data.Galleries.Add(photo); data.SaveChanges(); helpers.showInfo("New destinations has been added!"); } catch (SqlException ex) { if (ex.Number == 2627) { helpers.showError("Sorry, can't add duplicate destinations data!"); } else { helpers.showError(ex.Message); } } } catch (SqlException ex) { if (ex.Number == 2627) { helpers.showError("Sorry, can't add duplicate destinations data!"); } else { helpers.showError(ex.Message); } } } }
public ExecuteTripSenderListItemViewModel(TripDestination tripDestination, List <ExecuteTripVisitPurposeSelectionVM> visitPurposeVMs) { TripDestination = tripDestination; VisitPurposeVMs = visitPurposeVMs; //iterate over corresponding visit purpose view models to set the callback method VisitPurposeVMs?.ForEach(vp => vp.OnIsAbandonedChangedHandler = CalcState); CalcState(); //commands AbandonCommand = new RelayCommand(AbandonCommandMethod); }
public TripDestinationResource Convert(TripDestination tripDestination) { var result = _mapper.Map <TripDestinationResource>(tripDestination); if (result.Type == TripDestinationType.Mountain) { result.Mountain = _mountainBriefResourceConverter.Convert(tripDestination.Mountain); } else if (result.Type == TripDestinationType.Rock) { result.Rock = _rockBriefResourceConverter.Convert(tripDestination.Rock); } return(result); }
public IActionResult AddDestination(int tripId, TripDestination newTripDestination) { newTripDestination.TripId = tripId; bool alreadyExists = db.TripDestinations .Any(td => td.TripId == newTripDestination.TripId && td.DestinationMediaId == newTripDestination.DestinationMediaId); if (!alreadyExists) { db.TripDestinations.Add(newTripDestination); db.SaveChanges(); } return(RedirectToAction("Details", new { tripId = newTripDestination.TripId })); }
public IActionResult AddDestination(TripDestination newTripDest, int tripId) { db.TripDestinations.Add(newTripDest); db.SaveChanges(); return(RedirectToAction("Details", new { tripId = tripId })); }