예제 #1
0
        public async Task <ActionResult> Create(IFormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                problem = new Problem
                {
                    Name      = collection["Name"],
                    Condition = collection["Condition"],
                    Example   = collection["Example"],
                    Level     = Convert.ToInt32(collection["Level"]),
                    Notation  = collection["Notation"],
                    Template  = collection["Template"]
                };

                await _problemService.Create(problem);

                var createdProblem = await _problemService.GetProblemName(problem.Name);

                return(RedirectToAction("Create", "Test", new { problemId = createdProblem.FirstOrDefault().Id }));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Post(ProblemUserModel problem)
        {
            var newProblem = _problemService.Create(problem.ToModel(), AuthorId);

            if (newProblem == null)
            {
                return(StatusCode(403));
            }
            return(StatusCode(201, newProblem.ToView()));
        }
예제 #3
0
        public IActionResult Create(ProblemInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Problems/Create"));
            }
            var problem = new Problem()
            {
                Name   = model.Name,
                Points = model.Points
            };

            problemService.Create(problem);
            return(Redirect("/"));
        }
예제 #4
0
        public async Task <ApiResponse> Create(string externalId, [FromBody] List <ProblemCreateRequest> request)
        {
            foreach (var medication in request)
            {
                var result = await _objControllerHelper.Create(medication, externalId);

                if (result.Status != PatientCreateStatus.Success)
                {
                    //return new ApiResponse(result, 200);

                    return(new ApiResponse(400, result.Error));
                }
            }
            return(new ApiResponse(200));
        }
예제 #5
0
 public HttpResponse Create(string name, int points)
 {
     if (!this.IsUserSignedIn())
     {
         return(this.Redirect("/Users/Login"));
     }
     if (string.IsNullOrWhiteSpace(name) || name.Length < 5 || name.Length > 20)
     {
         return(this.Error("Problem name must be between 5 and 20 characters!"));
     }
     if (points < 50 || points > 300)
     {
         return(this.Error("Points must be between 50 and 300 !"));
     }
     problemService.Create(name, points);
     return(this.Redirect("/"));
 }
예제 #6
0
 public ActionResult Create(CreateRestoreDataViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var problem = model.Adapt <RestoreData>();
             _problemService.Create(problem);
             return(RedirectToAction("Index", "Problemset"));
         }
         catch
         {
             return(View("Error"));
         }
     }
     ViewBag.GeneratorType = DataGeneratorTypeExtensions.GetGenerateTypes();
     return(View("DisplayTemplates/CreateRestoreDataViewModel", model));
 }
 public IActionResult Create(CreateCodeCorrectorViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var problem = model.Adapt <CodeCorrectorData>();
             _problemService.Create(problem);
             return(RedirectToAction("Index", "Problemset"));
         }
         catch (Exception e)
         {
             ViewBag.Error = e.Message;
             return(View("Error"));
         }
     }
     ViewBag.GeneratorType = DataGeneratorTypeExtensions.GetGenerateTypes();
     return(View("DisplayTemplates/CreateCodeCorrectorViewModel", model));
 }
예제 #8
0
        public ActionResult Create(CreateTraceTableViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var problem = model.Adapt <TraceTableData>();
                    _problemService.Create(problem);

                    return(RedirectToAction("Index", "Problemset"));
                }
                catch
                {
                    return(View("Error"));
                }
            }

            return(View("DisplayTemplates/CreateTraceTableViewModel", model));
        }
