Ejemplo n.º 1
0
 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();
     }
 }
Ejemplo n.º 2
0
 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();
     }
 }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
        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);

            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            SoftUniEntities db = new SoftUniEntities();

            var employees = db.Employees.ToList();

            foreach (var item in employees)
            {
                Console.WriteLine(item.LastName);
            }
        }
Ejemplo n.º 6
0
 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);
         }
     }
 }
Ejemplo n.º 7
0
        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;
            }
        }
Ejemplo n.º 8
0
        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();
            }
        }
Ejemplo n.º 9
0
        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);
                }
            }
        }
Ejemplo n.º 10
0
        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");
        }
Ejemplo n.º 11
0
        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();
            }
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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);

                }
            }
        }
Ejemplo n.º 14
0
 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();
     }
 }