Esempio n. 1
0
        /// <summary>
        /// Remove the subscriber for the given magazine.
        /// </summary>
        /// <param name="magazineName"></param>
        /// <param name="subscriber"></param>
        public void Unsubscribe(string magazineName, MagazineSubscriber subscriber)
        {
            if (!_subscribers.ContainsKey(magazineName) || !_subscribers[magazineName].Contains(subscriber))
            {
                Console.WriteLine($"{subscriber.Name} was not subscribed to {magazineName}.");
            }

            _subscribers[magazineName].Remove(subscriber);

            Console.WriteLine($"{subscriber.Name} is no longer subscribed to {magazineName}.");
        }
Esempio n. 2
0
        /// <summary>
        /// Subscribe the subscriber to the given magazine.
        /// </summary>
        /// <param name="magazineName"></param>
        /// <param name="subscriber"></param>
        public void Subscribe(string magazineName, MagazineSubscriber subscriber)
        {
            if (!_subscribers.ContainsKey(magazineName))
            {
                _subscribers[magazineName] = new HashSet <MagazineSubscriber>();
            }

            if (_subscribers[magazineName].Contains(subscriber))
            {
                Console.WriteLine($"{subscriber.Name} cannot subscribe to {magazineName} more than once.");
            }
            else
            {
                _subscribers[magazineName].Add(subscriber);

                Console.WriteLine($"{subscriber.Name} has been subscribed to {magazineName}.");
            }
        }