public async Task <IHttpActionResult> UpdateSample(int id, [FromBody] Delta <Sample> sample) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entity = await lstmDb.Samples.FindAsync(id); if (entity == null) { return(NotFound()); } sample.Patch(entity); try { await lstmDb.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SampleExists(id)) { return(NotFound()); } else { throw; } } return(Ok(entity)); }
public async Task <IHttpActionResult> CreateScenario([FromBody] Scenario scenario) { if (lstmDb.Scenarios.Count(e => e.name == scenario.name) > 0) { return(BadRequest("Scenario already exists")); } lstmDb.Scenarios.Add(scenario); await lstmDb.SaveChangesAsync(); Scenario temp = lstmDb.Scenarios.SingleOrDefault(e => e.name == scenario.name); return(Created("DefaultApi", temp)); }
public async Task <IHttpActionResult> CreateIntent([FromUri] string ScenarioName, [FromBody] Intent intent) { if (intent.name == null) { return(BadRequest("Without intent name")); } Scenario scenario = lstmDb.Scenarios.SingleOrDefault(e => e.name == ScenarioName); if (scenario == null) { return(BadRequest("No Such Scenario")); } if (lstmDb.Intents.Count(e => e.Scenario.name == scenario.name && e.name == intent.name) > 0) { return(BadRequest("Intent already exists")); } var mySlotDescriptions = string.IsNullOrEmpty(intent.slotDescriptions) ? new List <SlotDescription>() : JsonConvert.DeserializeObject <List <SlotDescription> >(intent.slotDescriptions); foreach (SlotDescription slotDescription in mySlotDescriptions) { if (slotDescription.name.Contains(' ')) { return(BadRequest("Slot name can't contain space")); } } //Default DateTime in database intent.lastTrainTime = Convert.ToDateTime("1900-01-01T00:00:00.000"); intent.scenarioID = scenario.id; lstmDb.Intents.Add(intent); await lstmDb.SaveChangesAsync(); intent = lstmDb.Intents.SingleOrDefault(e => e.scenarioID == scenario.id && e.name == intent.name); return(Created("DefaultApi", intent)); }