Example #1
0
        /// <summary>
        /// The create scenario.
        /// </summary>
        /// <param name="scenario">
        /// The scenario.
        /// </param>
        public void CreateScenario(Models.Scenario scenario)
        {
            using (var dbContext = new OpenAIEntities1())
            {
                Scenario entity = dbContext.Scenarios.Find(scenario.Id);
                if (entity == null)
                {
                    entity            = new Scenario();
                    entity.ScenarioId = scenario.Id;
                    dbContext.Scenarios.Add(entity);
                }

                entity.Name     = scenario.Name;
                entity.Contents = scenario.Contents;

                // Add the features
                DataTable table    = this.ParseCsv(scenario.Contents);
                int       position = 1;
                foreach (DataColumn column in table.Columns)
                {
                    if (entity.Features.Any(f => f.FeatureId == column.ColumnName))
                    {
                        continue;
                    }

                    var feature = new Feature();
                    feature.FeatureId  = column.ColumnName;
                    feature.ScenarioId = scenario.Id;
                    feature.Position   = position++;
                    entity.Features.Add(feature);
                }

                dbContext.SaveChanges();
            }
        }
Example #2
0
        public async Task <IActionResult> AddScenario(AddScenarioViewModel scenarioData)
        {
            if (HttpContext.Session.GetInt32(UserController._UserID) < 0)
            {
                return(Redirect(UserController._LoginPath));
            }

            if (ValidateScenarioData(scenarioData))
            {
                Models.Scenario scenario = new Models.Scenario
                {
                    TimeOfEvent = scenarioData.TimeOfEvent,
                    EventURL    = scenarioData.EventURL,
                    DeviceId    = scenarioData.DeviceId
                };

                Models.Scenario.AddScenario(_context, scenario);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Controllers.DeviceController.OpenRoomDeviceList), "Device", new { area = "Device", roomID = scenarioData.RoomID }));
            }

            return(View(_ViewPath + "AddScenario"));
        }
Example #3
0
 public static void AddScenario(SmartHomeDbContext context, Models.Scenario scenario)
 {
     context.Add(scenario);
 }
Example #4
0
 public void UpdateScenarioDescription(Models.Scenario scenario)
 {
     throw new NotImplementedException();
 }
Example #5
0
 public void SelectScenario(Models.Scenario scenario)
 {
     throw new NotImplementedException();
 }