private void UpdateDepartmentDetailViewModel(TreeViewNode selectedNode) { try { if (selectedNode.ID == -1) { return; } var dept = AuthorizationDepartments.FirstOrDefault(d => d.DepartmentID == selectedNode.ID); var parentDept = AuthorizationDepartments.FirstOrDefault(d => dept.Parent != null && d.DepartmentID == dept.Parent.DepartmentID); SelectedDepartmentDetailViewModel = new DepartmentDetailViewModel() { ID = dept.DepartmentID, DepartmentName = dept.Name, DepartmentCode = dept.DepartmentCode, OwnedDevices = dept.DeviceAssociations.ToList(), DeviceRole = AuthorizationDeviceRoles.First(r => r.DeviceRoleID == dept.DeviceRoleID), ParentDepartment = parentDept, CurrentDepartment = dept, }; RaisePropertyChanged(null); } catch (Exception ex) { Log.Error(ex); } }
public UserViewModel(User userInfo) { SaveCmd = new RelayCommand(Save); CancelCmd = new RelayCommand(() => Close("")); UploadImageCmd = new RelayCommand <string>(UploadImage); DepartmentChangedCmd = new RelayCommand(ProcessDepartmentChangedCmd); CurrentUser = userInfo; DepartmentInfo = new Department(); UserID = userInfo.UserID; IsAddMode = userInfo.UserID == 0; StartDate = DateTime.Now; Birthday = DateTime.Now; UserType = UserType.Employee; ViewModelAttachment = new ViewModelAttachment <User>(); Avator = _userAvatorService.GetAvator(_userAvatorService.DefaultAvatorFileName); Title = IsAddMode ? "新增人员" : "修改人员"; if (!IsAddMode) //Edit mode { UserType = userInfo.Type; UserCode = userInfo.UserCode; Name = userInfo.Name; Status = userInfo.Status == GeneralStatus.Enabled; StartDate = userInfo.StartDate; EndDate = userInfo.EndDate; Phone = userInfo.Phone; Avator = _userAvatorService.GetAvator(userInfo.Photo); DepartmentInfo = AuthorizationDepartments.FirstOrDefault(d => d.DepartmentID == userInfo.DepartmentID); CurrentDepartmentName = DepartmentInfo.Name; Gender = userInfo.Gender; LastName = userInfo.UserPropertyInfo.FirstName; FirstName = userInfo.UserPropertyInfo.FirstName; Nationality = userInfo.UserPropertyInfo.Nationality; NativePlace = userInfo.UserPropertyInfo.NativePlace; Birthday = userInfo.UserPropertyInfo.Birthday; Marriage = userInfo.UserPropertyInfo.Marriage; PoliticalStatus = (userInfo.UserPropertyInfo.PoliticalStatus != null) ? (PoliticalStatus)userInfo.UserPropertyInfo.PoliticalStatus : PoliticalStatus.Unknown; Degree = (userInfo.UserPropertyInfo.Degree != null) ? (DegreeStatus)userInfo.UserPropertyInfo.Degree : DegreeStatus.Unknown; HomeNumber = userInfo.UserPropertyInfo.HomeNumber; EnglishName = userInfo.UserPropertyInfo.EnglishName; Company = userInfo.UserPropertyInfo.Company; TechnicalTitle = userInfo.UserPropertyInfo.TechnicalTitle; TechnicalLevel = userInfo.UserPropertyInfo.TechnicalLevel; IDType = userInfo.UserPropertyInfo.IDType; IDNumber = userInfo.UserPropertyInfo.IDNumber; SocialNumber = userInfo.UserPropertyInfo.SocialNumber; Email = userInfo.UserPropertyInfo.Email; Address = userInfo.UserPropertyInfo.Address; Postcode = userInfo.UserPropertyInfo.Postcode; Remark = userInfo.UserPropertyInfo.Remark; } DeviceRoleListBoxSource = GetDeviceRoleListBoxSource(); }