Ejemplo n.º 1
0
 internal async Task UpdateCacheAsync()
 {
     using (var context = new ChannelImplementationContext())
     {
         _implementationItemsCache = context.ImplementationItems.ToList();
     }
 }
Ejemplo n.º 2
0
        internal async Task SetupChannel(SocketGuild server, string channelName, string groupName, LinkAction action)
        {
            var textChannel = server.TextChannels.FirstOrDefault();
            var role        = server.Roles.FirstOrDefault(_ => groupName.ToLower().Contains(_.Name.ToLower()) || _.Name.ToLower().Contains(groupName.ToLower()));
            var channel     = server.VoiceChannels.FirstOrDefault(_ => channelName.ToLower().Contains(_.Name.ToLower()) || _.Name.ToLower().Contains(channelName.ToLower()));

            if (role != null && action != LinkAction.None)
            {
                using (var context = new ChannelImplementationContext())
                {
                    using (var dbContextTransaction = context.Database.BeginTransaction())
                    {
                        context.ImplementationItems.Load();
                        var ExistImplementations = ((IQueryable <ImplementationItem>)context.ImplementationItems).Where(_ => _.ServerId == server.Id && _.ChannelId == channel.Id);
                        var roleImplementation   = ExistImplementations?.FirstOrDefault(_ => _.GroupId == role.Id);

                        if (action == LinkAction.Link)
                        {
                            if (roleImplementation == null)
                            {
                                context.ImplementationItems.Add(new ImplementationItem()
                                {
                                    ChannelId = channel.Id,
                                    GroupId   = role.Id,
                                    ServerId  = server.Id
                                });
                            }
                            else
                            {
                                roleImplementation.ChannelId = channel.Id;
                                roleImplementation.GroupId   = role.Id;
                                roleImplementation.ServerId  = server.Id;

                                context.ImplementationItems.Update(roleImplementation);
                            }
                        }
                        else
                        {
                            if (roleImplementation != null)
                            {
                                context.ImplementationItems.Remove(roleImplementation);
                            }
                        }

                        context.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    await textChannel.SendMessageAsync("Acknowlenged!").ConfigureAwait(false);
                }
            }
        }