Exemple #1
0
        /// <summary>
        /// 增加罗马音-谐音键值对,若本身存在返回ID
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool AddPair(string key, string value, out string sqlValue, out int id)
        {
            var pair = kouContext.Set <RomajiPair>().SingleOrDefault(x => x.RomajiKey == key);

            if (pair == null)
            {
                RomajiPair romajiPair = new RomajiPair {
                    RomajiKey = key, ZhValue = value
                };
                kouContext.Add(romajiPair);
                bool result = kouContext.SaveChanges() > 0;
                if (result)
                {
                    RomajiToZhDict.Add(key, value);
                }
                id       = romajiPair.Id;
                sqlValue = key;
                return(result);
            }
            else
            {
                sqlValue = pair.RomajiKey;
                id       = pair.Id;
                return(false);
            }
        }
Exemple #2
0
        public string KouLearnAnotherName(string songName, string songAnotherName)
        {
            string songEnID = _kouContext.Set <PluginArcaeaSongAnotherName>().Where(name => name.AnotherName == songName).FirstOrDefault()?.SongEnId;

            if (songEnID == null)
            {
                var songs = _kouContext.Set <PluginArcaeaSong>().Where(s => s.SongTitle.Contains(songName) && s.ChartRatingClass == PluginArcaeaSong.RatingClass.Future);
                if (songs.Count() == 0)
                {
                    return($"找不到是哪个歌叫做{SongName}");
                }
                if (songs.Count() > 1)
                {
                    return($"具体是指哪首歌可以叫{songAnotherName}?\n{songs.ToSetString<PluginArcaeaSong>()}");
                }
                songEnID = songs.First().SongEnId;
            }
            var allRatingSongs = _kouContext.Set <PluginArcaeaSong>().Where(s => s.SongEnId == songEnID);


            if (_kouContext.Set <PluginArcaeaSongAnotherName>().Any(x => x.AnotherName == songAnotherName && x.SongEnId == songEnID))
            {
                return($"我之前就知道能叫{songAnotherName}了");
            }
            var    learnedList  = _kouContext.Set <PluginArcaeaSongAnotherName>().Where(x => x.SongEnId == songEnID).ToList();
            string anotherNames = "";

            if (learnedList.Count > 0)
            {
                foreach (var item in learnedList)
                {
                    anotherNames += item.AnotherName + $"({item.AnotherNameId})、";
                }
                anotherNames = anotherNames.TrimEnd('、');
            }

            PluginArcaeaSongAnotherName anotherNameModel = new PluginArcaeaSongAnotherName
            {
                AnotherName = songAnotherName,
                SongEnId    = songEnID,
            };

            foreach (var item in allRatingSongs)
            {
                PluginArcaeaSong2anothername song2Anothername = new PluginArcaeaSong2anothername
                {
                    Song        = item,
                    AnotherName = anotherNameModel,
                };
                _kouContext.Add(song2Anothername);
            }
            if (_kouContext.SaveChanges() > 0)
            {
                return($"学到许多,{allRatingSongs.First().SongTitle}可以叫做{songAnotherName}({anotherNameModel.AnotherNameId})" + (anotherNames.IsNullOrWhiteSpace() ? null : $",我还知道它能叫做{anotherNames}!"));
            }
            return("啊...不知道为什么没学会");
        }