public void GetCategoryExercises()
        {
            var cid1 = _categoryService.Create(new Category {
                Name = "xxxx"
            }).Id;

            var pid1 = _exerciseService.Create(new Exercise {
                Name = "aaa", CategoryId = cid1
            });
            var pid2 = _exerciseService.Create(new Exercise {
                Name = "bbb", CategoryId = cid1
            });
            var pid3 = _exerciseService.Create(new Exercise {
                Name = "ccc", CategoryId = cid1
            });

            var exercises = _categoryService.GetExercises(cid1);

            var names = exercises.Select(p => p.Name).ToList();

            Assert.Equal(3, exercises.Count());

            Assert.Contains("aaa", names);
            Assert.Contains("bbb", names);
            Assert.Contains("ccc", names);
        }
예제 #2
0
        public int ExerciseCreate()
        {
            var exerciseId = _exerciseService.Create(new Exercise {
                Name = "abc", Content = "cde"
            });
            var exercise = _exerciseService.Get(exerciseId);

            Assert.Equal("abc", exercise.Name);
            Assert.Contains("cde", exercise.Content);
            return(exerciseId);
        }
예제 #3
0
        public async Task <ActionResult <Exercise> > Create(ExerciseRequest exercise)
        {
            var result = await _exercises.Create(exercise, HttpContext.RequestAborted);

            if (result == null)
            {
                return(Conflict());
            }

            return(result);
        }
        public async Task <IActionResult> PostExercise([FromBody] Exercise exercise)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            await _exerciseService.Create(exercise);

            return(CreatedAtAction("GetExercise", new { id = exercise.RecordId }, exercise));
        }
예제 #5
0
        public ActionResult PostExercise(Exercise exercise)
        {
            var result = _exerciseService.Create(exercise);

            if (result == 0)
            {
                return(Forbid());
            }
            return(Ok(new Exercise {
                Id = result
            }));
        }
예제 #6
0
        public IHttpActionResult Create([FromBody] Exercise exercise)
        {
            LogInfoObjectToJson(exercise, "Creating 'Exercise':");

            return(ExecuteRequest(() =>
            {
                var exerciseDTO = _mapper.Map <ExerciseDTO>(exercise);
                var result = _service.Create(exerciseDTO);

                LogInfoObjectToJson(result, "Created 'Exercise':");
                return Ok <IOperationResult>(result);
            }));
        }
예제 #7
0
        public async Task <IActionResult> Create([FromBody] ExerciseModel model)
        {
            var exercise = _mapper.Map <Exercise>(model);

            try
            {
                await _exerciseService.Create(exercise);

                return(Ok());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
예제 #8
0
        public ActionResult <Exercise> CreateExercise([FromBody] CreateExercise model)
        {
            // map model to entity
            var Exercise = _mapper.Map <Exercise>(model);

            try
            {
                // create Exercise
                _ExerciseService.Create(Exercise);
                return(Ok());
            }
            catch (AppException ex)
            {
                // return error message if there was an cexception
                return(BadRequest(new { message = ex.Message }));
            }
        }
        public IActionResult Post([FromBody] CreateExercise request)
        {
            _exerciseService.Create(request.Name);

            return(StatusCode(201));
        }
예제 #10
0
 private void AddExercise()
 {
     Messenger.Default.Send(new StartEditingExerciseMessage(exerciseService.Create()));
 }