예제 #1
0
 // PUT /api/category/5
 public IHttpActionResult Put(int id, CategoryModel category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Category entity = Mapper.Map<CategoryModel, Category>(category);
             _categoryService.Update(entity);
             return Ok(category);
         }
         catch (Exception ex)
         {
             HttpResponseMessage responseMessage = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
                 ex.Message);
             return ResponseMessage(responseMessage);
         }
     }
     return BadRequest(ModelState);
 }
예제 #2
0
 // POST /api/category
 public IHttpActionResult Post(CategoryModel category)
 {
     if (ModelState.IsValid)
     {
         try
         {
             Category entity = Mapper.Map<CategoryModel, Category>(category);
             _categoryService.Insert(entity);
             CreatedAtRouteNegotiatedContentResult<CategoryModel> response = CreatedAtRoute("DefaultApi",
                 new {id = category.Id}, category);
             return response;
         }
         catch (Exception ex)
         {
             HttpResponseMessage responseMessage = Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
                 ex.Message);
             return ResponseMessage(responseMessage);
         }
     }
     return BadRequest(ModelState);
 }