예제 #1
0
        /// <summary>
        /// Add Channel to a given user (based on channel Link)
        /// </summary>
        /// <param name="user">User to which channel will be added</param>
        /// <param name="channelLink">Link to a channel</param>
        /// <param name="saveToDb">Save changes to database or not</param>
        public void AddUserChannel(User user, string channelLink, bool saveToDb = true)
        {
            var channel = _dbContext.Channels.Create();

            channel.Link        = channelLink;
            channel.ChannelName = _yt.ChannelDisplayNameByChannelUrl(channelLink);
            _dbContext.Channels.Add(channel);

            user.Channels.Add(channel);
            if (saveToDb)
            {
                _dbContext.SaveChanges();
            }
        }
예제 #2
0
        /// <summary>
        /// Add Channel to a given user (based on channel Link)
        /// </summary>
        /// <param name="user">User to which channel will be added</param>
        /// <param name="channelLink">Link to a channel</param>
        /// <param name="saveToDb">Save changes to database or not</param>
        public void AddUserChannel(User user, string channelLink, bool saveToDb = true)
        {
            var channel = new Channel {
                Link        = channelLink,
                ChannelName = _yt.ChannelDisplayNameByChannelUrl(channelLink)
            };

            _dbContext.Channels.Add(channel);

            var currentUser = _dbContext.Users.SingleOrDefault(u => u.UserId == user.UserId);

            currentUser?.Channels.Add(channel);

            if (saveToDb)
            {
                _dbContext.SaveChanges();
            }
        }