public bool ValidateScenarioData(AddScenarioViewModel scenarioData) { if (!ModelState.IsValid) { return(false); } string scenario; try { using (var wc = new System.Net.WebClient()) scenario = wc.DownloadString(scenarioData.EventURL); } catch { return(false); } string[] lines = scenario.Split(new char[] { '\n', '\r', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (lines.Length < 2 || !lines[0].Equals("SHScript")) { return(false); } return(true); }
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")); }