private static void Task6_AddingNewAdressAndUpdatingEmployee() { var adress = new Address() { AddressText = "Vitoshka 15", TownID = 4 }; Employee employee = null; var context = new SoftuniContext(); using (context) { var nakov = context.Employees .Where(employeeLastName => employeeLastName.LastName == "Nakov") .Take(1); foreach (var nakovName in nakov) { employee = nakovName; } context.Addresses.Add(adress); context.SaveChanges(); var adreesId = context.Addresses .Where(c => c.AddressText == "Vitoshka 15") .Select(b => b.AddressID) .Take(1); int nakovAdressId = 0; foreach (var id in adreesId) { nakovAdressId = id; } employee.AddressID = nakovAdressId; context.SaveChanges(); var output = context.Employees .OrderByDescending(c => c.AddressID) .Select(b => b.Address.AddressText) .Take(10); foreach (var line in output) { Console.WriteLine(line); } } }
private static void Task16_IncreaseSalaries() { var context = new SoftuniContext(); using (context) { var emnployees = context.Employees .Where(employee => employee.Department.Name == "Engineering" || employee.Department.Name == "Tool Design" || employee.Department.Name == "Marketing" || employee.Department.Name == "Information Services"); foreach (var employee in emnployees) { employee.Salary += employee.Salary * (decimal)0.12; Console.WriteLine($"{employee.FirstName} {employee.LastName} (${employee.Salary:F6})"); } context.SaveChanges(); } }
private static void Task7_DeleteProjectById() { var context = new SoftuniContext(); using (context) { var project = context.Projects.Find(2); project.Employees.Clear(); context.Projects.Remove(project); context.SaveChanges(); var allProjectsLeft = context.Projects .Select(a => a.Name) .Take(10); foreach (var projectName in allProjectsLeft) { Console.WriteLine(projectName); } } }