/// <summary>
        /// 添加UserLike
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="objId"></param>
        /// <param name="type"></param>
        public void Create(int userId, int objId, MusicRequestType type)
        {
            var user = _userManager.Find(userId);

            if (user.IsAdmin)
            {
                ThrowException("用户不存在!");
            }
            UserLike userLike = null;

            switch (type)
            {
            case MusicRequestType.Song:
                var music = _musicManager.Find(objId);
                if (!music.IsPublished)
                {
                    ThrowException("歌曲不存在!");
                }
                if (JMDbContext.UserLike.Any(u => u.UserId == userId && u.MusicId == objId))
                {
                    ThrowException("您的喜好歌曲中已存在该歌曲,无需重复添加");
                }
                userLike = new UserLike()
                {
                    UserId  = userId,
                    MusicId = objId,
                };
                break;

            default:
                return;
            }
            Create(userLike);
            Save();
        }
Ejemplo n.º 2
0
        public void AddToUserMusicList(int userId, int objId, int userMusicListId, MusicRequestType type)
        {
            var user = _userManager.Find(userId);

            if (user == null || user.IsAdmin)
            {
                ThrowException("用户不存在");
            }

            UserMusicList list = JMDbContext.UserMusicList.SingleOrDefault(u => u.Id == userMusicListId && u.UserId == userId && !u.IsDeleted);

            if (list == null)
            {
                ThrowException("未找到该用户的歌单");
            }

            switch (type)
            {
            case MusicRequestType.Song:
                var music = _musicManager.Find(objId);
                if (music == null || !music.IsPublished)
                {
                    ThrowException("歌曲不存在");
                }
                var listMusic = new UserMusicListMusic()
                {
                    MusicId     = music.Id,
                    MusicListId = list.Id
                };
                JMDbContext.UserMusicListMusic.Add(listMusic);
                break;

            default:
                return;
            }
            Save();
        }