New to MVC. I did the tutorial @ [http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/build-a-single-page-application-(spa)-with-aspnet-web-api-and-angularjs] and from this you produce a question and answer website. If I wanted to maintain progress i.e. keep a count of the number of questions correctly answered, do I need to calculate this value from retrieving the db.TriviaAnswers object or do I need to add a Count property to the TriviaAnswer class or do I need a separate variable then how do I maintain state between requests? Like ViewBag is not available in the
public async Task<IHttpActionResult> Post(TriviaAnswer answer){...}
method.
OPTION 1 as suggested below:
namespace GeekQuiz.Models
{
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
public class TriviaResults
{
[Required, Key, Column(Order=1)]
public string UserId { get; set; }
[Required, Key, Column(Order=0)]
public virtual int QuestionId { get; set; }
}
}
This code throws an InvalidOperationException in the method:
private async Task<TriviaQuestion> NextQuestionAsync(string userId)
on the first line of code.
lastQuestionId = ...