public async System.Threading.Tasks.Task <ActionResult> Add(Models.ScheduleAddVM model) { IDeviceScenarioService deviceScenarioService = DependencyUtils.Resolve <IDeviceScenarioService>(); if (ModelState.IsValid && CheckTimeValid(model.DeviceID, model.StartTime, model.EndTime)) { if (model.isFixed) { model.TimeToPlay = null; } else { model.EndTime = null; } IScenarioService scenarioService = DependencyUtils.Resolve <IScenarioService>(); var schedule = new Data.Models.Entities.DeviceScenario { ScenarioID = model.ScenarioID, DeviceID = model.DeviceID, TimesToPlay = model.TimeToPlay, StartTime = model.StartTime, EndTime = model.EndTime, LayoutID = scenarioService.GetLayoutIDById(model.ScenarioID), }; await deviceScenarioService.CreateAsync(schedule); return(new ContentResult { Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "Scheduling")), ContentType = "text/html" }); } return(View("Form", model)); }
public async System.Threading.Tasks.Task <ActionResult> Update(Models.AdvancedScheduleAddVM model) { IScheduleService scheduleService = DependencyUtils.Resolve <IScheduleService>(); IScenarioService scenarioService = DependencyUtils.Resolve <IScenarioService>(); if (ModelState.IsValid) { var schedule = scheduleService.Get(model.ScheduleID); int dayFilter = 0; int timeFilter = 0; foreach (var item in model.DayFilter) { dayFilter += item; } foreach (var item in model.TimeFilter) { timeFilter += item; } if (schedule != null) { schedule.ScenarioID = model.ScenarioID; schedule.DeviceID = model.DeviceID; schedule.LayoutID = scenarioService.GetLayoutIDById(model.ScenarioID); schedule.DayFilter = dayFilter; schedule.TimeFilter = timeFilter; schedule.Priority = model.Priority; schedule.isEnable = model.isEnable; await scheduleService.UpdateAsync(schedule); Session.Clear(); Session["UPDATE_RESULT"] = true; } return(new ContentResult { Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "AdvancedScheduling")), ContentType = "text/html" }); } return(View("Form", model)); }
public async System.Threading.Tasks.Task <ActionResult> Add(Models.AdvancedScheduleAddVM model) { IScheduleService scheduleService = DependencyUtils.Resolve <IScheduleService>(); if (ModelState.IsValid) { int dayFilter = 0; int timeFilter = 0; foreach (var item in model.DayFilter) { dayFilter += item; } foreach (var item in model.TimeFilter) { timeFilter += item; } IScenarioService scenarioService = DependencyUtils.Resolve <IScenarioService>(); var schedule = new Data.Models.Entities.Schedule { ScenarioID = model.ScenarioID, DeviceID = model.DeviceID, LayoutID = scenarioService.GetLayoutIDById(model.ScenarioID), DayFilter = dayFilter, TimeFilter = timeFilter, Priority = model.Priority, isEnable = model.isEnable, }; await scheduleService.CreateAsync(schedule); Session.Clear(); Session["ADD_RESULT"] = true; return(new ContentResult { Content = string.Format("<script type='text/javascript'>window.parent.location.href = '{0}';</script>", Url.Action("Index", "AdvancedScheduling")), ContentType = "text/html" }); } return(View("Form", model)); }