public bool UpdateAnswer(TwoButtonsContext context, int userId, int questionId, AnswerType answerType) { var answered = DateTime.Now; // var m = context.AnswerEntities.ToList(); // var t = m; context.AnswerEntities.Add(new AnswerEntity { AnswerType = answerType, QuestionId = questionId, UserId = userId }); // var p = context.AnswerEntities.ToList(); // var y = p; return(context.SaveChanges() > 0); //return await _context.Database.ExecuteSqlCommandAsync( // $"updateAnswer {userId}, {questionId}, {answerType}, {answered}") > 0; }
public async Task <bool> UpdateAnswer(int userId, int questionId, AnswerType answerType) { var answer = _db.AnswerEntities.FirstOrDefault(x => x.UserId == userId && x.QuestionId == questionId); if (answer == null) { answer = new AnswerEntity { UserId = userId, QuestionId = questionId, FeedbackType = QuestionFeedbackType.Neutral, IsDeleted = false, AnswerType = answerType, AnsweredDate = DateTime.UtcNow, IsFavorite = false, IsSaved = false }; _db.AnswerEntities.Add(answer); } answer.AnswerType = answerType; return(_db.SaveChanges() > 0); }