Beispiel #1
0
 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"));
     }
 }
Beispiel #2
0
 // POST: api/Products
 public void Post([FromBody] ProductModel product)
 {
     if (ModelState.IsValid)
     {
         if (productData.CheckIfAlreadyExist(product.Name) == false)
         {
             IProductModel model = product;
             productData.Create(model);
         }
     }
 }
Beispiel #3
0
 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"));
     }
 }
Beispiel #4
0
 // 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);
         }
     }
 }