public IActionResult Post([FromBody] TeamCategoryViewModel model) { try { if (ModelState.IsValid) { var newCategory = new TeamCategory() { Name = model.Name }; repository.AddTeamCategory(newCategory); if (repository.SaveAll()) { return(Ok("New team category has been saved")); } } else { return(BadRequest(ModelState)); } } catch (Exception exception) { Console.WriteLine(exception); } return(BadRequest("Failed to save new team category")); }
public IActionResult Edit([FromBody] TeamCategoryViewModel model, int id) { Console.WriteLine("Trying to update team category"); if (!ModelState.IsValid) { Console.WriteLine("ModelState is not valid"); return(BadRequest(ModelState)); } var category = repository.GetTeamCategoryById(id); if (category != null) { category.Name = model.Name; if (repository.SaveAll()) { return(new OkObjectResult("Successfully saved category inside")); } } Console.WriteLine("Successfully saved category outside"); return(new OkObjectResult("Successfully saved category outside")); }