예제 #1
0
 public async Task <IHttpActionResult> Post(Category category)
 {
     try
     {
         if (ModelState.IsValid)
         {
             var categoryToUpdate = _repo.GetCategoryByIdAsync(category.CategoryId).Result;
             if (categoryToUpdate != null)
             {
                 categoryToUpdate.Description = category.Description;
                 categoryToUpdate.Active      = category.Active;
                 if (_repo.SaveChanges())
                 {
                     return(Ok(categoryToUpdate));
                 }
             }
             else
             {
                 _repo.AddCategory(category);
                 if (await _repo.SaveChangesAsync())
                 {
                     return(Created("GetCategory", category));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
     return(BadRequest());
 }