public async Task CannotCancelCheckedOutBookingTest() { BookingItem bookingItem = CreateBookingItem(); bookingItem.Status = Constants.CheckedOut; var saga = new ProcessBookingSaga() { Data = new ProcessBookingSaga.BookingData() { BookingNumber = 0, ClientId = "JonSnowClientId", BookingItem = bookingItem } }; var context = new TestableMessageHandlerContext(); CancelBooking cancelBooking = new CancelBooking(); cancelBooking.BookingNumber = 0; cancelBooking.ClientId = "JonSnowClientId"; await saga.Handle(cancelBooking, context) .ConfigureAwait(false); Assert.AreEqual(0, context.PublishedMessages.Length); }
public async Task CancelBookingTest() { BookingItem bookingItem = CreateBookingItem(); var saga = new ProcessBookingSaga() { Data = new ProcessBookingSaga.BookingData() { BookingNumber = 0, ClientId = "JonSnowClientId", BookingItem = bookingItem } }; var context = new TestableMessageHandlerContext(); CancelBooking cancelBooking = new CancelBooking(); cancelBooking.BookingNumber = 0; cancelBooking.ClientId = "JonSnowClientId"; await saga.Handle(cancelBooking, context) .ConfigureAwait(false); var bookingCanceled = (BookingCancelled)context.PublishedMessages[0].Message; Assert.AreEqual(0, bookingCanceled.BookingNumber); Assert.AreEqual(Constants.Cancelled, saga.Data.BookingItem.Status); }
public async Task <MessageResult> Handle(CancelBooking message) { var booking = await repository.Get(message.BookingId); booking.Cancel(); await repository.Save(booking); return(MessageResult.Null); }
public async Task CancelBooking(int bookingNumber) { var command = new CancelBooking { ClientId = Context.ConnectionId, BookingNumber = bookingNumber }; var sendOptions = new SendOptions(); await MvcApplication.EndpointInstance.Send(command, sendOptions); }
public ActionResult Cancel(Guid id) { if (ModelState.IsValid) { CancelBooking cmd = new CancelBooking { Id = id, CancelledDate = DateTime.Now }; Domain.Dispatcher.SendCommand(cmd); } return(RedirectToAction("Index")); }
public IActionResult CancelBooking(CancelBooking cancelBooking) { if (ModelState.IsValid) { try { cancelBooking.Id = cancelBooking.BookingId; _domain.Dispatcher.SendCommand(cancelBooking); return(RedirectToAction("BookingCancellation", new { result = true, inProcess = true, errorMessage = "" })); } catch (Exception e) { _logger.LogInformation(ExceptionTranslator.TranslateException(e)); return(RedirectToAction("BookingCancellation", new { result = false, inProcess = true, errorMessage = ExceptionTranslator.TranslateException(e) })); } } return(RedirectToAction("BookingCancellation", new { result = false, inProcess = true, errorMessage = "Invalid data" })); }
public async Task <IActionResult> CancelBooking([FromRoute] CancelBooking cmd) { try { await messaging.Send(cmd); return(StatusCode(204)); } catch (Domain.BookingException e) { return(StatusCode(e.Status, new { e.Message })); } catch (Exception e) { logger.LogError(e, $"{nameof(CancelBooking)} error"); return(StatusCode(500)); } }
public IEnumerable Handle(CancelBooking c) { if (!DoesBookingExist(c.BookingId)) { throw new UnexistingBooking(); } foreach (BookingCheckedOut b in bookingsCheckedOut) { if (c.BookingId == b.BookingId) { throw new CanNotCancelUponCheckOut(); } } yield return(new BookingCancelled { Id = c.Id, BookingId = c.BookingId }); }
public Task Handle(CancelBooking message, IMessageHandlerContext context) { //cannot cancel a booking already checked out if (Data.BookingItem.Status == Constants.CheckedOut) { log.Error($"Cannot cancel out booking #{message.BookingNumber} ."); return(Task.CompletedTask); } Data.BookingItem.Status = Constants.Cancelled; MarkAsComplete(); log.Info($"Booking #{message.BookingNumber} was cancelled."); var orderCancelled = new BookingCancelled { BookingNumber = message.BookingNumber, ClientId = message.ClientId }; return(context.Publish(orderCancelled)); }
public void Process(CancelBooking command) { var e = new BookingCanceled(command.User); ApplyEvent(e); }
/// <summary> /// Tony Noel /// Created: 2015/03/20 /// UI to confirm details for cancelling a booking /// </summary> /// <remarks> /// Pat Banks /// Updated: 2015/03/19 /// Moved logic checks to invoice manager - checkToArchiveInvoice /// </remarks> private void CancelBooking() { //check if something was selected if (LvGuestBookings.SelectedItem == null) { throw new WanderingTurtleException(this, "Please select a booking to cancel."); } //check if selected item can be cancelled ResultsEdit result = _bookingManager.CheckToEditBooking((BookingDetails)LvGuestBookings.SelectedItem); switch (result) { case (ResultsEdit.CannotEditTooOld): throw new WanderingTurtleException(this, "Bookings in the past cannot be cancelled.", "Warning"); case (ResultsEdit.Cancelled): throw new WanderingTurtleException(this, "This booking has already been cancelled.", "Warning"); case (ResultsEdit.OkToEdit): try { //opens the ui and passes the booking details object in CancelBooking cancel = new CancelBooking((BookingDetails)LvGuestBookings.SelectedItem, CurrentInvoice); if (cancel.ShowDialog() == false) return; RefreshBookingList(); } catch (Exception ex) { throw new WanderingTurtleException(this, ex); } break; } }