Example #1
0
        public virtual Language GetValidLanguage(string paramValue, ItemContextParameters parameters, IConversation conversation)
        {
            var dbName = (!string.IsNullOrEmpty(parameters.Database)) ? parameters.Database : "master";
            var db     = DataWrapper.GetDatabase(dbName);
            var langs  = DataWrapper.GetLanguages(db).Where(a => a.Name.Equals(paramValue)).ToList();

            return(langs.Any() ? langs.First() : null);
        }
        public override ConversationResponse Respond(LuisResult result, ItemContextParameters parameters, IConversation conversation)
        {
            var item    = (Item)conversation.Data[ItemKey].Value;
            var version = (string)conversation.Data[VersionKey].Value;
            var date    = (string)conversation.Data[DateKey].Value;
            var dbs     = (List <Database>)conversation.Data[DBKey].Value;

            var fields = new Dictionary <ID, string>();
            int versionInt;

            //set item settings
            if (version.Equals("0"))
            {
                fields = (string.IsNullOrWhiteSpace(date))
                    ? GetFields("", "1", "", "")
                    : GetFields(date, "", "", "");
            } //version settings
            else if (int.TryParse(version, out versionInt))
            {
                fields = (string.IsNullOrWhiteSpace(date))
                    ? GetFields("", "", "", "1")
                    : GetFields("", "", date, "");
            }

            if (fields.Any())
            {
                DataWrapper.UpdateFields(item, fields);

                var db    = Sitecore.Configuration.Factory.GetDatabase(parameters.Database);
                var langs = DataWrapper.GetLanguages(db)
                            .Where(a => a.Name.Equals(parameters.Language))
                            .ToArray();
                PublishWrapper.PublishItem(item, dbs.ToArray(), langs, false, false, false);
            }

            var dateResponse = "";

            if (!string.IsNullOrWhiteSpace(date))
            {
                var dateTime = DateUtil.IsoDateToDateTime(date);
                dateResponse = (dateTime.Hour > 0)
                    ? dateTime.ToString("MMMM d, yyyy h:mmtt")
                    : dateTime.ToString("MMMM d, yyyy ");

                var at = Translator.Text("Chat.Intents.Unpublish.At");
                dateResponse = $" {at} {dateResponse}";
            }
            return(ConversationResponseFactory.Create(KeyName, string.Format(Translator.Text("Chat.Intents.Unpublish.Response"), item.Paths.Path, string.Join(", ", dbs.Select(a => a.Name)), dateResponse)));
        }