Beispiel #1
0
        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));
        }
Beispiel #2
0
 // GET: Scheduling/Form/:id
 public ActionResult Form(int?id)
 {
     Models.ScheduleAddVM model = null;
     if (id != null)
     {
         IDeviceScenarioService deviceScenarioService = DependencyUtils.Resolve <IDeviceScenarioService>();
         IDeviceService         deviceService         = DependencyUtils.Resolve <IDeviceService>();
         IScenarioService       scenarioService       = DependencyUtils.Resolve <IScenarioService>();
         var item = deviceScenarioService.Get(id);
         if (item != null)
         {
             model = new Models.ScheduleAddVM
             {
                 ScenarioID       = item.ScenarioID,
                 DeviceScenarioId = item.DeviceScenationID,
                 DeviceID         = item.DeviceID,
                 isHorizontal     = scenarioService.GetScenarioOrientationById(item.ScenarioID) ?? true,
                 isFixed          = item.TimesToPlay == null,
                 StartTime        = item.StartTime,
                 TimeToPlay       = item.TimesToPlay,
                 EndTime          = item.EndTime,
                 LayoutID         = item.LayoutID,
             };
         }
     }
     return(View(model));
 }
Beispiel #3
0
        public async System.Threading.Tasks.Task <ActionResult> Update(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;
                }
                var schedule = deviceScenarioService.Get(model.DeviceScenarioId);
                if (schedule != null)
                {
                    schedule.ScenarioID  = model.ScenarioID;
                    schedule.DeviceID    = model.DeviceID;
                    schedule.EndTime     = model.EndTime;
                    schedule.StartTime   = model.StartTime;
                    schedule.TimesToPlay = model.TimeToPlay;
                }
                await deviceScenarioService.UpdateAsync(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));
        }