// create a new scene public JsonResult AddNewScene(string user, [FromBody] CreateSceneRequest newScene) { // authentication if (!_grp.AuthenticatorInstance.IsValidUser(user)) { return(Json(_grp.AuthenticatorInstance.ErrorResponse(Request.Path.ToString()))); } // parameter check // verify that lights given by parameters are all known to us var lights = _grp.DatabaseInstance.GetCollection <Light>("lights"); var lightsInGroup = new LiteDB.BsonArray(); var count = lights.Count(x => newScene.Lights.Contains(x.Id.ToString())); if (count != newScene.Lights.Count) { return(Json(new List <Dictionary <string, object> > { new Dictionary <string, object> { ["failure"] = "Trying to add a non-existent light id into group" } })); } // insert new scene var scene = new Scene { Name = newScene.Name, Recycle = newScene.Recycle, Picture = newScene.Picture ?? "", Lights = newScene.Lights, Appdata = newScene.AppData, Type = newScene.Type ?? "LightScene", Version = 2, Owner = user, Lastupdated = DateTime.UtcNow, LightStates = new Dictionary <string, GroupAction>() }; var scenes = _grp.DatabaseInstance.GetCollection <Scene>("scenes"); var id = scenes.Insert(scene); return(Json(new List <Dictionary <string, object> > { new Dictionary <string, object> { ["success"] = new Dictionary <string, string> { ["id"] = $"{id}" } } })); }
private Task CreateTemporaryScene() { var request = new CreateSceneRequest { Parameters = new CreateSceneParameters { Name = "tmp scene", LightIds = new[] { 2, 3, 4 } } }; return(_client.GetResponseAsync(request).ContinueWith(p => { var response = p.Result; Assert.True(response is SuccessResponse); _sceneId = request.Parameters.SceneId; })); }
public async Task CreateSceneTest() { var request = new CreateSceneRequest { Parameters = new CreateSceneParameters { Name = "tmp scene", AppData = new SceneApplicationData { Data = "temporary scene", Version = 1 }, LightIds = new[] { 2, 3, 4 }, TransitionTime = TimeSpan.FromMilliseconds(100) } }; OnLog(await _client.GetResponseAsync(request)); Assert.True(!string.IsNullOrEmpty(request.Parameters.SceneId)); DeleteTemporaryScene(request.Parameters.SceneId).Wait(); }