Exemple #1
0
        public ActionResult SubmitSolution(AssignmentViewModel viewModel)
        {
            SubmissionViewModel submission = new SubmissionViewModel {
                AssignmentName = viewModel.Title, MilestoneID = viewModel.milestoneSubmissionID
            };
            Assignment assigment = (from s in db.Assignments
                                    where s.ID == viewModel.ID
                                    select s).FirstOrDefault();

            submission.ProgrammingLanguage = aAssignment.GetProgrammingLanguageByID(assigment.ProgrammingLanguageID);
            if (viewModel.File != null)
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    viewModel.File.InputStream.CopyTo(memoryStream);

                    string result = Encoding.ASCII.GetString(memoryStream.ToArray());
                    submission.Code = result;
                }
            }
            else if (!string.IsNullOrEmpty(viewModel.Solution))
            {
                submission.Code = viewModel.Solution;
            }

            if (submission.ProgrammingLanguage == "regex")
            {
                return(RedirectToAction("RegexTest", submission));
            }

            if (submission.ProgrammingLanguage == "other")
            {
                return(RedirectToAction("Other", submission));
            }

            if (submission.ProgrammingLanguage == "otherNotTests")
            {
                return(RedirectToAction("OtherWithTests", submission));
            }
            return(RedirectToAction("CompileSolution", submission));
        }