예제 #1
0
        public ActionResult RegisterFood(tbl_product_Class addfood, HttpPostedFileBase file)
        {
            SqlConnection con = new SqlConnection(MyConnection);

            con.Open();
            SqlCommand sqlcmd = new SqlCommand("spInsertIntoDeals", con);

            sqlcmd.CommandType = CommandType.StoredProcedure;
            sqlcmd.Parameters.AddWithValue("@pro_FoodName", addfood.pro_FoodName);
            sqlcmd.Parameters.AddWithValue("@pro_FoodDescription", addfood.pro_FoodDescription);
            sqlcmd.Parameters.AddWithValue("@pro_FoodPrice", addfood.pro_FoodPrice);
            if (file != null && file.ContentLength > 0)
            {
                string fileName = Path.GetFileName(file.FileName);
                string imgPath  = Path.Combine(Server.MapPath("~/User-Images/"), fileName);
                file.SaveAs(imgPath);
            }
            sqlcmd.Parameters.AddWithValue("@pro_FoodImage", "~/User-Images/" + file.FileName);
            sqlcmd.Parameters.AddWithValue("@pro_dealsName", addfood.pro_dealsName);

            sqlcmd.ExecuteNonQuery();
            con.Close();


            ViewData["Message"] = "Food Record " + addfood.pro_FoodName + "Is Saved Successfully!";



            return(RedirectToAction("ViewRegisterFood"));
        }
예제 #2
0
        //For Edir
        public ActionResult Edit(int id)
        {
            tbl_product_Class productModel = new tbl_product_Class();
            DataTable         dtbProduct   = new DataTable();

            using (SqlConnection sqlcon = new SqlConnection(MyConnection))
            {
                sqlcon.Open();
                string         query = "select * from tbl_product where pro_Food_id = @pro_Food_id";
                SqlDataAdapter sqlDa = new SqlDataAdapter(query, sqlcon);
                sqlDa.SelectCommand.Parameters.AddWithValue("@pro_Food_id", id);
                sqlDa.Fill(dtbProduct);
            }
            if (dtbProduct.Rows.Count == 1)
            {
                productModel.pro_Food_id         = Convert.ToInt32(dtbProduct.Rows[0][0].ToString());
                productModel.pro_FoodName        = dtbProduct.Rows[0][1].ToString();
                productModel.pro_FoodDescription = dtbProduct.Rows[0][2].ToString();
                productModel.pro_FoodPrice       = Convert.ToInt32(dtbProduct.Rows[0][3].ToString());
                productModel.pro_dealsName       = dtbProduct.Rows[0][4].ToString();

                return(View(productModel));
            }
            else
            {
                return(RedirectToAction("ViewRegisterFood"));
            }
        }
예제 #3
0
        public ActionResult Edit(tbl_product_Class productModel)
        {
            using (SqlConnection sqlcon = new SqlConnection(MyConnection))
            {
                sqlcon.Open();
                string     query  = "Update tbl_product set  pro_FoodName =  @pro_FoodName , pro_FoodDescription  = @pro_FoodDescription, pro_FoodPrice =  @pro_FoodPrice ,pro_dealsName = @pro_dealsName  where pro_Food_id = @pro_Food_id ";
                SqlCommand sqlcmd = new SqlCommand(query, sqlcon);
                sqlcmd.Parameters.AddWithValue("@pro_Food_id", productModel.pro_Food_id);

                sqlcmd.Parameters.AddWithValue("@pro_FoodName", productModel.pro_FoodName);
                sqlcmd.Parameters.AddWithValue("@pro_FoodDescription", productModel.pro_FoodDescription);
                sqlcmd.Parameters.AddWithValue("@pro_FoodPrice", productModel.pro_FoodPrice);
                sqlcmd.Parameters.AddWithValue("@pro_dealsName", productModel.pro_dealsName);


                sqlcmd.ExecuteNonQuery();
            }

            return(RedirectToAction("ViewRegisterFood"));
        }
예제 #4
0
        public ActionResult  RegisterFood()
        {
            tbl_product_Class addfood = new tbl_product_Class();

            return(View(addfood));
        }