示例#1
0
        public void Release(User user)
        {
            var queueItem = Queue.FirstOrDefault(it => it.BookedBy.Equals(user));

            if (BookedBy.Equals(user))
            {
                if (Queue.Count == 0)
                {
                    BookedUntil   = null;
                    BookingReason = null;
                    BookedBy      = null;
                }
                else
                {
                    var ticket = Queue.OrderBy(it => it.BookingDate).First();
                    Queue.Remove(ticket);

                    BookingReason = ticket.BookingReason;
                    BookedBy      = ticket.BookedBy;
                    BookedUntil   = DateTimeOffset.UtcNow.AddMinutes(ticket.DurationInMinutes);
                }
            }
            else if (queueItem != null)
            {
                Queue.Remove(queueItem);
            }
            else
            {
                throw new ArgumentException($"User {user.Login} is not allowd to release resource because {user.Login} did not book it");
            }
        }
示例#2
0
        private bool MatchBookedBy(Booking booking)
        {
            bool result = false;

            if (string.IsNullOrEmpty(BookedBy))
            {
                result = true;
            }
            else if (BookedBy.Equals(booking.BookedBy, StringComparison.InvariantCultureIgnoreCase))
            {
                result = true;
            }

            return(result);
        }