コード例 #1
0
ファイル: ContextService.cs プロジェクト: TulgaLisitsa/YTBot
        public Trigger SaveTrigger(Trigger trigger, BotChannelSettings bcs)
        {
            if (trigger.Id == 0)
            {
                if (bcs.Triggers.Any(t => t.TriggerName.ToLower().Equals(trigger.TriggerName.ToLower())))
                {
                    throw new Exception("Triggername already in triggerlist: " + trigger.TriggerName);
                }
                bcs.Triggers.Add(trigger);
            }
            else
            {
                var dbTrigger = bcs.Triggers.SingleOrDefault(t => t.Id == trigger.Id);

                dbTrigger.Active             = trigger.Active;
                dbTrigger.TriggerName        = trigger.TriggerName;
                dbTrigger.TriggerResponse    = trigger.TriggerResponse;
                dbTrigger.ModCanTrigger      = trigger.ModCanTrigger;
                dbTrigger.ViewerCanTrigger   = trigger.ViewerCanTrigger;
                dbTrigger.StreamerCanTrigger = trigger.StreamerCanTrigger;
                dbTrigger.SubCanTrigger      = trigger.SubCanTrigger;
                dbTrigger.TriggerType        = trigger.TriggerType;
            }

            Context.SaveChanges();

            return(trigger);
        }
コード例 #2
0
        public BotChannelSettings SetBotChannelSettings(BotChannelSettings botChannelSettings, ApplicationUser user)
        {
            var settings = GetBotChannelSettings(user);

            if (settings == null)
            {
                // create new
                Context.BotChannelSettings.Add(botChannelSettings);
            }
            else
            {
                Context.BotChannelSettings.AddOrUpdate(b => b.Id == botChannelSettings.Id, botChannelSettings);
            }

            Context.SaveChanges();

            return(botChannelSettings);
        }
コード例 #3
0
        public BotChannelSettings SetInitialBotChannelSettings(ApplicationUser user)
        {
            // Check that the user has BotChannelSettings
            if (GetBotChannelSettings(user) == null)
            {
                var bcs = new BotChannelSettings()
                {
                    User          = GetUser(user.UserName),
                    StreamViewers = new List <StreamViewer>(),
                    Timers        = new List <Timer>(),
                    Triggers      = new List <Trigger>(),
                    Loyalty       = new Loyalty(),
                    StreamGame    = "",
                    StreamTitle   = ""
                };
                Context.BotChannelSettings.Add(bcs);
                Context.SaveChanges();
                return(bcs);
            }

            return(null);
        }