public async Task <IActionResult> PostBulletPage([FromBody] BulletPage bulletPage) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.BulletPages.Add(bulletPage); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (BulletPageExists(bulletPage.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetBulletPage", new { id = bulletPage.Id }, bulletPage)); }
public async Task <IActionResult> PutMultipleChoiceQuestion([FromRoute] int id, [FromBody] MultipleChoiceQuestion multipleChoiceQuestion) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != multipleChoiceQuestion.Id) { return(BadRequest()); } _context.Entry(multipleChoiceQuestion).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MultipleChoiceQuestionExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> CreateBulletForBulletPage([FromBody] BulletDTO bulletDTO, [FromRoute] int bulletPageId) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (bulletDTO.Id != 0 || bulletPageId == 0) { return(BadRequest()); } if (!_context.BulletPages.Any(bp => bp.Id == bulletPageId)) { return(NotFound()); } var bulletPage = _context.BulletPages.FirstOrDefault(bp => bp.Id == bulletPageId); var bullet = _mapper.Map <BulletDTO, Bullet>(bulletDTO); bulletPage.Bullets.Add(bullet); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (BulletExists(bulletDTO.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } } return(Ok(bulletDTO)); }
public async Task <IActionResult> PostFlashcard([FromBody] Flashcard flashcard) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Flashcards.Add(flashcard); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (FlashcardExists(flashcard.Id)) { return(new StatusCodeResult(StatusCodes.Status409Conflict)); } else { throw; } } return(CreatedAtAction("GetFlashcards", new { id = flashcard.Id }, flashcard)); }