public void Build(BuildIceCreamViewController controller, IceCreamPart iceCreamPart)
        {
            var conversation = ActiveConversation;

            if (conversation == null)
            {
                throw new Exception("Expected a conversation");
            }

            var iceCream = controller.IceCream;

            if (iceCream == null)
            {
                throw new Exception("Expected the controller to be displaying an ice cream");
            }

            string messageCaption = string.Empty;
            var    b = iceCreamPart as Base;
            var    s = iceCreamPart as Scoops;
            var    t = iceCreamPart as Topping;

            if (b != null)
            {
                iceCream.Base  = b;
                messageCaption = "Let's build an ice cream";
            }
            else if (s != null)
            {
                iceCream.Scoops = s;
                messageCaption  = "I added some scoops";
            }
            else if (t != null)
            {
                iceCream.Topping = t;
                messageCaption   = "Our finished ice cream";
            }
            else
            {
                throw new Exception("Unexpected type of ice cream part selected.");
            }

            // Create a new message with the same session as any currently selected message.
            var message = ComposeMessage(iceCream, messageCaption, conversation.SelectedMessage?.Session);

            // Add the message to the conversation.
            conversation.InsertMessage(message, null);

            // If the ice cream is complete, save it in the history.
            if (iceCream.IsComplete)
            {
                var history = IceCreamHistory.Load();
                history.Append(iceCream);
                history.Save();
            }

            Dismiss();
        }
        public void Build(BuildIceCreamViewController controller, IceCreamPart iceCreamPart)
        {
            var conversation = ActiveConversation;
            if (conversation == null)
                throw new Exception ("Expected a conversation");

            var iceCream = controller.IceCream;
            if (iceCream == null)
                throw new Exception ("Expected the controller to be displaying an ice cream");

            string messageCaption = string.Empty;
            var b = iceCreamPart as Base;
            var s = iceCreamPart as Scoops;
            var t = iceCreamPart as Topping;

            if (b != null) {
                iceCream.Base = b;
                messageCaption = "Let's build an ice cream";
            } else if (s != null) {
                iceCream.Scoops = s;
                messageCaption = "I added some scoops";
            } else if (t != null) {
                iceCream.Topping = t;
                messageCaption = "Our finished ice cream";
            } else {
                throw new Exception ("Unexpected type of ice cream part selected.");
            }

            // Create a new message with the same session as any currently selected message.
            var message = ComposeMessage (iceCream, messageCaption, conversation.SelectedMessage?.Session);

            // Add the message to the conversation.
            conversation.InsertMessage (message, null);

            // If the ice cream is complete, save it in the history.
            if (iceCream.IsComplete) {
                var history = IceCreamHistory.Load ();
                history.Append (iceCream);
                history.Save ();
            }

            Dismiss ();
        }