Exemple #1
0
        public async Task <IActionResult> AddProductCategory([FromBody] UpdateProductCategoryRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var category = await _categoryService.CreateCategoryAsync(createRequest);

            var location = string.Format("/api/categories/{0}", category.Id);

            return(Created(location, category));
        }
Exemple #2
0
        public async Task <IHttpActionResult> AddProductCategoryAsync([FromBody] UpdateProductCategoryRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var category = await _categoryService.CreateCategoryAsync(createRequest);

                var location = string.Format("/api/categories/{0}", category.Id);
                return(Created <ProductCategory>(location, category));
            }
            catch (RequestedResourceHasConflictException)
            {
                return(Conflict());
            }
        }
Exemple #3
0
        public async Task <IHttpActionResult> AddProductCategory([FromBody] UpdateProductCategoryRequest createRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var category = await _categoryService.CreateCategoryAsync(createRequest);

                var location = string.Format("/api/categories/{0}", category.Id);
                return(Created <ProductCategory>(location, category));
            }
            catch (RequestedResourceHasConflictException ex)
            {
                return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.Conflict, ex.Message)));
            }
            catch (Exception)
            {
                return(this.InternalServerError());
            }
        }