Beispiel #1
0
        public ActionResult Edit(decimal id)
        {
            BusinessLayer.FoodGroup fooditem = dbset.FoodGroups.Single(emp => emp.FoodGroupId == id);
            if (fooditem == null)
            {
                return(HttpNotFound());
            }

            return(View(fooditem));
        }
Beispiel #2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(BusinessLayer.FoodGroup fooditem)
        {
            if (ModelState.IsValid)
            {
                dbset.SaveChangesFoodGroupToDB(fooditem);
                //db.Entry(fooditem).State = EntityState.Modified;
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(fooditem));
        }
Beispiel #3
0
        //[ActionName("Create")]
        //[ValidateAntiForgeryToken]
        public ActionResult Create(BusinessLayer.FoodGroup fooditem)//Create(FormCollection formCollection)
        {
            if (ModelState.IsValid)
            {
                dbset.AddFoodGroupToDB(fooditem);
                return(RedirectToAction("Index"));
            }

            //ViewBag.FoodGroupId = new SelectList(dbset.FoodGroups, "FoodGroupId", "FoodGroupName");

            return(View());
        }
        public void AddFoodGroupToDB(FoodGroup employee)
        {
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("spAddFoodGroup", con);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlParameter paramFoodName = new SqlParameter();
                paramFoodName.ParameterName = "@FoodName";
                paramFoodName.Value         = employee.FoodGroupName;
                cmd.Parameters.Add(paramFoodName);

                con.Open();
                cmd.ExecuteNonQuery();
            }
        }