public ActionResult Create([Bind(Include = "ID,Name")] CategoryModel category) { if (ModelState.IsValid) { try { // Checking if already exist a category with same name (case insensitive) if (categoryData.CheckIfAlreadyExist(category.Name) == false) { ICategoryModel model = category; categoryData.Create(model); return(RedirectToAction("Index")); } else { log.Info("The user tried to add a category that already existed"); return(View("AlreadyExists")); } } catch (Exception ex) { log.Error("Could't create a new category in the Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The model state of the category is invalid"); return(View("WrongData")); } }
// POST: api/Categories public void Post([FromBody] CategoryModel area) { if (ModelState.IsValid) { if (categoryData.CheckIfAlreadyExist(area.Name) == false) { ICategoryModel model = area; categoryData.Create(model); } } }
// POST: api/Areas public void Post([FromBody] AreaModel area) { if (ModelState.IsValid) { if (areaData.CheckIfAlreadyExist(area.Name) == false) { IAreaModel model = area; areaData.Create(model); } } }