예제 #1
0
        public void OrderUpdate(int orderKey, enums.OrderStatus statusOfOrder)
        {
            var orderToUpdate = (from xmlOrder in XmlConfigurations.OrderRoot.Elements()
                                 where xmlOrder.Element("OrderKey")?.Value == orderKey.ToString()
                                 select xmlOrder).FirstOrDefault();

            if (orderToUpdate == null)
            {
                throw new OrderProblemException("something wrong with the order key");
            }



            orderToUpdate.Element("HostId").Value            = orderToUpdate.Element("HostId")?.Value;
            orderToUpdate.Element("AccommodationKey").Value  = orderToUpdate.Element("AccommodationKey")?.Value;
            orderToUpdate.Element("HostingUnitKey").Value    = orderToUpdate.Element("HostingUnitKey")?.Value;
            orderToUpdate.Element("GuestRequestKey").Value   = orderToUpdate.Element("GuestRequestKey")?.Value;
            orderToUpdate.Element("OrderKey").Value          = orderToUpdate.Element("OrderKey")?.Value;
            orderToUpdate.Element("OrderStatus").Value       = statusOfOrder.ToString();
            orderToUpdate.Element("OrderCreationDate").Value = orderToUpdate.Element("OrderCreationDate")?.Value;
            orderToUpdate.Element("SendingEmailDate").Value  = orderToUpdate.Element("SendingEmailDate")?.Value;



            XmlConfigurations.OrderRoot.Save(XmlConfigurations.OrdersPath);
        }
예제 #2
0
        /// <summary>
        /// Update Order status in Data Base
        /// </summary>
        /// <param name="orderKey"></param>
        /// <param name="statusOfOrder"></param>
        public void OrderUpdate(int orderKey, enums.OrderStatus statusOfOrder)
        {
            var ourOrder = GetAllOrders(getOrder => getOrder.OrderKey == orderKey).FirstOrDefault();

            if (ourOrder == null)
            {
                throw new Exception("The order is not exist");
            }

            if (ourOrder.OrderStatus == enums.OrderStatus.Completed)
            {
                throw new Exception("Reservation changes cannot be made once closed");
            }


            if (statusOfOrder == enums.OrderStatus.Completed)
            {
                //get the guest request
                var getRequest = GetAllGuestRequests(x => x.GuestRequestKey == ourOrder.GuestRequestKey)
                                 .FirstOrDefault();

                //Saves the days for booking in the guest unit book
                _idalImp.HostingUnitDiaryUpdate(ourOrder.HostingUnitKey, ourOrder.AccommodationKey, ourOrder.HostId,
                                                getRequest.CheckInDate, getRequest.CheckOutDate);

                //change the guestRequest status
                _idalImp.CustomerRequirementStatusUpdate(true, getRequest.GuestRequestKey);

                //Updating the status of all open orders for a customer's cancellation request after
                //the customer has selected one of the offers
                foreach (var getOrder in _idalImp.GetAllOrders(others =>
                                                               others.GuestRequestKey == getRequest.GuestRequestKey && others.OrderKey != orderKey))
                {
                    _idalImp.OrderUpdate(getOrder.OrderKey, enums.OrderStatus.Cancelled);
                }


                //Update in database about the new order and the commission
                _idalImp.UpdateOrderCompletion(CommissionCalculate(getRequest.CheckInDate, getRequest.CheckOutDate),
                                               ourOrder.HostId);

                //Update the sum of orders-completed on the specific unit
                HostingUnitUpdate(ourOrder.HostingUnitKey, ourOrder.AccommodationKey, ourOrder.HostId, enums.UnitUpdate.OrderCompleted, true);
            }

            if (statusOfOrder == enums.OrderStatus.EmailSent)
            {
                Console.WriteLine("you got an order");
            }


            //update the status of order in database
            _idalImp.OrderUpdate(orderKey, statusOfOrder.Clone());
        }