public async Task <ActionResult> Index(int acctivityID = 3) { Submission currentSubmission = await GetSubmission(acctivityID); ViewData[Constants.ActivityKey] = currentSubmission.Activity.Name; if (KnownMSPs == null) { using MSPAppContext dbLink = new MSPAppContext(); List <string> mspData = dbLink.UserData.Select(x => x.Mspmail).ToList(); CurrentSession.AddToJSONFrom <List <string> >(Constants.MSPsKey, mspData); } return(View(currentSubmission)); }
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); }