public HttpResponseMessage SetConfig(ConfigModel configModel) { if (!ModelState.IsValid || configModel == null) return Request.CreateResponse(HttpStatusCode.BadRequest); var scheduledTasks = new List<ScheduledTaskDto>(); var config = AdminManager.GetConfig().UpdateConfigFromModel(configModel); // update scheduled tasks or create new foreach (var scheduledTaskModel in configModel.ScheduledTasks) { var scheduledTask = AdminManager.GetScheduledTask(scheduledTaskModel); if (scheduledTask == null) { scheduledTask = new ScheduledTaskDto(scheduledTaskModel); } else { scheduledTask.UpdateScheduledTaskFromModel(scheduledTaskModel); } scheduledTasks.Add(scheduledTask); } AdminManager.Save(config, scheduledTasks); return new HttpResponseMessage(HttpStatusCode.Accepted); }
public ConfigDto UpdateConfigFromModel(ConfigModel model) { YoutubeApiKey = model.YoutubeApiKey; return this; }