예제 #1
0
        private void DeleteTimeGroup()
        {
            try
            {
                if (SelectedTimeGroupViewModel == null)
                {
                    Messenger.Default.Send(new NotificationMessage("请先选择时间组!"), Tokens.TimeGroupPage_ShowNotification);
                    return;
                }

                var timeZones = _timeZoneRepo.Query(new Hashtable());
                if (timeZones.Any())
                {
                    var timeGroupsInUsing = timeZones.SelectMany(x => x.TimeGroupAssociations);
                    if (timeGroupsInUsing.Any(x => x.TimeGroupID == SelectedTimeGroupViewModel.TimeGroupID))
                    {
                        Messenger.Default.Send(new NotificationMessage("该时间组已经被关联到时间区,不能删除!"), Tokens.TimeGroupPage_ShowNotification);
                        return;
                    }
                }

                string question = string.Format("确定删除时间组:{0}吗?", SelectedTimeGroupViewModel.Name);
                Messenger.Default.Send(new NotificationMessageAction(this, question, ConfirmDeleteTimeGroup), Tokens.TimeGroupPage_ShowQuestion);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #2
0
        public TimeZonePageViewModel()
        {
            AddCmd               = new AuthCommand(AddTimeZone);
            ModifyCmd            = new AuthCommand(ModifyTimeZone);
            DeleteCmd            = new AuthCommand(DeleteTimeZone);
            TimeZoneDashboardCmd = new RelayCommand(OpenTimeZoneDetail);

            TimeZoneViewModels = new ObservableCollection <TimeZoneViewModel>();
            var timezones = _timeZoneRepo.Query(new Hashtable()).ToList();

            timezones.ForEach(t => TimeZoneViewModels.Add(new TimeZoneViewModel(t)));
        }
예제 #3
0
        public void UpdateUserDeviceRole(User systemUserInfo)
        {
            var userDeviceRoles = new List <UserDeviceRole>();

            if (systemUserInfo.DepartmentID != 0)
            {
                var departmentRepo = RepositoryManager.GetRepository <IDepartmentRepository>();
                var departmentInfo = departmentRepo.GetByKey(systemUserInfo.DepartmentID);
                if (departmentInfo != null)
                {
                    userDeviceRoles.Add(new UserDeviceRole()
                    {
                        UserID = systemUserInfo.UserID, DeviceRoleID = departmentInfo.DeviceRoleID
                    });
                }
            }

            var deviceRoles = _deviceRole.Query(new Hashtable {
                { "Status", (int)GeneralStatus.Enabled }
            }).ToList();
            var timezoneInfos = _timeZoneRepo.Query(new Hashtable {
                { "Status", (int)GeneralStatus.Enabled }
            }).ToList();
            var role = deviceRoles.FirstOrDefault(x => CheckRoleForUser(x, userDeviceInfoDict, timezoneInfos));

            if (role != null)
            {
                if (userDeviceRoles.All(x => x.DeviceRoleID != role.DeviceRoleID))
                {
                    userDeviceRoles.Add(new UserDeviceRole()
                    {
                        UserID = systemUserInfo.UserID, DeviceRoleID = role.DeviceRoleID
                    });
                }
            }
            else
            {
                Log.Info("Cannot find existing device roles matches user, trying to apply default role for user.");
                var defaultRole = GetDefaultRole(deviceRoles);
                if (defaultRole != null && userDeviceRoles.All(x => x.DeviceRoleID != defaultRole.DeviceRoleID))
                {
                    Log.InfoFormat("Apply default role id={0} for user", defaultRole.DeviceRoleID);
                    userDeviceRoles.Add(new UserDeviceRole()
                    {
                        UserID = systemUserInfo.UserID, DeviceRoleID = defaultRole.DeviceRoleID
                    });
                }
            }

            var addedRoleIds   = new List <int>();
            var deletedRoleIds = new List <int>();

            if (userDeviceRoles.Any())
            {
                var originalRoleIds = systemUserInfo.UserDeviceRoles.Select(d => d.DeviceRoleID);
                var currentRoleIds  = userDeviceRoles.Select(d => d.DeviceRoleID);
                deletedRoleIds = originalRoleIds.Except(currentRoleIds).ToList();

                addedRoleIds = currentRoleIds.Except(originalRoleIds).ToList();
            }
            else
            {
                deletedRoleIds = systemUserInfo.UserDeviceRoles.Select(d => d.UserDeviceRoleID).ToList();
            }

            deletedRoleIds.ForEach(d => _userDeviceRoleRepo.Delete(d));
            addedRoleIds.ForEach(d =>
            {
                var auth = userDeviceRoles.First(x => x.DeviceRoleID == d);
                _userDeviceRoleRepo.Insert(auth);
            });

            systemUserInfo.UserDeviceRoles = userDeviceRoles;
        }