Exemplo n.º 1
0
        public IEnumerable Handle(CancelRoom c)
        {
            if (status == RoomStatus.Available)
            {
                throw new RoomNotBooked($"The room {c.RoomNumber} has not been booked.");
            }
            if (status == RoomStatus.CheckedOut)
            {
                throw new CustomerHasCheckedOut($"Customer has already checked out the room {c.RoomNumber}. Cancellation is not allowed.");
            }

            yield return(new RoomCancelled
            {
                Id = c.Id,
                RoomNumber = c.RoomNumber,
                CancelledTime = c.CancelTime
            });
        }
Exemplo n.º 2
0
        public ActionResult Change(BookingList model)
        {
            var errors = new List <string>();

            if (model.Items?.Count > 0)
            {
                var selected = model.Items.Where(item => item.Selected);
                if (selected.Count() > 0)
                {
                    var bookings = BookingStartup.BookingQueries.GetCurrentBookings();

                    foreach (var item in selected)
                    {
                        try
                        {
                            var booking = bookings.FirstOrDefault(b => b.RoomNumber == item.RoomNumber);
                            if (booking == null)
                            {
                                continue;                   //if the booking cannot be found in current booking, we just disregard it
                            }
                            if (model.Action == "checkin")
                            {
                                var command = new CheckIn {
                                    Id = booking.Id, RoomNumber = item.RoomNumber, CheckInTime = DateTime.Now
                                };
                                BookingStartup.Dispatcher.SendCommand(command);
                            }
                            else if (model.Action == "checkout")
                            {
                                var command = new CheckOut {
                                    Id = booking.Id, RoomNumber = item.RoomNumber, CheckOutTime = DateTime.Now
                                };
                                BookingStartup.Dispatcher.SendCommand(command);
                            }
                            else if (model.Action == "cancel")
                            {
                                var command = new CancelRoom {
                                    Id = booking.Id, RoomNumber = item.RoomNumber, CancelTime = DateTime.Now
                                };
                                BookingStartup.Dispatcher.SendCommand(command);
                            }
                        }
                        catch (Exception ex)
                        {
                            var error = ex.GetType().Name;
                            if (!string.IsNullOrEmpty(ex.Message))
                            {
                                error += ": " + ex.Message;
                            }
                            errors.Add(error);
                        }
                    }
                }
            }

            if (errors.Count > 0)
            {
                TempData["Errors"] = errors;
            }

            return(RedirectToAction("Index"));
        }