private static void P12_IncreaseSalaries(SoftuniContext context) { string[] departmentNames = new[] { "Engineering", "Tool Design", "Marketing", "Information Services" }; var employees = context.Employees .Where(e => departmentNames.Contains(e.Department.Name)); foreach (Employee e in employees) { e.Salary *= 1.12m; } context.SaveChanges(); foreach (Employee e in employees) { Console.WriteLine($"{e.FirstName} {e.LastName} (${e.Salary:f6})"); } }
private static void P15_DeleteProjectById(SoftuniContext context) { Project targetProject = context.Projects.Find(2); if (targetProject != null) { foreach (Employee employee in targetProject.Employees) { employee.Projects.Remove(targetProject); } context.Projects.Remove(targetProject); context.SaveChanges(); } var projects = context.Projects.Select(p => p.Name).Take(10); foreach (var p in projects) { Console.WriteLine(p); } }
private static void P06_AddNewAddressUpdateEmployee(SoftuniContext context) { Address address = new Address() { AddressText = "Vitoshka 15", TownID = 4 }; Employee employee = context.Employees.FirstOrDefault(e => e.LastName == "Nakov"); if (employee != null) { employee.Address = address; context.SaveChanges(); } var employees = context.Employees .OrderByDescending(e => e.AddressID) .Take(10) .Select(e => e.Address.AddressText); foreach (var addressText in employees) { Console.WriteLine(addressText); } }