Beispiel #1
0
        public async Task<HttpResponseMessage> Post(CategoryRequestModel requestModel)
        {
            var postResult = await _categoryService.AddCategory(requestModel.ToCategory());

            if (!postResult.IsSuccess)
                return new HttpResponseMessage(HttpStatusCode.Conflict);

            var response = Request.CreateResponse(HttpStatusCode.Created, postResult.Entity.ToCategoryDto());

            response.Headers.Location = new Uri(Url.Link("GetCategoryById", new { id = postResult.Entity.CategoryID }));

            return response;
        }
Beispiel #2
0
        public async Task<HttpResponseMessage> Put(int id, CategoryRequestModel requestModel)
        {
            var category = await _categoryService.GetCategory(id);

            if (category == null)
                return new HttpResponseMessage(HttpStatusCode.NotFound);

            requestModel.CategoryID = id;

            var putResult = await _categoryService.EditCategory(requestModel.ToCategory());

            if (!putResult.IsSuccess)
                return new HttpResponseMessage(HttpStatusCode.Conflict);

            var response = Request.CreateResponse(HttpStatusCode.OK, putResult.Entity.ToCategoryDto());

            response.Headers.Location = new Uri(Url.Link("GetCategoryById", new { id = putResult.Entity.CategoryID }));

            return response;
        }