public static ContestTaskSubmit Create()
        {
            var submit = new ContestTaskSubmit();

            submit.Results.Add(new SubmitResult(submit));
            return(submit);
        }
Beispiel #2
0
        public void SubmitSolution(int contestId, string label, int selectedLanguage, HttpPostedFileBase file, UserInfo userInfo)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            string sourceCode;

            using (var sr = new StreamReader(file.InputStream))
            {
                sourceCode = sr.ReadToEnd();
            }

            using (var unitOfWork = _factory.GetUnitOfWork(true))
            {
                var contest = unitOfWork.GetRepository <IContestsRepository>().Get(contestId);
                if (DateTime.UtcNow < contest.StartTime)
                {
                    throw new InvalidOperationException("Contest not started");
                }

                if (DateTime.UtcNow >= contest.FinishTime)
                {
                    throw new InvalidOperationException("Contest finished");
                }

                var task = unitOfWork.GetRepository <IContestTaskRepository>().Get(contestId, label);

                if (task == null)
                {
                    throw new InvalidOperationException("Task not found");
                }

                var submit = ContestTaskSubmit.Create();

                submit.ProblemId  = task.Task.Id;
                submit.ContestId  = contestId;
                submit.LanguageId = selectedLanguage;
                submit.UserId     = userInfo.UserId;
                submit.FileName   = Path.GetFileName(file.FileName);
                submit.SourceCode = sourceCode;
                submit.UserHost   = userInfo.Host;
                submit.SessionId  = userInfo.SessionId;

                var submitRepository = unitOfWork.GetRepository <ISubmitRepository>();
                submitRepository.Add(submit);
                unitOfWork.Commit();
            }
        }