public ActionResult CreateSubmission(Guid AssessmentID, Guid MembershipID, double Score, DateTime SubmissionDate)
        {
            try
            {
                Assessment assessment = dataRepository.GetAssessmentByID(courseTerm, AssessmentID);
                if (assessment == null)
                {
                    return View("AssessmentNotFound");
                }

                SubmissionRecord record = new SubmissionRecord();
                assessment.SubmissionRecords.Add(record);
                record.GradedBy = UserHelpers.GetCurrentUserID();
                record.GradedOn = DateTime.Now;
                record.StudentID = MembershipID;
                record.SubmissionDate = SubmissionDate;

                foreach (var answer in assessment.Answers)
                {
                    AssessTrack.Models.Response response = new Response();
                    response.Score = (Score / 100.0) * answer.Weight;
                    response.AnswerID = answer.AnswerID;
                    response.ResponseText = "n/a";
                    record.Responses.Add(response);
                }

                dataRepository.Save();
            }
            catch (Exception)
            {
                ModelState.AddModelError("_FORM", "An error occurred while creating the submission.");
                List<Profile> students = dataRepository.GetStudentProfiles(courseTerm);
                List<Assessment> assessments = dataRepository.GetAllNonTestBankAssessments(courseTerm);

                CreateSubmissionViewModel model = new CreateSubmissionViewModel(students,assessments);

                return View(model);
            }
            FlashMessageHelper.AddMessage("Score added successfully!");
            return RedirectToRoute(new { siteShortName = site.ShortName, courseTermShortName = courseTerm.ShortName, action = "Index", controller = "SubmissionRecord" });
        }
        public ActionResult Submit(string courseTermShortName, string siteShortName, Guid id, FormCollection collection)
        {
            Assessment assessment = dataRepository.GetAssessmentByID(courseTerm, id);
            if (assessment == null || !assessment.IsVisible)
                return View("AssessmentNotFound");
            if (!assessment.AllowMultipleSubmissions && dataRepository.HasUserSubmittedAssessment(assessment) && !AssessmentHelpers.StudentHasExtension(assessment, UserHelpers.GetCurrentUserID())) //Exceptions allow students to submit multiple times
            {
                return View("AlreadySubmitted");
            }
            if (DateTime.Now.Subtract(assessment.DueDate).TotalSeconds > 0)
            {
                if (!AssessmentHelpers.StudentHasExtension(assessment, UserHelpers.GetCurrentUserID()))
                {
                    return View("DueDatePassed");
                }
            }
            if (!assessment.IsOpen)
            {
                return View("AssessmentClosed");
            }
            //check prereq
            if (assessment.PreReq != null)
            {
                if (!dataRepository.HasUserSubmittedAssessment(assessment.PreReq))
                {
                    return View("PreReqNotSatisfied", assessment);
                }
                else
                {
                    Grade g = new Grade(assessment.PreReq, dataRepository.GetLoggedInProfile());
                    if (assessment.PrereqMinScorePct != null && g.Percentage < assessment.PrereqMinScorePct.Value)
                    {
                        return View("PreReqNotSatisfied", assessment);
                    }
                }
            }
            try
            {
                using (TransactionScope transaction = new TransactionScope())
                {
                    //Upload all attachments and store their IDs
                    Dictionary<string, string> answerAttachments = new Dictionary<string, string>();
                    foreach (Answer answer in assessment.Answers)
                    {
                        if (answer.Type == "attachment")
                        {
                            AssessTrack.Models.File file = FileUploader.GetFile(answer.AnswerID.ToString(), Request);
                            if (file != null)
                            {
                                dataRepository.SaveFile(file);
                                dataRepository.Save();
                                string downloadUrl = Url.Action("Download", "File", new { id = file.FileID });
                                string link = string.Format("<a href=\"{0}\">Click here to download {1}.</a>", downloadUrl, file.Name);
                                answerAttachments.Add(answer.AnswerID.ToString(), link);
                            }
                        }
                    }

                    SubmissionRecord record = new SubmissionRecord();

                    Guid studentID = dataRepository.GetLoggedInProfile().MembershipID;
                    record.StudentID = studentID;
                    record.SubmissionDate = DateTime.Now;

                    foreach (Answer answer in assessment.Answers)
                    {
                        string responseText = collection[answer.AnswerID.ToString()];

                        //Put the download link in responseText if this is an attachment
                        if (answer.Type == "attachment")
                        {
                            answerAttachments.TryGetValue(answer.AnswerID.ToString(), out responseText);
                        }

                        if (responseText != null)
                        {
                            Response response = new Response();
                            response.Answer = answer;
                            response.ResponseText = responseText;
                            record.Responses.Add(response);
                        }

                    }
                    record.Assessment = assessment;
                    //Run the autograder
                    dataRepository.GradeSubmission(record);

                    //Need to save the submission before compiling the code questions
                    dataRepository.SaveSubmissionRecord(record);

                    //Compile any code answers after record is saved and has an id
                    record.CompileCodeQuestions();

                    string message = "Your answers were submitted successfully! " +
                        "Your Comfirmation Number is \"" + record.SubmissionRecordID +
                        "\". Keep this number for you records!";
                    FlashMessageHelper.AddMessage(message);

                    transaction.Complete();
                    return RedirectToAction("Index", new { siteShortName = siteShortName, courseTermShortName = courseTermShortName });
                }
            }
            catch (Exception e)
            {
                FlashMessageHelper.AddMessage("An error occurred while submitting your answers. <br/> Message: " + e.Message );
                return View(assessment);
            }
        }