public InitialStatusException(Order.Status status, string message) : this(message) { OrderStatus = status; }
// Edits the given order and returns a collection of all affected orders public IEnumerable <Order> EditOrder(Order order, Order.Status status) { ICollection <Order> affected_orders = new List <Order>(); if (order.OrderStatus != status) { // Order is already cancelled if (order.OrderStatus == "Cancelled" || order.OrderStatus == "Confirmed") { throw new OrderStatusChangeException(order, "Error: Could not change the status because the order is already closed (confirmed or cancelled)."); } // Order is being opened if (status == "Not addressed") { throw new OrderStatusChangeException(order, "Error: An order cannot be reopened."); } affected_orders.Add(order); // Order is being confirmed if (status == "Confirmed") { if (order.Unit == null) { throw new OrderStatusChangeException(order, "Error: Cannot confirm this order because the hosting unit it is referring to has been deleted."); } if (order.GuestRequest == null) { throw new OrderStatusChangeException(order, "Error: Cannot confirm this order because the guest request it is referring to has been deleted."); } if (!order.Unit.Host.DebitAuthorisation) { throw new OrderStatusChangeException(order, "Error: Cannot close the order because the host does not have debit authorisation."); } try { int fee = Config.FeePerDay * order.GuestRequest.Duration; order.Unit.Bookings.Add(new Unit.Calendar.Booking(order.GuestRequest.StartDate, order.GuestRequest.Duration)); } catch (BookingOverlapException ex) { throw new OrderStatusChangeException(order, "Error: Cannot confirm this order because the your unit is occupied on the requested dates.", ex); } data.Unit.Edit(order.Unit); // Update the unit's calendar in the database // Close all other open orders on this guest request or that overlap the same hosting unit List <Order> orders_to_close = data.Order.All.Where(order1 => order.ID != order1.ID && // It's a different order (order1.OrderStatus == "Not addresses" || order1.OrderStatus == "Sent email") && // The order is open ( order.GuestRequest.ID == order1.GuestRequest.ID || // The order is on the same guest request as the confirmed one (order.Unit.ID == order1.Unit.ID && order.Overlaps(order1)) // The orders overlap on the same unit ) ).ToList(); for (int i = 0; i < orders_to_close.Count; ++i) { EditOrder(orders_to_close[i], "Cancelled"); affected_orders.Add(orders_to_close[i]); } } else if (status == "Sent email") { try { new InvitationSender(order).Send(); } catch (Exception ex) when(ex is InvalidOperationException || ex is ObjectDisposedException || ex is SmtpException || ex is SmtpFailedRecipientException || ex is SmtpFailedRecipientsException) { throw new OrderStatusChangeException(order, "Error: Could not send invitation to the guest. Please check your internet connection.", ex); } } } order.OrderStatus = status; data.Order.Edit(order); return(affected_orders); }
public InitialStatusException(Order.Status status) : this(status, "Error: When adding a new order, the status must be 'Not addressed'. The received order had status '" + status + "'.") { }