public IActionResult SaveEntry([FromBody] UserSelectionsForCreationDto entry) { bool resp = _quizRepository.SaveEntryForQuestion(entry); if (!_quizRepository.Save()) { throw new Exception($"Creating entry failed on save."); } return(Ok(resp)); }
public bool SaveEntryForQuestion([FromBody] UserSelectionsForCreationDto selection) { var noUserEntries = _context.Entries.Where(u => u.UserId == selection.UserId).ToList().Count(); if (noUserEntries > Convert.ToInt32(Configuration.GetConnectionString("totalNoOfQuizes"))) { throw new Exception($"Total number of entry for user exceeded"); } var isUserSelectionCorrect = CheckEntryForUser(selection.Selection, selection.QuestionId); var entry = new Entry() { Id = Guid.NewGuid(), QuestionId = selection.QuestionId, UserId = selection.UserId, Correct = isUserSelectionCorrect }; _context.Entries.Add(entry); return(isUserSelectionCorrect); }