private void RemoveSubCategory() { try { using (var ctx = new ServerContext()) { List <Standardprice> subCategoryList = ctx.Standardprices.Where(x => x.id.CompareTo(SelectedSubCategory.id) == 0).ToList(); Standardprice subCategory = subCategoryList.First(); ctx.Standardprices.Remove(subCategory); ctx.SaveChanges(); } this.AllSubCategories.Remove(this.SelectedSubCategory); this.ShownSubCategories.Remove(this.SelectedSubCategory); } catch (System.Data.DataException) { PopupService.PopupMessage(Application.Current.FindResource("CouldNotConnectToDatabase").ToString(), Application.Current.FindResource("Error").ToString()); } }
//help method for RemoveCategory private void RemoveSubCategories() { try { using (var ctx = new ServerContext()) { List <Standardprice> subCategoryList = ctx.Standardprices.Where(x => x.Parent_id.CompareTo(SelectedCategory.id) == 0).ToList(); foreach (Standardprice subcategory in subCategoryList) { Standardprice tmp = new Standardprice(); tmp = subcategory; ctx.Standardprices.Remove(tmp); ctx.SaveChanges(); } } } catch (System.Data.DataException) { PopupService.PopupMessage(Application.Current.FindResource("CouldNotConnectToDatabase").ToString(), Application.Current.FindResource("Error").ToString()); } }