Пример #1
0
        //
        // Todo, should I reload instead?
        //
        private void DeleteSelectedCompany()
        {
            _repository.DeleteCompany(_writer, SelectedCompany);
            var companyToRemove = AllCompanies.FirstOrDefault(c => c.Id == SelectedCompany.Id);

            if (companyToRemove != null)
            {
                AllCompanies.Remove(companyToRemove);
            }
            SelectedCompany = null;
            SendCompanyCommand.Execute(null);
            FilterList();
        }
Пример #2
0
        private void DeleteCompany_E(object obj)
        {
            try
            {
                if (allCompanySelectedId == null || allCompanySelectedId < 0)
                {
                    MessageBox.Show("Please select a company to delete");
                    return;
                }

                if (MessageBox.Show("Deleting a Company would also delete all data about the company , Including data of all clients " +
                                    "and suppliers, Click Okay to Proceed", "Permanent Delete Information", MessageBoxButton.OKCancel, MessageBoxImage.Information) == MessageBoxResult.Cancel)
                {
                    return;
                }

                if (allCompanySelectedId == 1)
                {
                    MessageBox.Show("Default Company Cannot be deleted", "Invalid Operation", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                var company = db.Companies.Find(allCompanySelectedId);
                if (company == SelectedCompany)
                {
                    MessageBox.Show("The Currently Selected Company Cannot be deleted", "Invalid Operation", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                else if (MessageBox.Show("Are you sure you want to delete the selected Company", "Confirm Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    db.Companies.Remove(company);
                    currentContext.Post(_ =>
                    {
                        AllCompanies.Remove(company);
                    }, null);

                    db.SaveChanges();
                    refreshCs_E(null);
                }
            }
            catch
            {
            }
        }