예제 #1
0
        public static void AddNewProject(
            string projectName,
            DateTime startDate,
            DateTime? endDate = null,
            string projectDescription = null,
            params int[] employeesId
            )
        {
            var project = new Project
            {
                Name = projectName,
                Description = projectDescription,
                StartDate = startDate,
                EndDate = endDate,
            };

            using (var db = new SoftUniEntities())
            {

                foreach (var id in employeesId)
                {
                    project.Employees.Add(db.Employees.Find(id));
                }

                db.Projects.Add(project);
                db.SaveChanges();
            }
        }
예제 #2
0
        //06.Adding a new address and updating Employee
        private static void AddAddress(SoftUniEntities context)
        {
            //var address = new Address()
            //{
            //    AddressText = "Vitoshka 15",
            //    TownID = 4
            //};
            //context.Addresses.Add(address);
            //context.SaveChanges();

            //Employee emp = context.Employees.FirstOrDefault(e => e.LastName == "Nakov");
            //emp.Address = address;
            //context.SaveChanges();


            var address = new Address()
            {
                AddressText = "Vitoshka 15",
                TownID      = 4
            };
            Employee emp = context.Employees.FirstOrDefault(e => e.LastName == "Nakov");

            emp.Address = address;
            context.SaveChanges();

            var addresses = context.Employees.OrderByDescending(e => e.AddressID).Take(10).ToList();

            foreach (var e in addresses)
            {
                Console.WriteLine(e.Address.AddressText);
            }
        }
예제 #3
0
 public static void DeleteEmployee(int employeeId)
 {
     using (var db = new SoftUniEntities())
     {
         db.Employees.Remove(db.Employees.Find(employeeId));
         db.SaveChanges();
     }
 }
        public static void Add(Employee employee)
        {
            var context = new SoftUniEntities();

            context.Employees.Add(employee);

            context.SaveChanges();
        }
        public static void Delete(Employee employee)
        {
            var context = new SoftUniEntities();

            context.Employees.Remove(employee);

            context.SaveChanges();
        }
        public static void Modify(Employee employee)
        {
            var context = new SoftUniEntities();

            context.Employees.Attach(employee);
            context.Entry(employee).State = EntityState.Modified;

            context.SaveChanges();
        }
예제 #7
0
        //15.Delete project by ID
        private static void DeletProject(SoftUniEntities context)
        {
            var projects = context.Projects.Find(2);

            foreach (var emp in projects.Employees)
            {
                emp.Projects.Remove(projects);
            }
            context.Projects.Remove(projects);
            context.SaveChanges();

            var result = context.Projects.Take(10);

            foreach (var pr in result)
            {
                Console.WriteLine(pr.Name);
            }
        }
예제 #8
0
        //12.Increase Salary
        private static void IncreaseSalary(SoftUniEntities context)
        {
            IEnumerable <Employee> employees = context.Employees
                                               .Where(
                e => e.Department.Name == "Engineering" ||
                e.Department.Name == "Tool Design" ||
                e.Department.Name == "Marketing" ||
                e.Department.Name == "Information Services");

            foreach (Employee e in employees)
            {
                e.Salary += e.Salary * 0.12M;

                Console.WriteLine($"{e.FirstName} {e.LastName} (${e.Salary})");
            }

            context.SaveChanges();
        }
예제 #9
0
        public static void ModifyEmployee(
            Employee employee,
            string FirstName = null,
            string MiddleName = null,
            string LastName = null,
            string JobTitle = null,
            int? DepartmentID = null,
            int? ManagerID = null,
            DateTime? HireDate = null,
            decimal? Salary = null,
            int? AddressID = null
            )
        {
            using (var db = new SoftUniEntities())
            {
                var emp = db.Employees.Find(employee.EmployeeID);

                if (FirstName != null)
                {
                    emp.FirstName = FirstName;
                }
                if (MiddleName != null)
                {
                    emp.MiddleName = MiddleName;
                }
                if (LastName != null)
                {
                    emp.LastName = LastName;
                }
                if (JobTitle != null)
                {
                    emp.JobTitle = JobTitle;
                }
                if (DepartmentID != null)
                {
                    emp.DepartmentID = (int)DepartmentID;
                }
                if (ManagerID != null)
                {
                    emp.ManagerID = ManagerID;
                }
                if (HireDate != null)
                {
                    emp.HireDate = (DateTime)HireDate;
                }
                if (Salary != null)
                {
                    emp.Salary = (decimal)Salary;
                }
                if (AddressID != null)
                {
                    emp.AddressID = AddressID;
                }

                db.SaveChanges();
            }
        }
예제 #10
0
 public static void InsertEmployee(Employee employee)
 {
     using (var db = new SoftUniEntities())
     {
         db.Employees.Add(employee);
         db.SaveChanges();
     }
 }