public async Task <PredictionHouseDB.Responses> AddResponseAsync(PredictionHouseDB.Responses newResponse) { PredictionHouseDB.Responses addedResponse = null; try { addedResponse = await _dbContext .Responses .SingleOrDefaultAsync(x => x.RespondentId == newResponse.RespondentId && x.QuestionId == newResponse.QuestionId); if (addedResponse == null) { var newR = new PredictionHouseDB.Responses(newResponse.ResponseId, newResponse.QuestionId, newResponse.RespondentId, newResponse.Response, newResponse.Correct); var addedR = await _dbContext.AddAsync(newR); await _dbContext.SaveChangesAsync(); addedResponse = addedR.Entity; } else { addedResponse = null; } } catch (Exception ex) { Console.WriteLine("Error saving new response to DB: {0}", ex.Message); addedResponse = null; } return(addedResponse); }
public async Task <PredictionHouseDB.Responses> AddResponseAsync(PredictionHouseDB.Responses newResponse) { var responsesAccessor = new ResponsesAccessor(_dbContext); PredictionHouseDB.Responses addedResponse = await responsesAccessor.AddResponseAsync(newResponse); return(addedResponse); }
public async Task <ActionResult <PredictionHouseDB.Responses> > PostResponse(PredictionHouseDB.Responses newResponse) { PredictionHouseDB.Responses addedResponse = await responsesManager.AddResponseAsync(newResponse); if (addedResponse != null) { string uriStr = "api/responses/" + addedResponse.ResponseId.ToString(); return(Created(uriStr, addedResponse)); } else { return(BadRequest()); } }