コード例 #1
0
        public void Update(TestCategoryDTO entity)
        {
            TestCategory category = _mapper.Map <TestCategory>(entity);

            _unitOfWork.TestCategories.Update(category);
            _unitOfWork.SaveChanges();
        }
コード例 #2
0
        public IHttpActionResult DeleteCategory(int id)
        {
            TestCategoryDTO categoryToDel = this._testCategoryService.GetById(id);

            if (categoryToDel == null)
            {
                return(Content(HttpStatusCode.NotFound,
                               $"Test category with id={id} does not exist."));
            }

            this._testCategoryService.Delete(id);

            return(Ok());
        }
コード例 #3
0
        public IHttpActionResult CreateCategory([FromBody] TestCategoryBindingModel category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TestCategoryDTO newCategory = new TestCategoryDTO()
            {
                Title = category.Title
            };

            this._testCategoryService.Add(newCategory);

            return(Ok());
        }
コード例 #4
0
        public IHttpActionResult UpdateCategory(int id, [FromBody] TestCategoryBindingModel category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            TestCategoryDTO categoryToUpdate = this._testCategoryService.GetById(id);

            if (categoryToUpdate == null)
            {
                return(Content(HttpStatusCode.NotFound,
                               $"Test category with id={id} does not exist."));
            }

            TestCategoryDTO updatedCategory = new TestCategoryDTO()
            {
                Title = category.Title
            };

            this._testCategoryService.Update(updatedCategory);

            return(Ok());
        }