private void Type_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            vNextBot.Model.Action action = sender as vNextBot.Model.Action;

            if (action != null)
            {
                Title.IsEnabled = true;
                Url.IsEnabled   = true;

                switch (action.c_const)
                {
                case "TFS_API":
                case "API":
                    Title.IsEnabled = false;
                    break;

                case "TEXT":
                    Url.IsEnabled = false;
                    break;
                }
            }
        }
        /// <summary>
        /// Сохранение
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
        {
            resetSummary();

            if (string.IsNullOrEmpty(Question.Text))
            {
                setSummary("Вопрос не указан.");
                args.Cancel = true;
                return;
            }

            vNextBot.Model.Action action = (vNextBot.Model.Action)Type.SelectedValue;
            if (action.c_const == "TFS_API" ||
                action.c_const == "API" ||
                action.c_const == "DOWNLOAD" ||
                action.c_const == "LINK")
            {
                if (string.IsNullOrEmpty(Url.Text))
                {
                    setSummary("url не указан.");
                    args.Cancel = true;
                    return;
                }
            }

            if (action.c_const == "DOWNLOAD" ||
                action.c_const == "LINK" ||
                action.c_const == "TEXT")
            {
                if (string.IsNullOrEmpty(Title.Text))
                {
                    setSummary("title не указан.");
                    args.Cancel = true;
                    return;
                }
            }

            using (ApplicationContext db = new ApplicationContext())
            {
                KnowledgeBase setting;

                if (id.HasValue)
                {
                    setting = db.KnowledgeBases.Find(id);
                }
                else
                {
                    // создание
                    setting            = new KnowledgeBase();
                    setting.dx_created = DateTime.Now;
                }

                setting.c_question = Question.Text;
                setting.jb_tags    = Newtonsoft.Json.JsonConvert.SerializeObject(Tags.Text.Split(", "));
                setting.f_action   = ((vNextBot.Model.Action)Type.SelectedValue).id;
                setting.b_disabled = IsDisabled.IsChecked.Value;
                setting.c_weight   = Weight.Text[0];

                dynamic data = new {
                    url   = Url.Text,
                    title = Title.Text
                };
                setting.jb_data = Newtonsoft.Json.JsonConvert.SerializeObject(data);

                if (id.HasValue)
                {
                    db.KnowledgeBases.Update(setting);
                }
                else
                {
                    var query = from t in db.KnowledgeBases
                                where t.c_question == setting.c_question
                                select t;
                    if (query.Count() > 0)
                    {
                        setSummary("Запись с вопросом " + setting.c_question + " существует.");
                        args.Cancel = true;
                    }
                    else
                    {
                        db.KnowledgeBases.Add(setting);
                    }
                }
                db.SaveChanges();
            }
        }