示例#1
0
        public ActionResult AddDictata(string lexemeId, AddEditDictataViewModel vModel)
        {
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            ILexeme lex = ConfigDataCache.Get<ILexeme>(new ConfigDataCacheKey(typeof(ILexeme), lexemeId, ConfigDataType.Dictionary));
            if (lex == null)
            {
                return RedirectToAction("Index", new { Message = "That does not exist" });
            }

            IDictata newObj = vModel.DataObject;

            lex.AddNewForm(newObj);

            string message;
            if (lex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                LoggingUtility.LogAdminCommandUsage("*WEB* - AddDictata[" + newObj.UniqueKey + "]", authedUser.GameAccount.GlobalIdentityHandle);
                message = "Creation Successful.";
            }
            else
            {
                message = "Error; Creation failed.";
            }

            return RedirectToAction("Index", new { Message = message });
        }
示例#2
0
        /// <summary>
        /// Get the lexeme for this word
        /// </summary>
        /// <returns>the lexeme</returns>
        public ILexeme GetLexeme()
        {
            ILexeme lex = ConfigDataCache.Get <ILexeme>(string.Format("{0}_{1}_{2}", ConfigDataType.Dictionary, Language.Name, Name));

            if (lex != null)
            {
                if (!lex.WordForms.Any(form => form == this))
                {
                    lex.AddNewForm(this);
                    lex.SystemSave();
                    lex.PersistToCache();
                }
            }
            else
            {
                lex = new Lexeme()
                {
                    Name     = Name,
                    Language = Language
                };

                lex.SystemSave();
                lex.PersistToCache();

                lex.AddNewForm(this);
            }

            return(lex);
        }
示例#3
0
        public ActionResult EditDictata(string lexemeId, string id, AddEditDictataViewModel vModel)
        {
            string message = string.Empty;
            ApplicationUser authedUser = UserManager.FindById(User.Identity.GetUserId());

            ILexeme lex = ConfigDataCache.Get<ILexeme>(new ConfigDataCacheKey(typeof(ILexeme), lexemeId, ConfigDataType.Dictionary));
            IDictata obj = lex?.WordForms?.FirstOrDefault(form => form.UniqueKey == id);

            if (obj == null)
            {
                message = "That does not exist";
                return RedirectToAction("Index", new { Message = message });
            }

            obj.Name = vModel.DataObject.Name;
            obj.Severity = vModel.DataObject.Severity;
            obj.Quality = vModel.DataObject.Quality;
            obj.Elegance = vModel.DataObject.Elegance;
            obj.Tense = vModel.DataObject.Tense;
            obj.Synonyms = vModel.DataObject.Synonyms;
            obj.Antonyms = vModel.DataObject.Antonyms;
            obj.PhraseSynonyms = vModel.DataObject.PhraseSynonyms;
            obj.PhraseAntonyms = vModel.DataObject.PhraseAntonyms;
            obj.Language = vModel.DataObject.Language;
            obj.WordType = vModel.DataObject.WordType;
            obj.Feminine = vModel.DataObject.Feminine;
            obj.Possessive = vModel.DataObject.Possessive;
            obj.Plural = vModel.DataObject.Plural;
            obj.Determinant = vModel.DataObject.Determinant;
            obj.Positional = vModel.DataObject.Positional;
            obj.Perspective = vModel.DataObject.Perspective;
            obj.Semantics = vModel.DataObject.Semantics;

            lex.AddNewForm(obj);

            if (lex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                foreach (IDictata syn in obj.Synonyms)
                {
                    if (!syn.Synonyms.Any(dict => dict == obj))
                    {
                        HashSet<IDictata> synonyms = syn.Synonyms;
                        synonyms.Add(obj);

                        ILexeme synLex = syn.GetLexeme();
                        syn.Synonyms = synonyms;

                        synLex.AddNewForm(syn);
                        synLex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                    }
                }

                foreach (IDictata ant in obj.Antonyms)
                {
                    if (!ant.Antonyms.Any(dict => dict == obj))
                    {
                        HashSet<IDictata> antonyms = ant.Antonyms;
                        antonyms.Add(obj);

                        ILexeme antLex = ant.GetLexeme();
                        ant.Antonyms = antonyms;
                        antLex.AddNewForm(ant);
                        antLex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                    }
                }

                foreach (IDictataPhrase syn in obj.PhraseSynonyms)
                {
                    if (!syn.Synonyms.Any(dict => dict == obj))
                    {
                        HashSet<IDictata> synonyms = syn.Synonyms;
                        synonyms.Add(obj);

                        syn.Synonyms = synonyms;
                        syn.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                    }
                }

                foreach (IDictataPhrase ant in obj.PhraseAntonyms)
                {
                    if (!ant.Antonyms.Any(dict => dict == obj))
                    {
                        HashSet<IDictata> antonyms = ant.Antonyms;
                        antonyms.Add(obj);

                        ant.Antonyms = antonyms;
                        ant.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                    }
                }

                LoggingUtility.LogAdminCommandUsage("*WEB* - EditDictata[" + obj.UniqueKey + "]", authedUser.GameAccount.GlobalIdentityHandle);
                message = "Edit Successful.";
            }
            else
            {
                message = "Error; Edit failed.";
            }

            return RedirectToAction("Index", new { Message = message });
        }