/// <summary> /// add order to database /// </summary> /// <param name="order"></param> public void Add_Order(Order order) { //Getting the hosting unit of the order HostingUnit unit = Dal.Get_Hosting_Unit_List().Find(o => o.HostingUnitKey == order.HostingUnitKey); //Getting the guest request of the order GuestRequest req = Dal.Get_Guest_Request_List().Find(o => o.GuestRequestKey == order.GuestRequestKey); //Creating order if (unit.ApproveRequest(req))//If this hosting unit can take this guest request { order.OrderDate = DateTime.Today; try { Dal.Add_Order(order); } catch (KeyNotFoundException ex) { throw new KeyNotFoundException(ex.Message); } } else { throw new InvalidInputException("This unit cannot take this request !"); } }