/// <summary> /// Saves all bookings on the BookingList to the database /// </summary> public void SaveBookingsToDB() { foreach (var booking in BookingList) { int bookingId = Bookings.Insert(booking); foreach (var item in booking.Credits.OrderBy(x => x.CreditId)) { item.RefBookingId = bookingId; var fakeId = item.CreditId; item.CreditId = Credits.Insert(item); foreach (var credit in booking.Credits) { if (credit.RefCreditId == fakeId) { credit.RefCreditId = item.CreditId; } } } foreach (var item in booking.Debits.OrderBy(x => x.DebitId)) { item.RefBookingId = bookingId; var fakeId = item.DebitId; item.DebitId = Debits.Insert(item); foreach (var debit in booking.Debits) { if (debit.RefDebitId == fakeId) { debit.RefDebitId = item.DebitId; } } } foreach (ScannedDocument item in booking.ScannedDocuments) { item.RefBookingId = bookingId; } ScannedDocuments.Insert(booking.ScannedDocuments); foreach (BookingCostCenterMapping item in booking.BookingCostCenterMappingList) { item.RefBookingId = bookingId; } BookingCostCenterMappings.Insert(booking.BookingCostCenterMappingList); } BookingList.Clear(); SelectedBooking = null; }
private void CancelingSelectedBooking() { SelectedBooking.IsCanceled = true; Bookings.UpdateCancelingStatus(SelectedBooking); Booking cancelBooking = new Booking(DateTime.Now, "Stornierung von Buchung " + SelectedBooking.BookingId + " - " + SelectedBooking.Description) { RefFixedCostAllocationId = SelectedBooking.RefFixedCostAllocationId, FixedCostAllocation = SelectedBooking.FixedCostAllocation, }; cancelBooking.BookingId = Bookings.Insert(cancelBooking); foreach (Credit item in SelectedBooking.Credits) { cancelBooking.Credits.Add(new Credit(item.Amount * (-1), item.RefCostAccountId, cancelBooking.BookingId)); } foreach (Debit item in SelectedBooking.Debits) { cancelBooking.Debits.Add(new Debit(item.Amount * (-1), item.RefCostAccountId, cancelBooking.BookingId)); } foreach (BookingCostCenterMapping item in SelectedBooking.BookingCostCenterMappingList) { cancelBooking.BookingCostCenterMappingList.Add(new BookingCostCenterMapping(cancelBooking.BookingId, item.RefCostCenterId, item.Amount * (-1)) { CostCenter = item.CostCenter }); } Credits.Insert(cancelBooking.Credits); Debits.Insert(cancelBooking.Debits); BookingCostCenterMappings.Insert(cancelBooking.BookingCostCenterMappingList); SearchForData(); }