public void DeleteDepartment(DepartmentModel department) { using (geekinsidekmsEntities context = new geekinsidekmsEntities()) { Department dbDept = (from d in context.Departments where d.Id == department.Id select d).FirstOrDefault(); if (dbDept != null) { context.Departments.DeleteObject(dbDept); context.SaveChanges(); } } }
public int CreateDepartment(DepartmentModel department) { using (geekinsidekmsEntities context = new geekinsidekmsEntities()) { Department dbDepartment = new Department { DepartmentName = department.DepartmentName, FolderId = department.FolderId }; context.Departments.AddObject(dbDepartment); context.SaveChanges(); return dbDepartment.Id; } }
public void UpdateDepartment(DepartmentModel department) { using (geekinsidekmsEntities context = new geekinsidekmsEntities()) { Department dbDepartment = new Department { Id = department.Id, DepartmentName = department.DepartmentName, FolderId = department.FolderId }; context.Departments.AddObject(dbDepartment); context.ObjectStateManager.ChangeObjectState(dbDepartment, EntityState.Modified); context.SaveChanges(); } }
// 添加部门 public void CreateDepartment(string deptName, string folderDesc) { FolderModel deptFolder = new FolderModel { FolderName = deptName, Description = folderDesc, ParentFolderId = 0, // 1级目录 PhysicalPath = Helper.CreateNewFolderPath(@"\") // 1级目录存放在根目录下 }; Helper.CreateDirectory(deptFolder.PhysicalPath); // 创建目录 int folderId = folderDAL.CreateFolder(deptFolder); DepartmentModel dept = new DepartmentModel { DepartmentName = deptName, FolderId = folderId }; departmentDAL.CreateDepartment(dept); }
// 更新部门信息 public void UpdateDepartment(DepartmentModel dept) { departmentDAL.UpdateDepartment(dept); }