Beispiel #1
0
        public async Task <BindingStatus> AddBinding(string username, IMessageChannel channel)
        {
            if (string.IsNullOrEmpty((await twitterSession.GetUserProfile(username)).Name))
            {
                return(BindingStatus.Error);
            }
            using (var db = new TwitterContext(dbOptions))
            {
                var twitterBinding = new TwitterBinding
                {
                    TwitterUsername = username.ToLower(),
                    LatestPost      = DateTime.UtcNow,
                };

                if (db.TwitterChannelBindings.Any(b => b.ChannelId == channel.Id && b.TwitterBinding.TwitterUsername == twitterBinding.TwitterUsername))
                {
                    return(BindingStatus.AlreadyExists);
                }

                db.TwitterChannelBindings.Add(new TwitterChannelBinding
                {
                    TwitterBinding = twitterBinding,
                    ChannelId      = channel.Id,
                });

                await db.SaveChangesAsync();

                return(BindingStatus.Added);
            }
        }