public Submission CreateProblemSubmission(int problem_id, SubmissionFormData submission_data) { var problem = context.Problems.Find(problem_id); var judge = new JudgeService(); if (problem == null) { throw new ObjectNotFoundException("Problem with specified id does not exist"); } // Trace.WriteLine(submission_data.ProgrammingLanguageId); var submission = InitializeSubmissionObject(problem, submission_data); context.Submissions.Add(submission); context.SaveChanges(); judge.OnSubmissionStatusChange += (sender, e) => { var result = e.ExecutionResult; submission.Status = context.SubmissionStatus.Find(result.Verdict); submission.RunningTime = result.RunningTime; submission.PeakMemmoryUsage = result.MemmoryUsage; // submission.PeakMemmoryUsage = result.Verdict == Verdict.CompilationError ? 0 : 5; // TODO REPLACE WITH REAL VALUE submission.StandardErrorStream = result.ErrorMsg; context.SaveChanges(); // this event must be emitter *after* invoking context.SaveChanges() OnSubmissionStatusChange?.Invoke(this, e); }; judge.judge(submission_data, problem); return(submission); }
public void CreateProblem(ProblemCreationForm data) { Problem problem = new Problem() { Title = data.Title, Description = data.Description, Constraints = data.Constraints, InputSpecification = data.InputSpecification, OutputSpecification = data.OutputSpecification, SampleInput = data.SampleInput, SampleOutput = data.SampleOutput, Notes = data.Notes, TimeLimit = data.TimeLimit, MemoryLimit = data.MemoryLimit, IsPublic = data.IsPublic, TestCaseInput = data.TestCaseInput, TestCaseOutput = data.TestCaseOutput, CreateDate = DateTime.Now, Creator = context.Users.Find(user_service.GetUserId()), }; context.Problems.Add(problem); context.SaveChanges(); }
public void CreateSubmission(int contest_id, int problem_no, SubmissionFormData submission_data) { // important: submission_repository must be initialized using this.context SubmissionRepository submission_repository = new SubmissionRepository(context); Contest contest = context.Contests.Include(x => x.Problems).FirstOrDefault(x => x.Id == contest_id); if (contest.EndDate < DateTime.Now) { throw new InvalidOperationException("Can not create submission to contest that has ended"); } if (contest.StartDate > DateTime.Now) { throw new InvalidOperationException("Can not create submission to contest that has not started"); } ContestProblem contest_problem = contest.Problems.FirstOrDefault(x => x.Order == problem_no); Problem problem = contest_problem.Problem; submission_repository.OnSubmissionStatusChange += (Object sender, ExecutionResultEventArgs args) => { // the submission entry is updated by SubmissionRepository, // this handler only updates the contestant // replace with real user var contestant = context.Contestants.Include(x => x.Submissions).First(x => x.Contest.Id == contest_id); contestant.Penalty = contest_service.CalclatePenalty(contestant.Submissions); contestant.SolveCount = context.ContestProblems.Count(x => x.Submissions. Count(y => y.Submission.Status.Id == Verdict.Accepted) > 0); context.SaveChanges(); }; User submitter = context.Users.First(); Submission submission = submission_repository.CreateProblemSubmission(problem.Id, submission_data); ContestSubmission contest_submission = new ContestSubmission() { Submitter = context.Contestants.First(x => x.Contest.Id == contest_id && x.User.Id == submitter.Id), Problem = contest_problem, Submission = submission, }; contest.Submissions.Add(contest_submission); context.SaveChanges(); }
public Announcement createAnnouncement(AnnouncementFormData data) { Announcement announcement = new Announcement() { Title = data.Title, Description = data.Description, CreateDate = DateTime.Now, Creator = context.Users.Find(user_service.GetUserId()) }; context.Announcements.Add(announcement); context.SaveChanges(); return(announcement); }
public void UpdateUser(int id, UserProfileUpdateForm data) { User user = context.Users.Find(id); if (user == null) { throw new ObjectNotFoundException("User with specified ID not found"); } user.Email = data.Email; user.Password = data.Password; user.UserType = context.UserTypes.Find(data.UserType); context.SaveChanges(); }
public Contestant RegisterUserForContest(int contest_id, int user_id, ContestRegistrationFormData data) { Contest contest = context.Contests.Include(x => x.Contestants).FirstOrDefault(x => x.Id == contest_id); var user = context.Users.Find(user_id); if (contest == null) { throw new ObjectNotFoundException("Contest with specified id not found"); } if (user == null) { throw new ObjectNotFoundException("User with specified id not found"); } // if user is already registered for this contest if (contest.Contestants.Count(x => x.User == user) > 0) { throw new InvalidOperationException("User is already registered for contest"); } if (!contest.IsPublic && contest.Password != data.Password) { throw new InvalidOperationException("Wrong password for registation"); } if (contest.StartDate < DateTime.Now) { throw new InvalidOperationException("Contest registration time has ended"); } Trace.WriteLine(contest.Contestants.Count); var contestant = new Contestant(user); contest.Contestants.Add(contestant); context.SaveChanges(); return(contestant); }