コード例 #1
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("啊...不知道为什么没学会");
        }
コード例 #2
0
ファイル: RomajiHelper.cs プロジェクト: Euynac/Koubot.Plugin
        /// <summary>
        /// 删除罗马音-谐音键值对
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeletePair(int id)
        {
            var pair = kouContext.Set <RomajiPair>().SingleOrDefault(x => x.Id == id);

            if (pair == null)
            {
                return(false);
            }
            kouContext.Remove(pair);
            RomajiToZhDict.Remove(pair.RomajiKey);
            return(kouContext.SaveChanges() > 0);
        }