private void UpdateDataGrid() { GoodsInMarketDtos = _mapper.Map <List <GoodsInMarket>, List <GoodsInMarketDTO> >(_goodsInMarketService.GetAll()); GoodsInMarketDtos.Sort(delegate(GoodsInMarketDTO x, GoodsInMarketDTO y) { return(x.Id.CompareTo(y.Id)); }); FilteredGoodsInMarketDtos = GoodsInMarketDtos; FilteredGoodsInMarketDtos.Sort(delegate(GoodsInMarketDTO x, GoodsInMarketDTO y) { return(Convert.ToInt32(x.ProductCode).CompareTo(Convert.ToInt32(y.ProductCode))); }); if (MarketFilterComboBox.SelectedItem != null) { var tempMarket = (MarketDTO)MarketFilterComboBox.SelectedItem; var tempList = FilteredGoodsInMarketDtos.Where(item => item.FullMarketAddress == tempMarket.FullAddress) .ToList(); FilteredGoodsInMarketDtos = tempList; } if (Regex.Match(TitleFilterTextBox.Text, @"^\D{1,20}$").Success) { var tempList = FilteredGoodsInMarketDtos.Where(item => item.Good.Contains(TitleFilterTextBox.Text)) .ToList(); FilteredGoodsInMarketDtos = tempList; } if (CategoryFilterComboBox.SelectedItem != null) { var tempCategory = (CategoryDTO)CategoryFilterComboBox.SelectedItem; var tempList = FilteredGoodsInMarketDtos.Where(item => item.Category == tempCategory.Title).ToList(); FilteredGoodsInMarketDtos = tempList; } if (ProducerFilterComboBox.SelectedItem != null) { var tempProducer = (ProducerDTO)ProducerFilterComboBox.SelectedItem; var tempList = FilteredGoodsInMarketDtos.Where(item => item.Producer == tempProducer.Title).ToList(); FilteredGoodsInMarketDtos = tempList; } DataGrid.ItemsSource = FilteredGoodsInMarketDtos; }
private void CreateBtn_OnClick(object sender, RoutedEventArgs e) { if (!ValidateForm()) { return; } var goodsInMarket = new GoodsInMarket(); Goods tempGoods; var tempMarket = (MarketDTO)MarketComboBox.SelectedItem; if (GoodsInMarketDtos.FirstOrDefault(item => item.ProductCode == ProductCodeTextBox.Text && item.FullMarketAddress == tempMarket.FullAddress) != null) { MessageBox.Show("Such good is already in this market"); return; } goodsInMarket.Id = GoodsInMarketDtos[^ 1]?.Id + 1 ?? 1;