// POST: api/courses public IHttpActionResult Postcourse(EmberWrapper course) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Course newCourse = new Course { Name = course.Course.Name, }; db.Courses.Add(newCourse); try { db.SaveChanges(); } catch (DbUpdateException) { if (courseExists(newCourse.Id)) { return Conflict(); } else { throw; } } return Ok(new { course = newCourse }); }
// POST: api/cardSets public IHttpActionResult PostcardSet(EmberWrapper wrappedCardSet) { if (!ModelState.IsValid) { return BadRequest(ModelState); } CardSet newCardSet = new CardSet { Name = wrappedCardSet.CardSet.Name, Course = db.Courses.Find(wrappedCardSet.CardSet.Course) }; db.CardSets.Add(newCardSet); db.SaveChanges(); wrappedCardSet.CardSet.Course = newCardSet.Course.Id; wrappedCardSet.CardSet.Id = newCardSet.Id; return Ok(new { cardSet = wrappedCardSet.CardSet }); }
public object PostCard(EmberWrapper wrappedCard) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Card newCard = new Card { FrontText = wrappedCard.Card.FrontText, BackText = wrappedCard.Card.BackText, CardSet = db.CardSets.Find(wrappedCard.Card.CardSet) }; db.Cards.Add(newCard); db.SaveChanges(); wrappedCard.Card.CardSet = newCard.CardSet.Id; wrappedCard.Card.Id = newCard.Id; return new { card = wrappedCard.Card }; }