Beispiel #1
0
        private void DeleteService()
        {
            using (var db = new EmployeeContext())
            {
                foreach (var item in db.services.ToList())
                {
                    Console.WriteLine(item);
                }

                // Service choosen to delete
                Service deletedService = null;
                long    response;

                // serviceToDelete contient l'instance à supprimer
                do
                {
                    Console.WriteLine("Choose the id service you want to delete");
                    long.TryParse(Console.ReadLine(), out response);
                    deletedService = db.services.Find(response);
                } while (deletedService == null);

                // sure ?
                int?choice;
                do
                {
                    choice = MenuUtils.GetIntChoice(MenuUtils.deletedServiceChoice(), 1, 3);
                    switch (choice)
                    {
                    case 1:
                        // delete all affected employees
                        // or
                        // affecte a new id service for the employee who lost their id service ?
                        int?newIdServiceChoice;
                        do
                        {
                            newIdServiceChoice = MenuUtils.GetIntChoice(MenuUtils.NewIdServiceChoice(), 1, 4);
                            switch (newIdServiceChoice)
                            {
                            case 1:
                                AffectedNewIdServiceAllEmployees(deletedService);
                                break;

                            case 2:
                                AffectedNewIdServiceEachEmployees(deletedService);
                                break;

                            case 3:
                                DeleteAllAffectedEmployees(deletedService);
                                break;

                            case 4:
                                DeleteService();
                                break;
                            }
                        } while (newIdServiceChoice != 1 || newIdServiceChoice != 2 || newIdServiceChoice != 3 || newIdServiceChoice != 4);
                        ;

                        break;

                    case 2:
                        DeleteService();
                        break;

                    case 3:
                        CUDService();
                        break;
                    }
                } while (choice != 1 || choice != 2 || choice != 3);



                // save
                db.SaveChanges();
            }
        }