Ejemplo n.º 1
0
        /// <summary>
        /// Enqueue a new ticket to the queue system
        /// </summary>
        /// <param name="queueLaneNumber"></param>
        /// <param name="newQueueTicket"></param>
        /// <returns></returns>
        public bool EnqueueLane(QueueTicket newQueueTicket)
        {
            if (laneQueues.TryGetValue(newQueueTicket.QueueLane.LaneNumber, out LaneQueue laneQueue))
            {
                if (laneQueue == null)
                {
                    //lane is inactive
                    return(false);
                }
                else
                {
                    if (laneQueue.QueueList.Count != laneQueue.GetQueueCapacity())
                    {
                        //reflect changes in database
                        bool isSuccess = dataAccessLogic.AddQueueTicket(
                            newQueueTicket,
                            queueStatusMapper
                            );

                        //check if account is user or guest
                        if (newQueueTicket.owner is User user)
                        {
                            newQueueTicket = dataAccessLogic
                                             .GetQueueTicketsOfWithStatusAndLaneID(
                                user.AccountNumber,
                                newQueueTicket.QueueLane.LaneID,
                                newQueueTicket.Status,
                                queueStatusMapper
                                )
                                             .DefaultIfEmpty(null)
                                             .FirstOrDefault();
                        }
                        else if (newQueueTicket.owner is Guest guest)
                        {
                            newQueueTicket = dataAccessLogic
                                             .GetQueueTicketsOfWithStatusAndLaneID(
                                guest.AccountNumber,
                                newQueueTicket.QueueLane.LaneID,
                                newQueueTicket.Status,
                                queueStatusMapper
                                )
                                             .DefaultIfEmpty(null)
                                             .FirstOrDefault();
                        }
                        else
                        {
                            throw new ArgumentException("Unexpected account type for queue ticket, it is not a guest or user.");
                        }

                        if (!isSuccess ||
                            newQueueTicket == null)
                        {
                            throw new Exception("Failed to add or get new queue ticket.");
                        }

                        laneQueue.EnqueueTicket(newQueueTicket);

                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }
        }