//[ActionName("Create")]
        //[ValidateAntiForgeryToken]
        public ActionResult Create(BusinessLayer.FoodItem fooditem)//Create(FormCollection formCollection)
        {
            if (ModelState.IsValid)
            {
                dbset.AddFoodItemToDB(fooditem);
                return(RedirectToAction("Index"));
            }

            /*FoodItem fooditem = new FoodItem();
             * // Retrieve form data using form collection
             * fooditem.FoodName = formCollection["FoodName"];
             * fooditem.FoodGroupId = Convert.ToDecimal(formCollection["FoodGroupId"]);
             * fooditem.FoodCost = Convert.ToDecimal(formCollection["FoodCost"]);
             * fooditem.FoodWeightTypeId = Convert.ToDecimal(formCollection["FoodWeightTypeId"]);
             * fooditem.SellerId = Convert.ToDecimal(formCollection["SellerId"]);
             * fooditem.QuantityAvailable = Convert.ToInt32(formCollection["QuantityAvailable"]);
             * fooditem.SubFoodGroupId = Convert.ToDecimal(formCollection["SubFoodGroupId"]);
             */
            ViewBag.FoodGroupId      = new SelectList(dbset.FoodGroups.OrderBy(x => x.FoodGroupName), "FoodGroupId", "FoodGroupName");
            ViewBag.SubFoodGroupId   = new SelectList(dbset.SubFoodGroups.OrderBy(x => x.SubFoodGroupName), "SubFoodGroupId", "SubFoodGroupName");
            ViewBag.FoodWeightTypeId = new SelectList(dbset.FoodWeightTypes.OrderBy(x => x.FoodWeightTypeName), "FoodWeightTypeId", "FoodWeightTypeName");
            ViewBag.SellerId         = new SelectList(dbset.SellerDetails.OrderBy(x => x.SellerAccountName), "SellerId", "SellerName");

            return(View());
        }
        public ActionResult Edit(decimal id)
        {
            BusinessLayer.FoodItem fooditem = dbset.FoodItems.Single(emp => emp.FoodItemId == id);
            if (fooditem == null)
            {
                return(HttpNotFound());
            }
            ViewBag.FoodGroupId      = new SelectList(dbset.FoodGroups.OrderBy(x => x.FoodGroupName), "FoodGroupId", "FoodGroupName", fooditem.FoodGroupId);
            ViewBag.SubFoodGroupId   = new SelectList(dbset.SubFoodGroups.OrderBy(x => x.SubFoodGroupName), "SubFoodGroupId", "SubFoodGroupName", fooditem.SubFoodGroupId);
            ViewBag.FoodWeightTypeId = new SelectList(dbset.FoodWeightTypes.OrderBy(x => x.FoodWeightTypeName), "FoodWeightTypeId", "FoodWeightTypeName", fooditem.FoodWeightTypeId);
            ViewBag.SellerId         = new SelectList(dbset.SellerDetails.OrderBy(x => x.SellerAccountName), "SellerId", "SellerName", fooditem.SellerId);

            return(View(fooditem));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(BusinessLayer.FoodItem fooditem)
        {
            if (ModelState.IsValid)
            {
                dbset.SaveChangesFoodItemToDB(fooditem);
                //db.Entry(fooditem).State = EntityState.Modified;
                //db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.FoodGroupId      = new SelectList(dbset.FoodGroups.OrderBy(x => x.FoodGroupName), "FoodGroupId", "FoodGroupName", fooditem.FoodGroupId);
            ViewBag.SubFoodGroupId   = new SelectList(dbset.SubFoodGroups.OrderBy(x => x.SubFoodGroupName), "SubFoodGroupId", "SubFoodGroupName", fooditem.SubFoodGroupId);
            ViewBag.FoodWeightTypeId = new SelectList(dbset.FoodWeightTypes.OrderBy(x => x.FoodWeightTypeName), "FoodWeightTypeId", "FoodWeightTypeName", fooditem.FoodWeightTypeId);
            ViewBag.SellerId         = new SelectList(dbset.SellerDetails.OrderBy(x => x.SellerAccountName), "SellerId", "SellerName", fooditem.SellerId);

            return(View(fooditem));
        }
        public IEnumerable <FoodItem> GetSearchRequest(string str)
        {
            List <FoodItem> fooditems = new List <FoodItem>();
            var             strings   = str.Split(' ');

            foreach (var splitString in strings)
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetSearchFoodItems", con);
                    cmd.CommandType = CommandType.StoredProcedure;

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

                    con.Open();
                    // cmd.ExecuteNonQuery();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        FoodItem fooditem = new FoodItem();
                        fooditem.FoodItemId        = Convert.ToDecimal(rdr["FoodItemId"]);
                        fooditem.FoodName          = rdr["FoodName"].ToString();
                        fooditem.FoodGroupId       = Convert.ToDecimal(rdr["FoodGroupId"]);
                        fooditem.FoodCost          = Convert.ToDecimal(rdr["FoodCost"].ToString());
                        fooditem.FoodWeightTypeId  = Convert.ToDecimal(rdr["FoodWeightTypeId"]);
                        fooditem.SellerId          = Convert.ToDecimal(rdr["SellerId"]);
                        fooditem.QuantityAvailable = Convert.ToInt32(rdr["QuantityAvailable"]);
                        fooditem.SubFoodGroupId    = Convert.ToDecimal(rdr["SubFoodGroupId"]);
                        fooditem.FoodPicture       = rdr["FoodPicture"].ToString();
                        fooditem.AlternateText     = rdr["AlternateText"].ToString();
                        fooditems.Add(fooditem);
                    }
                    rdr.Dispose();
                }
            }

            var DistinctItems = fooditems.GroupBy(x => x.FoodItemId).Select(y => y.First());

            return(DistinctItems);
        }
        //
        // GET: /Store/AddToCart/5
        //[ChildActionOnly]
        public ActionResult AddToCart(decimal id)
        //public ActionResult AddToCart(BusinessLayer.FoodItem id)
        {
            // Retrieve the album from the database

            /*BusinessLayer.FoodItem addedAlbum = storeDB.FoodItems
             *  .Single(album => album.FoodItemId == id);*/
            BusinessLayer.FoodItem fooditem = dbset.FoodItems.Single(emp => emp.FoodItemId == id);

            //Get SubgroupID

            decimal subgrpId = fooditem.FoodGroupId;

            // Add it to the shopping cart
            BusinessLayer.ShoppingCart cart = BusinessLayer.ShoppingCart.GetCart(this.HttpContext);

            cart.AddToCart(fooditem);
            //cart.AddToCart(id);

            // Go back to the main store page for more shopping
            //return RedirectToAction("Index", "Home");
            return(RedirectToAction("Browse", "Store", new { id = subgrpId }));
        }
        public void AddFoodItemToDB(FoodItem employee)
        {
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                SqlCommand cmd = new SqlCommand("spAddFoodItems", con);
                cmd.CommandType = CommandType.StoredProcedure;

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

                SqlParameter paramFoodGrpId = new SqlParameter();
                paramFoodGrpId.ParameterName = "@FoodGroupId";
                paramFoodGrpId.Value         = employee.FoodGroupId;
                cmd.Parameters.Add(paramFoodGrpId);

                SqlParameter paramFoodCost = new SqlParameter();
                paramFoodCost.ParameterName = "@FoodCost";
                paramFoodCost.Value         = employee.FoodCost;
                cmd.Parameters.Add(paramFoodCost);

                SqlParameter paramFoodWeigth = new SqlParameter();
                paramFoodWeigth.ParameterName = "@FoodWeightTypeId";
                paramFoodWeigth.Value         = employee.FoodWeightTypeId;
                cmd.Parameters.Add(paramFoodWeigth);

                SqlParameter paramQtyAvailable = new SqlParameter();
                paramQtyAvailable.ParameterName = "@QuantityAvailable";
                paramQtyAvailable.Value         = employee.QuantityAvailable;
                cmd.Parameters.Add(paramQtyAvailable);

                SqlParameter paramSellerId = new SqlParameter();
                paramSellerId.ParameterName = "@SellerId";
                paramSellerId.Value         = employee.SellerId;
                cmd.Parameters.Add(paramSellerId);

                SqlParameter paramSubGrpId = new SqlParameter();
                paramSubGrpId.ParameterName = "@SubFoodGroupId";
                paramSubGrpId.Value         = employee.SubFoodGroupId;
                cmd.Parameters.Add(paramSubGrpId);

                SqlParameter paramBuyingPrice = new SqlParameter();
                paramBuyingPrice.ParameterName = "@BuyingPrice";
                paramBuyingPrice.Value         = employee.BuyingPrice;
                cmd.Parameters.Add(paramBuyingPrice);

                SqlParameter paramAlternateText = new SqlParameter();
                paramAlternateText.ParameterName = "@AlternteText";
                paramAlternateText.Value         = employee.AlternateText;
                cmd.Parameters.Add(paramAlternateText);


                SqlParameter paramFoodPicture = new SqlParameter();
                paramFoodPicture.ParameterName = "@FoodPicture";
                paramFoodPicture.Value         = employee.FoodPicture;
                cmd.Parameters.Add(paramFoodPicture);

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