private string getId() { string result = ""; List <Dish> DishDB = DishDao.GetAll().ToList(); //Get ID in DB var myDishIDs = DishDB.Select(x => x.Id).ToList(); bool Loop = true; int count = 0; do { count++; string newID = $"DISH{count}"; //Check if new ID haven't existed in database var checkItem = myDishIDs.Where(x => x.Contains(newID)).FirstOrDefault(); if (checkItem == null) { result = newID; Loop = false; } else /*Do nothing*/ } { } while (Loop); return(result); }
private void Window_Loaded(object sender, RoutedEventArgs e) { //Dish var DishDB = new List <Dish>(DishDao.GetAll()); myDish = DishDB.Where(x => x.Id == myDishId).FirstOrDefault(); myListStep = new ListViewData(); myListStep.ImageList = new ObservableCollection <List <StepImage> >(); //Step var StepDB = RecipeDetailDao.getData(); StepDetail = new BindingList <RecipeDetail>(StepDB.Where(x => x.dishID == myDishId).ToList()); TotalElement += StepDetail.Count; myBtnList = new BindingList <ButtonList>(); myBtnList.Add(new ButtonList() { buttonName = "Main" }); //video if (myDish.LinkVideo != "") { myDish.LinkVideo = getEmbedYoutubeLink(myDish.LinkVideo); if (myDish.LinkVideo != "") { myBtnList.Add(new ButtonList() { buttonName = "Video" }); videoGrid.Visibility = Visibility.Visible; videoSP.Visibility = Visibility.Visible; videolabel.Visibility = Visibility.Visible; videocef.Visibility = Visibility.Visible; videocef.Address = myDish.LinkVideo; TotalElement++; } } /// for (int i = 0; i < StepDetail.Count; i++) { var ListImgTemp = RecipeDetailDao.getStepImageData(myDishId, i + 1, StepDetail[i].quantityOfImage); myBtnList.Add(new ButtonList() { buttonName = $"Step {i + 1}" }); myListStep.ImageList.Add(ListImgTemp); } stepDetailView.ItemsSource = StepDetail; this.DataContext = myListStep; CarouselBtnSkip.ItemsSource = myBtnList; //Food Type myListType = new BindingList <FoodType>(); var DishTypeDB = Dish_TypeDao.getData(); var myDishType = new List <string>(DishTypeDB.Where(x => x.dishID == myDishId).Select(x => x.typeID).ToList()); var TypeDB = FoodTypeDao.getData(); foreach (var item in myDishType) { var temp = TypeDB.Where(x => x.typeID == item).FirstOrDefault(); myListType.Add(temp); } DishNameLabel.Content = myDish.Name; dishDesTextBlock.Text = myDish.Description; dishIngTextBlock.Text = myDish.Ingredient; var Folder = AppDomain.CurrentDomain.BaseDirectory; var path = $"{Folder}Resources\\Images\\{myDishId}.jpg"; var Bitmap = new BitmapImage(new Uri(path, UriKind.Absolute)); dishImage.Source = Bitmap; tagList.ItemsSource = myListType; }
private void UpdateView() { _dishes_list = DishDao.GetAll(this.ActualWidth, this.ActualHeight, _current_page, filter.SelectedIndex, _is_only_fav, _search); dishesView.ItemsSource = _dishes_list; }