private int?SelectedAnswere(int questionId, int takeId) { TakedAnswer takedAnswer = this.takedAnswerRepository.All().Where(x => x.QuestionId == questionId && x.TakeId == takeId).FirstOrDefault(); if (takedAnswer != null) { return(takedAnswer.AnswerId); } return(null); }
public async Task SaveTakedAnswerAsync(string userId, int questionId, int answerId) { Take take = this.GetTake(userId); TakedAnswer takedAnswer = this.takedAnswerRepository.All().Where(x => x.QuestionId == questionId && x.TakeId == take.Id).FirstOrDefault(); if (takedAnswer != null) { this.takedAnswerRepository.All().FirstOrDefault(x => x.TakeId == take.Id && x.QuestionId == questionId).AnswerId = answerId; } else { take.TakedAnswers.Add(new TakedAnswer { QuestionId = questionId, AnswerId = answerId }); } this.takeRepository.Update(take); await this.takeRepository.SaveChangesAsync(); }