示例#1
0
 public static void DeleteDepartment(Department dp)
 {
     using (Lvl2Lesson7DBEntities db = new Lvl2Lesson7DBEntities())
     {
         var dep = db.tbl_Departments.Where(x => x.Name_Department.Equals(dp.NameDepartment)).FirstOrDefault();
         db.tbl_Departments.Remove(dep);
     }
 }
示例#2
0
 public static void EditEmployeeDepartment(Employees emp, string newDepartment)
 {
     using (Lvl2Lesson7DBEntities db = new Lvl2Lesson7DBEntities())
     {
         db.tbl_Employees.Where(x => x.First_Name.Equals(emp.FirstName) && x.Last_Name.Equals(emp.LastName))
         .FirstOrDefault().Code_Department = db.tbl_Departments.Where(x => x.Name_Department.Equals(newDepartment)).FirstOrDefault().ID_Departments;
         db.SaveChanges();
     }
 }
示例#3
0
 public static void AddDepartment(string nameDepartment)
 {
     using (Lvl2Lesson7DBEntities db = new Lvl2Lesson7DBEntities())
     {
         db.tbl_Departments.Add(new tbl_Departments {
             Name_Department = nameDepartment
         });
         db.SaveChanges();
     }
 }
示例#4
0
 public static void CreateEmployee(string firstName, string lastName, string nameDepartment)
 {
     using (Lvl2Lesson7DBEntities db = new Lvl2Lesson7DBEntities())
     {
         tbl_Employees emp = new tbl_Employees {
             First_Name      = firstName,
             Last_Name       = lastName,
             Code_Department = db.tbl_Departments.Where(x => x.Name_Department.Equals(nameDepartment)).FirstOrDefault().ID_Departments
         };
         db.tbl_Employees.Add(emp);
         db.SaveChanges();
     }
 }
示例#5
0
        public static ObservableCollection <Department> GetDepartments()
        {
            ObservableCollection <Department> liDep = new ObservableCollection <Department>();

            using (Lvl2Lesson7DBEntities db = new Lvl2Lesson7DBEntities())
            {
                var rawDepartments = db.tbl_Departments.ToList();
                foreach (var item in rawDepartments)
                {
                    liDep.Add(new Department {
                        NameDepartment = item.Name_Department
                    });
                }
            }
            return(liDep);
        }
示例#6
0
        public static ObservableCollection <Employees> GetEmployees()
        {
            ObservableCollection <Employees> liEmp = new ObservableCollection <Employees>();

            using (Lvl2Lesson7DBEntities db = new Lvl2Lesson7DBEntities())
            {
                var rawEmployees = db.tbl_Employees.ToList();

                foreach (var item in rawEmployees)
                {
                    string depart = db.tbl_Departments.Where(x => x.ID_Departments == item.Code_Department).FirstOrDefault().Name_Department;
                    liEmp.Add(new Employees(item.First_Name, item.Last_Name, new Department {
                        NameDepartment = depart
                    }));
                }
            }

            return(liEmp);
        }