//add another version of this and and if statement in the controller that accesses one or the other depending on the type of user (admin vs player) public QuestionDetail GetQuestionById(int id) { var asvc = new AnswerService(); using (var ctx = new ApplicationDbContext()) { if (!_userService.ConfirmUserIsAdmin(_userId.ToString())) { var playerEntity = ctx .Questions .Single(e => e.Id == id && e.AuthorId == _userId.ToString()); return (new QuestionDetail { Id = playerEntity.Id, Text = playerEntity.Text, Category = playerEntity.Category, GameVersion = playerEntity.Version, Author = playerEntity.Author, IsUserGenerated = playerEntity.IsUserGenerated, Answers = playerEntity.Answers }); } var adminEntity = ctx .Questions .Single(e => e.Id == id); return (new QuestionDetail { Id = adminEntity.Id, Text = adminEntity.Text, Category = adminEntity.Category, GameVersion = adminEntity.Version, Author = adminEntity.Author, IsUserGenerated = adminEntity.IsUserGenerated, Answers = adminEntity.Answers }); } }
public QuestionDetail GetQuestionByIdForGame(int?id) { var asvc = new AnswerService(); using (var ctx = new ApplicationDbContext()) { var entity = ctx .Questions .Single(e => e.Id == id); return (new QuestionDetail { Id = entity.Id, Text = entity.Text, Category = entity.Category, GameVersion = entity.Version, Author = entity.Author, IsUserGenerated = entity.IsUserGenerated, Answers = entity.Answers }); } }