public void DeleteCollection(object param) { try { using (var db = new AliContext()) { // Select group and items for deletion var gs = db.Groups.Where(g => g.Id == (Guid)param).Include(i => i.Items).ToList(); // Delete group foreach (var g in gs) { db.Groups.Remove(g); } db.SaveChanges(); // Delete group from datagrid // Get group by id var group = AliGroups.First(g => g.Id == (Guid)param); // Remove current group AliGroups.Remove(group); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void OpenCollection(object param) { try { var aliItems = new ObservableCollection <AliItem>(); // Get group by id var ai = AliGroups.First(g => g.Id.Equals(param)).Items; // Convert AukroItemModel to AukroItem var itemNo = 0; foreach (var item in ai) { itemNo++; aliItems.Add(new AliItem { Id = item.Id, No = itemNo, Title = item.Title, Price = item.Price, PriceCurrency = item.PriceCurrency, Unit = item.Unit, Seller = item.Seller, Link = item.Link, Description = item.Description, Image = item.Image }); } OnItemsOpened?.Invoke(aliItems); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } }