public async Task<ActionResult> Statistics() { var db = new TriviaContext(); var statisticsService = new StatisticsService(db); return View(await statisticsService.GenerateStatistics()); }
public TriviaController() { this.db = new TriviaContext(); this.questionsService = new QuestionsService(db); this.answersService = new AnswersService(db); this.statisticsService = new StatisticsService(db); }
public QuestionsService(TriviaContext db) { this.db = db; }
public OptionController(TriviaContext context) { _context = context; }
public AnswersService(TriviaContext db) { this.db = db; }
public StatisticsService(TriviaContext db) { this.db = db; }
using GeekQuiz.Models;using GeekQuiz.Services;using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Net.Http;using System.Threading.Tasks;using System.Web.Http;namespace GeekQuiz.Controllers{ [Authorize] public class TriviaController : ApiController { private TriviaContext db; private QuestionsService questionsService; private AnswersService answersService; public TriviaController() { this.db = new TriviaContext(); this.questionsService = new QuestionsService(db); this.answersService = new AnswersService(db); } public async Task<TriviaQuestion> Get() { var userId = User.Identity.Name; TriviaQuestion nextQuestion = await this.questionsService.NextQuestionAsync(userId); if (nextQuestion == null) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound)); } return nextQuestion; } public async Task<HttpResponseMessage> Post(TriviaAnswer answer) { if (ModelState.IsValid) { answer.UserId = User.Identity.Name; var isCorrect = await this.answersService.StoreAsync(answer); return Request.CreateResponse(HttpStatusCode.Created, isCorrect); } else { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } } protected override void Dispose(bool disposing) { this.db.Dispose(); base.Dispose(disposing); } }}
public StatisticsController() { this.db = new TriviaContext(); this.statisticsService = new StatisticsService(db); }