protected async override void DeleteSelected() { if ( MessageBox.Show("Are you sure you want to delete this commodity Producer?", "Agrimanagr: Delete Commodity Producer", MessageBoxButton.YesNo) == MessageBoxResult.No) return; using (var c = NestedContainer) { if (SelectedCommodityProducer.Status == EntityStatus.Active) { var commodityProducer = Using<ICommodityProducerRepository>(c).GetById(SelectedCommodityProducer.Id) ; if (Using<IMasterDataUsage>(c).CommodityProducerHasPurchases(commodityProducer)) { MessageBox.Show( "Commodity Producer " + SelectedCommodityProducer.Name + " has purchases in the system and thus cannot be deleted.", "Agrimanagr: Delete Commodity Producer", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } ResponseBool response = new ResponseBool() { Success = false }; // 1 if (SelectedCommodityOwner == null) return; if (SelectedCommodityProducer == null) return; _proxy = Using<IDistributorServiceProxy>(c); response = await _proxy.CommodityProducerDeleteAsync(SelectedCommodityProducer.Id); if (response.Success) { var commodityProducer = Using<ICommodityProducerRepository>(c).GetById(SelectedCommodityProducer.Id); Using<ICommodityProducerRepository>(c).SetAsDeleted(commodityProducer); MessageBox.Show(response.ErrorInfo, "Agrimangr:Manage Commodity Producer", MessageBoxButton.OK, MessageBoxImage.Information); Load(); } } }