Exemplo n.º 1
0
        public ActionResult AddRelatedWord(string lexemeId, string id, 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 dict = lex.WordForms.FirstOrDefault(form => form.UniqueKey == id);
            if (dict == null)
            {
                return RedirectToAction("Index", new { Message = "That does not exist" });
            }

            Lexeme relatedLex = new Lexeme
            {
                Name = vModel.Word,
                Language = lex.Language
            };

            Dictata relatedWord = new Dictata()
            {
                Name = vModel.Word,
                Severity = dict.Severity + vModel.Severity,
                Quality = dict.Quality + vModel.Quality,
                Elegance = dict.Elegance + vModel.Elegance,
                Tense = dict.Tense,
                Language = dict.Language,
                WordType = dict.WordType,
                Feminine = dict.Feminine,
                Possessive = dict.Possessive,
                Plural = dict.Plural,
                Determinant = dict.Determinant,
                Positional = dict.Positional,
                Perspective = dict.Perspective,
                Semantics = dict.Semantics
            };

            HashSet<IDictata> synonyms = dict.Synonyms;
            synonyms.Add(dict);

            if (vModel.Synonym)
            {
                relatedWord.Synonyms = synonyms;
                relatedWord.Antonyms = dict.Antonyms;
                relatedWord.PhraseSynonyms = dict.PhraseSynonyms;
                relatedWord.PhraseAntonyms = dict.PhraseAntonyms;
            }
            else
            {
                relatedWord.Synonyms = dict.Antonyms;
                relatedWord.Antonyms = synonyms;
                relatedWord.PhraseSynonyms = dict.PhraseAntonyms;
                relatedWord.PhraseAntonyms = dict.PhraseSynonyms;
            }

            relatedLex.AddNewForm(relatedWord);

            string message;
            if (relatedLex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User)))
            {
                if (vModel.Synonym)
                {
                    HashSet<IDictata> mySynonyms = dict.Synonyms;
                    mySynonyms.Add(relatedWord);

                    dict.Synonyms = mySynonyms;
                }
                else
                {
                    HashSet<IDictata> antonyms = dict.Antonyms;
                    antonyms.Add(relatedWord);

                    dict.Antonyms = antonyms;
                }

                lex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));
                relatedLex.Save(authedUser.GameAccount, authedUser.GetStaffRank(User));

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

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