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); }
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); }
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)); }
public ActionResult PostExercise(Exercise exercise) { var result = _exerciseService.Create(exercise); if (result == 0) { return(Forbid()); } return(Ok(new Exercise { Id = result })); }
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); })); }
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 })); } }
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)); }
private void AddExercise() { Messenger.Default.Send(new StartEditingExerciseMessage(exerciseService.Create())); }