public IActionResult CreateClothesCategory([FromBody] ClothesCategory clothesCategory) { try { if (clothesCategory.IsEntityNull()) { return(BadRequest("ClothesCategory object is null")); } if (!clothesCategory.IsEntityEmpty()) { return(BadRequest("For create, the Id must be null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } _clothesCategoryService.CreateClothesCategory(clothesCategory); _clothesCategoryService.Save(); return(CreatedAtRoute("ClothesCategoryById", new { id = clothesCategory.Id.Value }, clothesCategory)); } catch (Exception ex) { _logger.Error(ex, "Error in call : api/clothesCategory/CreateClothesCategory", clothesCategory); return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error")); } }
public IActionResult UpdateClothesCategory(int id, [FromBody] ClothesCategory clothesCategory) { try { if (clothesCategory.IsEntityNull()) { return(BadRequest("ClothesCategory object is null")); } if (!ModelState.IsValid) { return(BadRequest("Invalid model object")); } ClothesCategory dbClothesCategory = _clothesCategoryService.GetClothesCategoryById(id); if (dbClothesCategory.IsEntityNull()) { _logger.Error($"ClothesCategory with id: {id} not found in db"); return(NotFound()); } _clothesCategoryService.UpdateClothesCategory(dbClothesCategory, clothesCategory); _clothesCategoryService.Save(); return(NoContent()); } catch (Exception ex) { _logger.Error(ex, "Error in call : api/clothesCategory/UpdateClothesCategory/" + id, clothesCategory); return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error")); } }
public IActionResult DeleteClothesCategory(int id) { try { ClothesCategory clothesCategory = _clothesCategoryService.GetClothesCategoryById(id); if (clothesCategory.IsEntityNull()) { _logger.Error($"ClothesCategory with id: {id} not found in db"); return(NotFound()); } _clothesCategoryService.DeleteClothesCategory(clothesCategory); _clothesCategoryService.Save(); return(NoContent()); } catch (Exception ex) { _logger.Error(ex, "Error in call : api/clothesCategory/DeleteClothesCategory/" + id); return(StatusCode(StatusCodes.Status500InternalServerError, "Internal server error")); } }