public async Task <int> DeleteJobConfigs(IEnumerable <decimal> channelIds) { var jobConfigs = channelIds.Select(s => new JobConfig { ChannelId = s }).ToList(); JobConfigs.AttachRange(jobConfigs); JobConfigs.RemoveRange(jobConfigs); await SaveChangesAsync(); return(jobConfigs.Count); }
public async Task <JobConfigContainer> SetJobConfig(decimal channelId, JobConfigContainer jobConfigContainer) { JobConfig jobConfig; var match = await JobConfigs.SingleOrDefaultAsync(s => s.ChannelId == channelId); if (match != null) //already exists, so mutate it { jobConfig = match; match.Interval = jobConfigContainer.Interval; match.Time = jobConfigContainer.Time; match.IntervalMinutes = DetermineIntervalMinutes(jobConfigContainer); match.RandomSearchString = jobConfigContainer.RandomSearchString; match.MinQuietHour = jobConfigContainer.MinQuietHour; match.MaxQuietHour = jobConfigContainer.MaxQuietHour; match.Prefix = jobConfigContainer.Prefix; } else //new item { jobConfig = new JobConfig { ChannelId = channelId, Interval = jobConfigContainer.Interval, Time = jobConfigContainer.Time, IntervalMinutes = DetermineIntervalMinutes(jobConfigContainer), RandomSearchString = jobConfigContainer.RandomSearchString, MinQuietHour = jobConfigContainer.MinQuietHour, MaxQuietHour = jobConfigContainer.MaxQuietHour, Prefix = jobConfigContainer.Prefix }; JobConfigs.Add(jobConfig); } await SaveChangesAsync(); return(new JobConfigContainer { ChannelId = jobConfig.ChannelId, Interval = jobConfig.Interval, Time = jobConfig.Time, RandomSearchString = jobConfig.RandomSearchString, MinQuietHour = jobConfig.MinQuietHour, MaxQuietHour = jobConfig.MaxQuietHour, Prefix = jobConfig.Prefix }); }
public async Task <JobConfigContainer> GetJobConfig(decimal id) { var jobConfig = await JobConfigs.Where(s => s.ChannelId == id).Select(s => new JobConfigContainer { ChannelId = s.ChannelId, Interval = s.Interval, Time = s.Time, RandomSearchString = s.RandomSearchString, MinQuietHour = s.MinQuietHour, MaxQuietHour = s.MaxQuietHour, Prefix = s.Prefix }).SingleOrDefaultAsync(); if (jobConfig != null) { return(jobConfig); } return(new JobConfigContainer { ChannelId = id }); }