public async Task <IActionResult> AddStepAt(string id, int at, [FromBody] Models.Post.Step model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var db = RavenStore.Store.OpenAsyncSession()) { var test = await db.LoadAsync <Models.Raven.Test>($"tests/{id}"); if (test == null) { return(NotFound()); } try { test.Steps.Insert(at, new Models.Raven.Test.Step() { Description = model.description }); } catch (ArgumentOutOfRangeException e) { return(BadRequest(new { message = "at index is out of range of the list of steps" })); } await db.SaveChangesAsync(); return(NoContent()); } }
public async Task <IActionResult> AddStep(string id, [FromBody] Models.Post.Step model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (var db = RavenStore.Store.OpenAsyncSession()) { var test = await db.LoadAsync <Models.Raven.Test>($"tests/{id}"); if (test == null) { return(NotFound()); } test.Steps.Add(new Models.Raven.Test.Step() { Description = model.description }); await db.SaveChangesAsync(); return(NoContent()); } }