public CommContracts.Department GetCurrentDepartment(int employeeID) { using (DAL.HisContext ctx = new DAL.HisContext()) { var query = from u in ctx.EmployeeDepartmentHistorys where u.EmployeeID == employeeID && !u.EndDate.HasValue select u.Department; if (query.Count() == 1) { DAL.Department department = query.First() as DAL.Department; var config = new MapperConfiguration(cfg => { cfg.CreateMap <DAL.Department, CommContracts.Department>(); }); var mapper = config.CreateMapper(); CommContracts.Department temp = new CommContracts.Department(); temp = mapper.Map <CommContracts.Department>(department); return(temp); } return(null); } }
public bool SaveDepartment(CommContracts.Department department) { using (DAL.HisContext ctx = new DAL.HisContext()) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <CommContracts.Department, DAL.Department>(); }); var mapper = config.CreateMapper(); DAL.Department temp = new DAL.Department(); temp = mapper.Map <DAL.Department>(department); ctx.Departments.Add(temp); try { ctx.SaveChanges(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(false); } } return(true); }
public bool UpdateDepartment(CommContracts.Department department) { using (DAL.HisContext ctx = new DAL.HisContext()) { var temp = ctx.Departments.FirstOrDefault(m => m.ID == department.ID); if (temp != null) { //temp = mapper.Map<DAL.Department>(department); // 这里使用mapper来更新数据之后保存不上,不知为何 temp.Name = department.Name; temp.Abbr = department.Abbr; temp.DepartmentEnum = (DAL.DepartmentEnum)department.DepartmentEnum; temp.DepartmentAddress = department.DepartmentAddress; } else { return(false); } try { ctx.SaveChanges(); } #pragma warning disable CS0168 // 声明了变量“ex”,但从未使用过 catch (Exception ex) #pragma warning restore CS0168 // 声明了变量“ex”,但从未使用过 { return(false); } } return(true); }
public EditDepartmentView(CommContracts.Department department = null) { InitializeComponent(); DepartmentCombo.ItemsSource = Enum.GetValues(typeof(CommContracts.DepartmentEnum)); DepartmentCombo.SelectedItem = CommContracts.DepartmentEnum.其他科室; bIsEdit = false; if (department != null) { this.Department = department; this.NameEdit.Text = department.Name; this.AbbrEdit.Text = department.Abbr; this.DepartmentCombo.SelectedItem = department.DepartmentEnum; bIsEdit = true; } }
private void SaveBtn_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(this.NameEdit.Text.Trim())) { return; } if (this.DepartmentCombo.SelectedItem == null) { return; } if (bIsEdit) { Department.Name = this.NameEdit.Text.Trim(); Department.Abbr = this.AbbrEdit.Text.Trim(); Department.DepartmentEnum = (CommContracts.DepartmentEnum) this.DepartmentCombo.SelectedItem; CommClient.Department myd = new CommClient.Department(); if (myd.UpdateDepartment(Department)) { (this.Parent as Window).DialogResult = true; (this.Parent as Window).Close(); } } else { CommContracts.Department department = new CommContracts.Department(); department.Name = this.NameEdit.Text.Trim(); department.Abbr = this.AbbrEdit.Text.Trim(); department.DepartmentEnum = (CommContracts.DepartmentEnum) this.DepartmentCombo.SelectedItem; CommClient.Department myd = new CommClient.Department(); if (myd.SaveDepartment(department)) { (this.Parent as Window).DialogResult = true; (this.Parent as Window).Close(); } } }
public List <CommContracts.Department> getALLDepartment(string strName = "") { List <CommContracts.Department> list = new List <CommContracts.Department>(); using (DAL.HisContext ctx = new DAL.HisContext()) { var query = from u in ctx.Departments where u.Name.StartsWith(strName) select u; foreach (DAL.Department ass in query) { var config = new MapperConfiguration(cfg => { cfg.CreateMap <DAL.Department, CommContracts.Department>(); }); var mapper = config.CreateMapper(); CommContracts.Department temp = mapper.Map <CommContracts.Department>(ass); list.Add(temp); } } return(list); }