protected async Task OnAccountSelected(ChangeEventArgs args) { var accountId = Guid.Parse((string)args.Value); if (SelectedBooking != null) { var account = PaymentAccounts.FirstOrDefault(x => x.Id == accountId); SelectedBooking.PaymentAccount = account; SelectedBooking.PaymentAccountId = account?.Id; await SelectBooking(SelectedBooking); } }
public async Task SelectBooking(Booking booking) { SelectedBooking = booking; if (SelectedBooking.PaymentAccount == null) { if (booking.AssignedPilot != null) { if (booking.PaymentType == PaymentType.Vipps) { booking.PaymentAccountId = booking.AssignedPilot.VippsPaymentAccountId; } else if (booking.PaymentType == PaymentType.IZettle) { booking.PaymentAccountId = booking.AssignedPilot.IZettlePaymentAccountId; } booking.PaymentAccount = PaymentAccounts.FirstOrDefault(a => a.Id == booking.PaymentAccountId); } } using (var scope = ScopeFactory.CreateScope()) { var db = scope.ServiceProvider.GetService <TandemBookingContext>(); FilteredPaymentAccounts = PaymentAccounts .Where(p => p.PaymentType == booking.PaymentType) .ToList(); FilteredPayments = db.Payments .Where(p => p.PaymentAccountId == SelectedBooking.PaymentAccountId) .Where(p => p.UnreconciledAmount > 0) .AsEnumerable() .OrderBy(p => Math.Abs((p.PaymentDate - (booking.CompletedDate ?? booking.BookingDate)).TotalSeconds)) .ToList(); } }