public ActionResult GetTestTitles(int groupId) { var testResponseModel = new TestResponseModel(); var testTitles = testsService.GetTestTitles().ToList(); List <TestTitleDto> testTitlesDtos = new List <TestTitleDto>(); testTitles.ForEach(testTitle => { if (testTitle.GroupId == groupId) { testTitlesDtos.Add((new TestTitleDto()).GetTestTitleDto(testTitle)); } }); testResponseModel.TestTitles = testTitlesDtos; if (testTitlesDtos != null) { return(Ok(GetResponse(ResponseType.OBJECT, ResponseStatusCode.SUCCESS, testResponseModel))); } else { return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "No test title found", "Please add a test title")))); } }
public IHttpActionResult Post([FromBody] TestResponseModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var test = this.models.Get <Test>(model); this.data.Tests.Add(test); this.data.SaveChanges(); return(this.Created(this.Url.ToString(), model)); }
public IHttpActionResult Remove([FromBody] TestResponseModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var testToDelete = this.data.Tests.All().FirstOrDefault(t => t.Id == model.Id); if (testToDelete == null) { return(this.NotFound()); } this.data.Tests.Delete(testToDelete); this.data.SaveChanges(); return(this.Ok(model)); }
public ActionResult GetOtherTests() { var testResponseModel = new TestResponseModel(); var otherTests = testsService.GetOtherTests().ToList(); List <OtherTestDto> otherTestDtos = new List <OtherTestDto>(); otherTests.ForEach(otherTest => otherTestDtos.Add((new OtherTestDto()).GetOtherTestDto(otherTest))); testResponseModel.OtherTests = otherTestDtos; testResponseModel.Groups = GetTestGroupTypeDtos(testsService.GetTestGroups().ToList()); testResponseModel.Titles = GetTestTitleTypeDtos(testsService.GetTestTitles().ToList()); if (otherTestDtos != null) { return(Ok(GetResponse(ResponseType.OBJECT, ResponseStatusCode.SUCCESS, testResponseModel))); } else { return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "No other test found", "Please add an other test")))); } }