Пример #1
0
        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();
        }
Пример #2
0
        public void UpdateProblem(int id, ProblemCreationForm problem_form)
        {
            var problem = context.Problems.Find(id);

            if (problem == null)
            {
                throw new ObjectNotFoundException("Problem record with specified id does not exist");
            }

            problem.Title               = problem_form.Title;
            problem.Description         = problem_form.Description;
            problem.Constraints         = problem_form.Constraints;
            problem.InputSpecification  = problem_form.InputSpecification;
            problem.OutputSpecification = problem_form.OutputSpecification;
            problem.SampleInput         = problem_form.SampleInput;
            problem.SampleOutput        = problem_form.SampleOutput;
            problem.Notes               = problem_form.Notes;
            problem.TimeLimit           = problem_form.TimeLimit;
            problem.MemoryLimit         = problem_form.MemoryLimit;
            problem.IsPublic            = problem_form.IsPublic;


            // these values will be updated only if they were provided
            if (problem_form.TestCaseInput != null)
            {
                problem.TestCaseInput = problem_form.TestCaseInput;
            }
            if (problem_form.TestCaseOutput != null)
            {
                problem.TestCaseOutput = problem_form.TestCaseOutput;
            }


            context.SaveChanges();
        }
Пример #3
0
        public async Task <IHttpActionResult> UpdateProblem(int id)
        {
            if (!user_service.IsAuthorizedToEditProblem(id))
            {
                return(Unauthorized());
            }

            // request contain must be of type multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }

            string root     = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider = new MultipartFormDataStreamProvider(root);

            try{
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);
            }
            catch (Exception e) {
                return(InternalServerError(e));
            }

            var problem_form = new ProblemCreationForm(provider.FormData, provider.FileData);

            FormDataValidationResult result = problem_form.Validate();

            if (!result.IsValid)
            {
                return(new BadHttpRequest(result.ErrorMessages));
            }

            try{
                problem_repository.UpdateProblem(id, problem_form);
            }
            catch (ObjectNotFoundException e) {
                return(InternalServerError(e));
            }
            return(Ok());
        }