public ActionResult Create([Bind(Include = "ID,Name,CategoryID,Price")] ProductModel product) { if (ModelState.IsValid) { try { // Checking if already exist a product with same name (case insensitive) if (productData.CheckIfAlreadyExist(product.Name) == false) { IProductModel model = product; productData.Create(model); return(RedirectToAction("Index")); } else { log.Info("The user tried to add a product that already existed"); return(View("AlreadyExists")); } } catch (Exception ex) { log.Error("Could't create a new product in the Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The model state of the product is invalid"); return(View("WrongData")); } }
public ActionResult Create([Bind(Include = "ID,NumberOfTable,AreaID,Occupied")] TableModel table) { if (ModelState.IsValid) { try { // Checking if already exist a table with same number if (tableData.CheckIfAlreadyExist(table.NumberOfTable.ToString()) == false) { ITableModel model = table; tableData.Create(model); return(RedirectToAction("Index")); } else { log.Info("The user tried to add a table that already existed"); return(View("AlreadyExists")); } } catch (Exception ex) { log.Error("Could't create a new table in the Database", ex); return(View("ErrorRetriveData")); } } else { log.Error("The model state of the table is invalid"); return(View("WrongData")); } }
// POST: api/Tables public void Post([FromBody] TableModel table) { if (ModelState.IsValid) { if (tableData.CheckIfAlreadyExist(table.NumberOfTable.ToString()) == false) { ITableModel model = table; tableData.Create(model); } } }
// POST: api/Products public void Post([FromBody] ProductModel product) { if (ModelState.IsValid) { if (productData.CheckIfAlreadyExist(product.Name) == false) { IProductModel model = product; productData.Create(model); } } }