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)); } } }
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)); } } }