static int?DetermineIntervalMinutes(JobConfigContainer jobConfigContainer)
 {
     if (!jobConfigContainer.Interval.HasValue || string.IsNullOrEmpty(jobConfigContainer.Time))
     {
         return(null);
     }
     if (jobConfigContainer.Time == "Hour" || jobConfigContainer.Time == "Hours")
     {
         return(jobConfigContainer.Interval.Value * 60);
     }
     return(jobConfigContainer.Interval.Value);
 }
        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
            });
        }