private async Task <Submission> GetSubmission(int activityID = 3) { Submission currentSubmission = CurrentSession.GetFromJSONTo <Submission>(Constants.SubmissionKey); if (currentSubmission == null) { (User graphUser, _) = await GetGraphUserData(); UserData currentUser = await graphUser.ToDBObject(); using MSPAppContext dbLink = new MSPAppContext(); ActivityType currentActivity = dbLink.ActivityType.FirstOrDefault( x => x.Id == activityID); List <ActivityDetails> details = dbLink.ActivityDetails.Where( x => x.ActivityId == activityID).ToList(); int submissionID = dbLink.Submission.Count(); int startingID = dbLink.SubmissionDetail.Count(); currentSubmission = new Submission { Id = submissionID, UserId = currentUser.Id, ActivityId = activityID, AnythingElse = "", SubmissionDetail = details.Select( x => new SubmissionDetail { SubmissionId = submissionID, ActivityDetailId = x.Id, Id = startingID++, Value = "" }).ToList(), Details = details.Select(x => "").ToList() }; dbLink.Submission.Add(currentSubmission); await dbLink.SaveChangesAsync(); currentSubmission = dbLink.Submission.FirstOrDefault(x => x.Id == submissionID); CurrentSession.AddToJSONFrom(Constants.SubmissionKey, currentSubmission); } return(currentSubmission); }