public IHttpActionResult Post(TestDetailsResponseModel model) { var currentUser = this.users .All() .FirstOrDefault(u => u.UserName == this.User.Identity.Name); var newTest = new Test { CourseId = model.CourseId }; this.tests.Add(newTest); this.tests.SaveChanges(); return this.Ok(newTest.Id); }
public IHttpActionResult Create(TestModel test) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var newTest = new Test { }; this.db.Tests.Add(newTest); this.db.SaveChanges(); test.TestId = newTest.Id; return Ok(newTest); }
public IHttpActionResult Update(int id, Test test) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var existingTest = GetTestById(id); if (existingTest == null) { return BadRequest(NoSuchId); } this.db.SaveChanges(); test.Id = existingTest.Id; return Ok(test); }