public ActionResult AddPro(product productmodel)
 {
     using (restaurantsdbEntities db = new restaurantsdbEntities())
     {
         try
         {
             int     idp;
             product LastProduct;
             try
             {
                 LastProduct = db.products.Where(x => x.IDProduct > 0).OrderByDescending(x => x.IDProduct).First();
                 idp         = LastProduct.IDProduct + 1;
             }
             catch
             {
                 idp = 1;
             }
             var ProductCreation = db.Set <product>();
             ProductCreation.Add(new product {
                 IDProduct = idp, Name = productmodel.Name, Price = productmodel.Price, Details = productmodel.Details
             });
             db.SaveChanges();
             return(RedirectToAction("Index", "Management"));
         }
         catch (Exception ex)
         {
             productmodel.AddPError = "Couldn't create new Product" + ex;
             return(PartialView("_ProAdd", productmodel));
         }
     }
 }
Exemple #2
0
 public ActionResult UpdateOrd(order ordermodel)
 {
     using (restaurantsdbEntities db = new restaurantsdbEntities())
     {
         if (ModelState.IsValid)
         {
             db.Entry(ordermodel).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("GetOrders"));
         }
         else
         {
             ordermodel.AddOError = "Couldn't edit Order";
             return(PartialView("_OrdEdit", ordermodel));
         }
     }
 }
 public ActionResult UpdatePro(product productmodel)
 {
     using (restaurantsdbEntities db = new restaurantsdbEntities())
     {
         if (ModelState.IsValid)
         {
             db.Entry(productmodel).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("GetProducts"));
         }
         else
         {
             productmodel.AddPError = "Couldn't edit Product";
             return(PartialView("_ProEdit", productmodel));
         }
     }
 }
 public ActionResult UpdateEmp(employee employeemodel)
 {
     using (restaurantsdbEntities db = new restaurantsdbEntities())
     {
         if (ModelState.IsValid)
         {
             db.Entry(employeemodel).State = EntityState.Modified;
             db.SaveChanges();
             return(RedirectToAction("GetEmployees"));
         }
         else
         {
             employeemodel.AddEError = "Couldn't edit Employee";
             return(PartialView("_EmpEdit", employeemodel));
         }
     }
 }
 public ActionResult AddEmp(employee employeemodel)
 {
     using (restaurantsdbEntities db = new restaurantsdbEntities())
     {
         try
         {
             var EmployeeCreation = db.Set <employee>();
             EmployeeCreation.Add(new employee {
                 Email = employeemodel.Email, Password = employeemodel.Password, Name = employeemodel.Name, Position = employeemodel.Position
             });
             db.SaveChanges();
             return(RedirectToAction("Index", "Management"));
         }
         catch (Exception ex)
         {
             employeemodel.AddEError = "Couldn't create new Employee" + ex;
             return(PartialView("_EmpAdd", employeemodel));
         }
     }
 }