public IHttpActionResult UpdateWholeTest(int id, [FromBody] NewTestBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestDTO testToUpdate = _testService.GetById(id); if (testToUpdate == null) { return(Content(HttpStatusCode.NotFound, $"Test with id={id} does not exist.")); } _testService.UpdateWholeTest(id, _mapper.Map <TestDTO>(model)); return(Ok()); }
//[Authorize(Roles = "Admin, Editor")] public IHttpActionResult CreateTest([FromBody] NewTestBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestDTO newTest = new TestDTO() { Title = model.Title, CategoryId = model.CategoryId, Descr = model.Descr, DurationMin = model.DurationMin, Questions = _mapper.Map <List <QuestionDTO> >(model.Questions) }; _testService.Add(newTest); return(Ok(newTest)); }