コード例 #1
0
        private void ServiceMenu()

        {
            PrintFromDb <Service>((EmployeeContext db) =>
            {
                return(db.Services.AsNoTracking().ToList());
            });



            int?serviceId = MenuUtils.GetIntChoice("Choose service by id", 1, int.MaxValue);



            int?choice = MenuUtils.GetIntChoice(MenuUtils.ServiceMenu(), 1, 4);



            Console.WriteLine("Service " + serviceId + " selected");

            PrintFromDb <Service>((EmployeeContext db) =>
            {
                return(db.Services.AsNoTracking().Where(x => x.ServiceId == serviceId).ToList());
            });



            switch (choice)

            {
            case 1:

                PrintFromDb <Employee>((EmployeeContext db) =>
                {
                    return(db.Employees.AsNoTracking().Where(x => x.Department.ServiceId == serviceId).ToList());
                });

                SalaryChargeMenu((EmployeeContext db) =>

                {
                    return(db.Employees.AsNoTracking().Include(x => x.Department).Where(x => x.Department.ServiceId == serviceId).Sum(x => x.Salary));
                }, ServiceMenu);

                break;

            case 2:

                using (var db = new EmployeeContext())

                {
                    if (db.Employees.Include(x => x.Department).Where(x => x.Department.ServiceId == serviceId).Count() > 0)

                    {
                        Console.WriteLine(db.Employees.Include(x => x.Department).Where(x => x.Department.ServiceId == serviceId).Sum(x => x.Salary));
                    }
                }

                break;

            case 3:

                CUDService();

                break;

            case 4:

                MainMenu();

                break;

            default:

                break;
            }
        }