public eMenuFood geteMenu([FromBody] MODEL.Criteria.reqeMenu req) { eMenuFood result = new eMenuFood(); result.ResultOk = "false"; eMenuBLL sv = new eMenuBLL(); try { //Veriy Data if (req != null) { return(sv.getFoodseMenu(req)); } } catch (Exception e) { result.ErrorMessage = e.Message; result.ResultOk = "false"; } return(result); }
public eMenuFood getFoodseMenu(MODEL.Criteria.reqeMenu req) { SqlConnection conn = new SqlConnection(DataHelper.GetConnectionString()); DataSet ds = new DataSet(); eMenuFood res = new eMenuFood(); try { conn.Open(); StringBuilder sqlstr = new StringBuilder(); sqlstr.Append("select menu.menu_id,LV1.category_lv1_id,LV1.category_lv1_name"); sqlstr.Append(",LV2.category_lv2_id,LV2.category_lv2_name"); sqlstr.Append(",menu.menu_name,menu.menu_description,menu.menu_price"); sqlstr.Append(",menu.menu_picture,menu.menu_flag_recommend"); sqlstr.Append(" from tb_Menu as menu"); sqlstr.Append(" inner join tb_Category_LV1 as [LV1] on LV1.category_lv1_id = menu.menu_category_lv1"); sqlstr.Append(" inner join tb_Category_LV2 as [LV2] on LV2.category_lv2_id = menu.menu_category_lv2"); sqlstr.Append(" where menu.restaurant_id = '" + req.restaurantID + "'"); //if (req.recommend == "1") //{ // sqlstr.Append(" and menu.menu_flag_recommend = '1'"); //} //else if (req.recommend == "2") //{ // sqlstr.Append(" and LV2.category_lv2_id = 24"); //} //else //{ //} SqlDataAdapter adp = new SqlDataAdapter(sqlstr.ToString(), conn); adp.SelectCommand.CommandType = CommandType.Text; adp.Fill(ds); DataTable dt = new DataTable(); //eMenuFood res = new eMenuFood(); dt = ds.Tables[0]; if (dt.Rows.Count > 0) { res.ResultOk = "true"; res.ErrorMessage = ""; List <eMenuFood> listeMenu = new List <eMenuFood>(); List <MODEL.FoodGroup> listMasterFoods = new List <MODEL.FoodGroup>(); List <MODEL.FoodGroup> listGroupFoods = new List <MODEL.FoodGroup>(); MODEL.FoodGroup MDrinks = new FoodGroup(); List <FoodsItems> listFoodsItem; FoodsItems FoodsItem; FoodGroup MFoods; //DataTable dtCategoryLV1 = new DataTable(); //dtCategoryLV1 = getCategoryeMenu(req); //DataTable dtFood = new DataTable(); //DataRow[] rowsFoods = dt.Select(""); FoodGroup Group; listGroupFoods = getCategoryeMenu(req); foreach (FoodGroup item in listGroupFoods) { Group = new FoodGroup(); Group.foodsTypeIDLevel1 = item.foodsTypeIDLevel1; Group.foodsTypeNameLevel1 = item.foodsTypeNameLevel1; Group.foodsTypeIDLevel2 = item.foodsTypeIDLevel2; Group.foodsTypeNameLevel2 = item.foodsTypeNameLevel2; MODEL.Criteria.reqeMenu reqMenu = new MODEL.Criteria.reqeMenu(); reqMenu.restaurantID = req.restaurantID; reqMenu.MenuCategoryLV1ID = Group.foodsTypeIDLevel1; reqMenu.MenuCategoryLV2ID = Group.foodsTypeIDLevel2; reqMenu.recommend = req.recommend; listFoodsItem = new List <FoodsItems>(); listFoodsItem = getFoodsItemInGroup(reqMenu); //FoodsItems model; //foreach (FoodsItems itemFoods in listFoodsItem) //{ // model = new FoodsItems(); // model = itemFoods; //} Group.foodsItems = listFoodsItem; listMasterFoods.Add(Group); } res.CountMenu = ""; MODEL.Restaurant modelRestaurant = new MODEL.Restaurant(); modelRestaurant = svRestaurant.getRestaurant(req.restaurantID); if (modelRestaurant != null) { res.restuarantName = modelRestaurant.RestaurantName; res.imageRestuarant = modelRestaurant.RestaurantImagePath; } else { res.restuarantName = ""; res.imageRestuarant = ""; } res.Data = listMasterFoods; //foreach (DataRow row in rowsFoods) //{ // listFoodsItem = new List<FoodsItems>(); // MFoods = new FoodGroup(); // MFoods.foodsTypeIDLevel1 = row["category_lv1_id"].ToString().Trim(); // MFoods.foodsTypeNameLevel1 = row["category_lv1_name"].ToString().Trim(); // MFoods.foodsTypeIDLevel2 = row["category_lv2_id"].ToString().Trim(); // MFoods.foodsTypeNameLevel2 = row["category_lv2_name"].ToString().Trim(); // FoodsItem = new FoodsItems(); // FoodsItem.foodID = row["menu_id"].ToString().Trim(); // FoodsItem.foodName = row["menu_name"].ToString().Trim(); // FoodsItem.Size = ""; // FoodsItem.Price = row["menu_price"].ToString().Trim(); // FoodsItem.Description = row["menu_description"].ToString().Trim(); // FoodsItem.ImagePath = row["menu_picture"].ToString().Trim(); // listFoodsItem.Add(FoodsItem); // MFoods.foodsItems = listFoodsItem; // listMFoods.Add(MFoods); // //Console.WriteLine("{0}, {1}", row[0], row[1]); //} //res.CountMenu = listMFoods.Count.ToString().Trim(); //res.Data = listMFoods; //res.Data.Add(MDrinks); } } catch (Exception ex) { res.ResultOk = "false"; res.ErrorMessage = ex.Message; //throw ex; } finally { conn.Close(); } return(res); }