public void SaveExpense(Trip trip, Expense expense) { if (trip.Expenses.FirstOrDefault((x) => x.Id == expense.Id) != null) trip.Expenses.Remove(expense); trip.Expenses.Add(expense); SaveTrip(trip); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); SetContentView(Resource.Layout.EditExpense); var tripId = Intent.GetStringExtra("SelectedTripId"); _trip = new TripManager().GetTrip(new Guid(tripId)); var expenseId = Intent.GetStringExtra("SelectedExpenseId"); if (!string.IsNullOrEmpty(expenseId)) _expense = _trip.Expenses.FirstOrDefault((x) => x.Id == new Guid(expenseId)); else { _expense = new Expense() {Date = DateTime.Now}; } FindViewById<Button>(Resource.Id.editExpenseButtonSave).Click += (s, e) => { UpdateExpense(); new TripManager().SaveExpense(_trip, _expense); var intent = new Intent(this, typeof(ViewTripDetailScreen)); intent.PutExtra("SelectedTripId", _trip.Id.ToString()); base.StartActivity(intent); }; FindViewById<Button>(Resource.Id.editExpenseButtonDelete).Click += (s, e) => { new TripManager().RemoveExpense(_trip, _expense); var intent = new Intent(this, typeof(ViewTripDetailScreen)); intent.PutExtra("SelectedTripId", _trip.Id.ToString()); base.StartActivity(intent); }; UpdateUI(); }
public void RemoveExpense(Trip trip, Expense expense) { trip.Expenses.Remove(expense); SaveTrip(trip); }
public void RemoveExpense(Trip trip, Expense expense) { _tripRepository.RemoveExpense(trip, expense); }
public void SaveExpense(Trip trip, Expense expense) { _tripRepository.SaveExpense(trip, expense); }