예제 #9
0
        public ActionResult Create(IFormCollection collection)
        {
            //try
            //{
            // TODO: Add insert logic here

            Problem problem = new Problem
            {
                Name      = collection["Name"],
                Condition = collection["Condition"],
                Example   = collection["Example"],
                Level     = Convert.ToInt32(collection["Level"]),
                Notation  = collection["Notation"],
                Template  = collection["Template"]
            };

            _problemService.Create(problem);

            //Problem createdProblem = _problemService.GetProblemName(problem.Name).Result.Cast<Problem>().First();

            //Test test = new Test
            //{
            //    Number = Convert.ToInt32(collection["Number"]),
            //    Hidden = Convert.ToBoolean(collection["Hidden"]),
            //    Input = collection["Input"],
            //    Output = collection["Output"],
            //    ProblemId = createdProblem.Id,
            //    Problem = createdProblem
            //};

            //_testService.Create(test);

            return(RedirectToAction("Index", "Home"));
            //}
            //catch
            //{
            //    return View();
            //}
        }
        public void AddProblemsTest()
        {
            var id = _categoryService.Create(new Category {
                Name = "abc"
            }).Id;

            _categoryService.Create(new Category {
                Name = "cde"
            }, id);
            _categoryService.Create(new Category {
                Name = "xyz"
            }, id);
            var id2 = _categoryService.Create(new Category {
                Name = "xyz"
            }, id).Id;

            var pid0 = _problemService.Create(new Problem {
                Name = "xxx1", CategoryId = id2
            }).Id;
            var pid1 = _problemService.Create(new Problem {
                Name = "xxx2", CategoryId = id2
            }).Id;
            var pid2 = _problemService.Create(new Problem {
                Name = "xxx3", CategoryId = id2
            }).Id;

            var problems = _categoryService.GetProblems(id2);

            //Assert.Equal("xyz", category.Name);
            Assert.Equal(3, problems.Count());
            //var problems = category.Problems.ToList();
            Assert.Contains(problems, p => p.Id == pid0);
            Assert.Contains(problems, p => p.Id == pid1);
            Assert.Contains(problems, p => p.Id == pid2);
        }
예제 #11
0
        public void ApproveAnswersTest()
        {
            // Tworzymy nowy problem.
            var id = _problemService.Create(new Problem {
                Name = "xxx", Content = "yyy"
            }).Id;

            // Tworzymy nową odpowiedź.
            var answerId1 = _problemService.CreateAnswer(id, new Answer {
                Content = "xxx"
            });
            var answerId2 = _problemService.CreateAnswer(id, new Answer {
                Content = "yyy"
            });
            var answerId3 = _problemService.CreateAnswer(id, new Answer {
                Content = "zzz"
            });

            // Pobieramy problem i sprawdzamy czy dostajemy odpowiedzi.
            var problem = _problemService.Get(id);

            // Sprawdzamy czy treść odpowiedzi się zgadza.
            Assert.Contains("xxx", problem.Answers.First(a => a.Id == answerId1).Content);
            Assert.Contains("yyy", problem.Answers.First(a => a.Id == answerId2).Content);
            Assert.Contains("zzz", problem.Answers.First(a => a.Id == answerId3).Content);

            // Sprawdzamy czy odpowiedzi oznaczone są jako niezatwierdzone.
            Assert.False(problem.Answers.First(a => a.Id == answerId1).IsApproved);
            Assert.False(problem.Answers.First(a => a.Id == answerId2).IsApproved);
            Assert.False(problem.Answers.First(a => a.Id == answerId3).IsApproved);

            // Zatwierdzamy odpowiedź.
            _problemService.SetAnswerApproval(id, answerId1);

            // Pobrany problem powinien figurować jako rozwiązany.
            var problem1 = _problemService.Get(id);

            Assert.True(problem1.IsSolved);
            Assert.True(problem1.Answers.First(a => a.Id == answerId1).IsApproved);
            Assert.False(problem1.Answers.First(a => a.Id == answerId2).IsApproved);
            Assert.False(problem1.Answers.First(a => a.Id == answerId3).IsApproved);

            // Zatwierdzamy inną odpowiedź.
            _problemService.SetAnswerApproval(id, answerId2);

            // Przy zatwierdzeniu innego rozwiązania odpowiedź pierwsza nie powinna być dalej zatwierdzona.
            var problem2 = _problemService.Get(id);

            Assert.True(problem2.IsSolved);
            Assert.False(problem2.Answers.First(a => a.Id == answerId1).IsApproved);
            Assert.True(problem2.Answers.First(a => a.Id == answerId2).IsApproved);
            Assert.False(problem2.Answers.First(a => a.Id == answerId3).IsApproved);

            // Zdejmujemy zatwierdzenie odpowiedzi.
            _problemService.SetAnswerApproval(id, answerId2, false);

            // Teraz problem powinien figurować jako nierozwiązany.
            var problem3 = _problemService.Get(id);

            Assert.False(problem3.IsSolved);
            Assert.False(problem3.Answers.First(a => a.Id == answerId1).IsApproved);
            Assert.False(problem3.Answers.First(a => a.Id == answerId2).IsApproved);
            Assert.False(problem3.Answers.First(a => a.Id == answerId3).IsApproved);
        }
 public IActionResult CreateProblem(ICreateProblemViewModel problemViewModel)
 {
     _problemService.Create(problemViewModel.Adapt <ProblemData>());
     return(RedirectToAction("Index"));
 }