public static void ModifyEmployee(string firstName, string newFirstName) { using (var db = new SoftUniEntities()) { Employee employee = db.Employees.Where(x => x.FirstName == firstName).FirstOrDefault<Employee>(); employee.FirstName = newFirstName; db.SaveChanges(); } }
public static void RemoveEmployee(string name) { using (var db = new SoftUniEntities()) { var customer = db.Employees.Where(x => x.FirstName == name).FirstOrDefault<Employee>(); db.Employees.Remove(customer); db.SaveChanges(); } }
public static List<Employee> AllEmployeesWIthProjectsAfter() { using (var db = new SoftUniEntities()) { DateTime date = new DateTime(2000); var employees = db.Employees.Where(e => e.Projects.All(p => p.StartDate > date)).ToList(); return employees; } }
public static void ShowEmployee(string firstName) { using (Homework.SoftUniEntities db = new Homework.SoftUniEntities()) { var employee = db.Employees.Where(e => e.FirstName == firstName).FirstOrDefault(); Console.WriteLine(employee.FirstName + " " + employee.LastName); } }
static void Main(string[] args) { SoftUniEntities db = new SoftUniEntities(); var employees = db.Employees.ToList(); foreach (var item in employees) { Console.WriteLine(item.LastName); } }
public static void ListAllEmployees() { using (Homework.SoftUniEntities db = new Homework.SoftUniEntities()) { var employees = db.Employees.ToList(); foreach (var emp in employees) { Console.WriteLine(emp.FirstName + " " + emp.LastName); } } }
public static List<Employee> AllCustomersWithOrdersQuery() { using (var db = new SoftUniEntities()) { string query = "SELECT * FROM Employees e WHERE e.EmployeeID IN (SELECT EmployeeID FROM EmployeesProjects ep JOIN Projects p ON ep.ProjectID = p.ProjectID WHERE p.StartDate > '2002-01-01 00:00:00')"; var queryResult = db.Database.SqlQuery<Employee>(query).ToList(); List<Employee> emp = queryResult.ToList(); return queryResult; } }
public static List<Employee> FindEmployeesByDepartmentAndManager(string department, string managerFirstName, string managerLastName) { using (var db = new SoftUniEntities()) { var employees = from e in db.Employees where e.Department.Name == department && (e.Manager.FirstName == managerFirstName) && (e.Manager.LastName == managerLastName) select e; return employees.ToList(); } }
public static void ListProjects(string name) { using(var db = new SoftUniEntities()) { var projects = from p in db.Projects where p.Name == name select p.Name + ", start date : " + p.StartDate; foreach (var project in projects) { Console.WriteLine(project); } } }
static void Main(string[] args) { SoftUniEntities db = new SoftUniEntities(); // MANAGER NAMES AND DEPARTMENTS //KenSanchez - Executive //JeffHay - Production //CynthiaRandall - Production //DavidLiu - Finance //LauraNorman - Executive //YuhongLi - Production //JamesHamilton - Production var employees = EmployeeMethods.FindEmployeeByDepartmentAndManager("Engineering", "Roberto", "Tamburello"); }
public static void InsertProject(string name, string description, DateTime startDate) { using( var db = new SoftUniEntities()) { Project newProject = new Project() { Name = name, Description = description, StartDate = startDate }; db.Projects.Add(newProject); db.SaveChanges(); } }
static void Main(string[] args) { SoftUniEntities dbOne = new SoftUniEntities(); SoftUniEntities1 dbTwo = new SoftUniEntities1(); var empOne = dbOne.Employees.Where(e => e.DepartmentID == 1).ToArray(); var empTwo = dbOne.Employees.Where(e => e.DepartmentID == 1).ToArray(); for (int i = 0; i < empOne.Length; i++) { empOne[i].FirstName = "Huhum"; empTwo[i].FirstName = "Zazum"; } dbOne.SaveChanges(); dbTwo.SaveChanges(); }
static void Main(string[] args) { using (var db = new SoftUniEntities()) { var firstEmployee = from e in db.Employees where e.EmployeeID == 1 select e; string fName = firstEmployee.FirstOrDefault().FirstName; string lName = firstEmployee.FirstOrDefault().LastName; var projectsByEmp = db.usp_Project_By_Employee(fName, lName).ToList<usp_Project_By_Employee_Result>(); foreach (var item in projectsByEmp) { Console.WriteLine("Project Name: {0}\nDescription: {1}\nStartDate: {2}\nEmployee Name: {3}\n", item.Name, item.Description, item.StartDate, item.Employee); } } }
public static void InsertEmployee(string firstName, string lastName, string jobTitle, string departmentName, DateTime hireDate, decimal salary) { using (var db = new SoftUniEntities()) { var employee = new Employee() { FirstName = firstName, LastName = lastName, JobTitle = jobTitle, DepartmentID = db.Departments .Where(d => d.Name == departmentName) .FirstOrDefault().DepartmentID, HireDate = hireDate, Salary = salary }; db.Employees.Add(employee); db.SaveChanges(); } }