public async Task <PredictionHouseDB.Questions> AddQuestion(PredictionHouseDB.Questions newQuestion) { PredictionHouseDB.Questions addedQ = null; try { addedQ = await _dbContext .Questions .SingleOrDefaultAsync(x => x.Question == newQuestion.Question && x.Year == newQuestion.Year); if (addedQ == null) { var newQ = new PredictionHouseDB.Questions(newQuestion.Question, newQuestion.Year, newQuestion.Answer); var addedResponse = await _dbContext.AddAsync(newQ); await _dbContext.SaveChangesAsync(); addedQ = addedResponse.Entity; } } catch (Exception ex) { Console.WriteLine("Error saving new question to DB: {0}", ex.Message); addedQ = null; } return(addedQ); }
public async Task <PredictionHouseDB.Questions> GetQuestionByIDAsync(int id) { PredictionHouseDB.Questions dbQuestions = await _dbContext .Questions .SingleOrDefaultAsync(x => x.QuestionId == id); return(dbQuestions); }
public async Task <PredictionHouseDB.Questions> AddQuestion(PredictionHouseDB.Questions newQuestion) { var questionAccessor = new QuestionAccessor(_dbContext); PredictionHouseDB.Questions addedQ = await questionAccessor.AddQuestion(newQuestion); return(addedQ); }
public async Task <PredictionHouseDB.Questions> GetQuestionByIDAsync(int id) { var questionAccessor = new QuestionAccessor(_dbContext); PredictionHouseDB.Questions question = await questionAccessor.GetQuestionByIDAsync(id); return(question); }
public async Task <ActionResult <PredictionHouseDB.Questions> > PostQuestion(PredictionHouseDB.Questions newQuestion) { PredictionHouseDB.Questions addedQ = await questionManager.AddQuestion(newQuestion); if (addedQ != null) { string uriStr = "api/questions/" + addedQ.QuestionId.ToString(); return(Created(uriStr, addedQ)); } else { return(BadRequest()); } }
public async Task <ActionResult <PredictionHouseDB.Questions> > GetQuestionByID(int id) { PredictionHouseDB.Questions question = await questionManager.GetQuestionByIDAsync(id); return(Ok(question)); }