예제 #1
0
 public OrganisationDoorViewModel(Organisation organisation, GKDoor door)
 {
     DoorUID = door.UID;
     PresentationName = door.PresentationName;
     No = door.No;
     IsChecked = organisation != null && organisation.DoorUIDs.Contains(door.UID);
 }
예제 #2
0
        public Organisation SetDoorChecked(Organisation organisation)
        {
            if (IsChecked)
            {
                if (!organisation.DoorUIDs.Contains(DoorUID))
                    organisation.DoorUIDs.Add(DoorUID);
                OrganisationHelper.AddDoor(organisation, DoorUID);
            }
            else
            {
                var linkedCards = GetLinkedCards(organisation.UID);

                var linkedAccessTemplates = GetLinkedAccessTemplates(organisation.UID);

                foreach (var card in linkedCards)
                {
                    card.CardDoors.RemoveAll(x => x.DoorUID == DoorUID);
                    CardHelper.Edit(card, organisation.Name);
                }

                foreach (var accessTemplate in linkedAccessTemplates)
                {
                    accessTemplate.CardDoors.RemoveAll(x => x.DoorUID == DoorUID);
                    AccessTemplateHelper.Save(accessTemplate, false);
                }

                if (organisation.DoorUIDs.Contains(DoorUID))
                {
                    organisation.DoorUIDs.Remove(DoorUID);
                }
                OrganisationHelper.RemoveDoor(organisation, DoorUID);
            }

            return organisation;
        }
예제 #3
0
		public void AddSameNameTest()
		{
			var organisation = new Organisation();
			var department = new ShortDepartment { Name = "Name", OrganisationUID = organisation.UID };
			var newDepartment = new ShortDepartment { Name = "Name", OrganisationUID = organisation.UID };
			var mock = new Mock<ISafeRubezhService>();
			mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns<OrganisationFilter>(filter =>
			{
				return new OperationResult<List<Organisation>>(new List<Organisation> { organisation });
			});
			mock.Setup(x => x.GetDepartmentList(It.IsAny<DepartmentFilter>())).Returns<DepartmentFilter>(filter =>
			{
				return new OperationResult<List<ShortDepartment>>(new List<ShortDepartment> { department });
			});
			mock.Setup(x => x.GetDepartmentDetails(It.IsAny<Guid>())).Returns<Guid>(uid =>
			{
				if (uid == department.UID)
					return new OperationResult<Department>(new Department { UID = department.UID, OrganisationUID = department.UID, Name = department.Name });
				return null;
			});
			mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns(() =>
			{
				return new OperationResult<List<ShortEmployee>>();
			});
			ClientManager.RubezhService = mock.Object;
			
		
			var departmentsViewModel = new DepartmentsViewModel();
			departmentsViewModel.Initialize(new DepartmentFilter());
			var detailsViewModel = new DepartmentDetailsViewModel();
			detailsViewModel.Initialize(organisation, newDepartment, departmentsViewModel);
			Assert.IsFalse(detailsViewModel.ValidateAndSave());
		}
		public ScheduleZoneDetailsViewModel(Schedule schedule, Organisation organisation)
		{
			Title = "Добавить новые зоны";
			ScheduleZone = new List<ScheduleZone>();

			Zones = new SortableObservableCollection<SelectationScheduleZoneViewModel>();
			var organisationResult = OrganisationHelper.GetSingle(organisation.UID);
			_doorUIDs = organisationResult != null ? organisationResult.DoorUIDs : new List<Guid>();

			var gkDoors = GKManager.Doors.Where(x => _doorUIDs.Any(y => y == x.UID));
			foreach (var door in gkDoors)
			{
				if (door.EnterZoneUID != Guid.Empty)
				{
					var enterZone = GKManager.SKDZones.FirstOrDefault(x => x.UID == door.EnterZoneUID);
					if (enterZone != null && !Zones.Any(x => x.ZoneUID == enterZone.UID))
						Zones.Add(new SelectationScheduleZoneViewModel(enterZone, schedule, door.UID));
				}

				if (door.ExitZoneUID != Guid.Empty)
				{
					var exitZone = GKManager.SKDZones.FirstOrDefault(x => x.UID == door.ExitZoneUID);
					if (exitZone != null && !Zones.Any(x => x.ZoneUID == exitZone.UID))
						Zones.Add(new SelectationScheduleZoneViewModel(exitZone, schedule, door.UID));
				}
			}

			Zones = new ObservableCollection<SelectationScheduleZoneViewModel>(Zones.OrderBy(x => x.No)); //TODO: 
			SelectedZone = Zones.FirstOrDefault();
		}
		public ReportFilterOrganisationViewModel(Organisation organisation)
		{
			Organisation = organisation;
			Name = organisation.Name;
			Description = organisation.Description;
			IsDeleted = organisation.IsDeleted;
		}
예제 #6
0
		public void AdditionalColumns()
		{
			var organisation1 = new Organisation();
			var organisation2 = new Organisation();
			var employee1 = new ShortEmployee { OrganisationUID = organisation1.UID };
			var employee2 = new ShortEmployee { OrganisationUID = organisation2.UID };
			var additionalColumnType1 = new AdditionalColumnType { OrganisationUID = organisation1.UID, IsInGrid = true, DataType = AdditionalColumnDataType.Text };
			var additionalColumnType2 = new AdditionalColumnType { OrganisationUID = organisation1.UID, IsInGrid = true, DataType = AdditionalColumnDataType.Text };
			var mock = new Mock<ISafeRubezhService>();
			mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns<OrganisationFilter>(filter =>
				{
					var result = new List<Organisation>();
					if (filter.UIDs.Count == 0)
					{
						result.Add(organisation1);
						result.Add(organisation2);
					}
					if (filter.UIDs.Any(x => x == organisation1.UID))
						result.Add(organisation1);
					if (filter.UIDs.Any(x => x == organisation2.UID))
						result.Add(organisation2);
					return new OperationResult<List<Organisation>>(result);
				});
			mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns<EmployeeFilter>(filter =>
				{
					var result = new List<ShortEmployee>();
					if(filter.OrganisationUIDs.Count == 0)
					{
						result.Add(employee1);
						result.Add(employee2);
					}
					if (filter.OrganisationUIDs.Any(x => x == organisation1.UID))
						result.Add(employee1);
					if (filter.OrganisationUIDs.Any(x => x == organisation2.UID))
						result.Add(employee2);
					return new OperationResult<List<ShortEmployee>>(result);
				});
			mock.Setup(x => x.GetAdditionalColumnTypes(It.IsAny<AdditionalColumnTypeFilter>())).Returns<AdditionalColumnTypeFilter>(filter =>
			{
				var result = new List<AdditionalColumnType>();
				if (filter.OrganisationUIDs.Count == 0)
				{
					result.Add(additionalColumnType1);
					result.Add(additionalColumnType2);
				}
				if (filter.OrganisationUIDs.Any(x => x == organisation1.UID))
					result.Add(additionalColumnType1);
				if (filter.OrganisationUIDs.Any(x => x == organisation2.UID))
					result.Add(additionalColumnType2);
				return new OperationResult<List<AdditionalColumnType>>(result);
			});
			ClientManager.RubezhService = mock.Object;

			var employeesViewModel = new EmployeesViewModel();
			employeesViewModel.Initialize(new EmployeeFilter());
			Assert.IsTrue(employeesViewModel.AdditionalColumnTypes.Count == 2);
			employeesViewModel.Initialize(new EmployeeFilter { OrganisationUIDs = new List<Guid> { organisation1.UID } });
			Assert.IsTrue(employeesViewModel.AdditionalColumnTypes.Count == 1);
		}
예제 #7
0
 public CardViewModel(Organisation organisation)
 {
     Organisation = organisation;
     IsOrganisation = true;
     Level = 0;
     IsLeaf = true;
     IsExpanded = false;
     UID = organisation.UID;
     Init();
 }
예제 #8
0
		public void DeleteChild()
		{
			var organisation = new Organisation();
			var department = new ShortDepartment { UID = Guid.NewGuid(), Name = "Name1", OrganisationUID = organisation.UID };
			var childDepartment = new ShortDepartment 
				{ 
					UID = Guid.NewGuid(),
					Name = "Name2", 
					OrganisationUID = organisation.UID, 
					ParentDepartmentUID = department.UID, 
					IsDeleted = true 
				};
			department.ChildDepartments.Add(new TinyDepartment { Name = childDepartment.Name, UID = childDepartment.UID });
			var mock = new Mock<ISafeRubezhService>();
			mock.Setup(x => x.GetOrganisations(It.IsAny<OrganisationFilter>())).Returns(() =>
			{
				return new OperationResult<List<Organisation>>(new List<Organisation> { organisation });
			});
			mock.Setup(x => x.GetDepartmentList(It.IsAny<DepartmentFilter>())).Returns(() =>
			{
				return new OperationResult<List<ShortDepartment>>(new List<ShortDepartment> { department, childDepartment });
			});
			mock.Setup(x => x.GetEmployeeList(It.IsAny<EmployeeFilter>())).Returns(() =>
			{
				return new OperationResult<List<ShortEmployee>>();
			});
			mock.Setup(x => x.RestoreDepartment(It.IsAny<ShortDepartment>())).Returns<ShortDepartment>(shortDeaprtment =>
			{
				if (shortDeaprtment.UID == department.UID)
					department.IsDeleted = false;
				if (shortDeaprtment.UID == childDepartment.UID)
					childDepartment.IsDeleted = false;
				return new OperationResult<bool>(true);
			});
			mock.Setup(x => x.GetParentEmployeeUIDs(It.IsAny<Guid>())).Returns<Guid>(uid =>
			{
				var result = new List<Guid>();
				if(uid == childDepartment.UID)
					result.Add(department.UID);
				return new OperationResult<List<Guid>>(result);
			});
			ClientManager.RubezhService = mock.Object;
			(ServiceFactory.MessageBoxService as MockMessageBoxService).ShowConfirmationResult = true;
			var departmentsViewModel = new DepartmentsViewModel();
			departmentsViewModel.Initialize(new DepartmentFilter());
			departmentsViewModel.SelectedItem = departmentsViewModel.Organisations.SelectMany(x  => x.GetAllChildren()).FirstOrDefault(x => x.UID == childDepartment.UID);
			if (departmentsViewModel.RestoreCommand.CanExecute(null))
				departmentsViewModel.RestoreCommand.ForceExecute();
			else
				Assert.IsTrue(false);
			departmentsViewModel.Initialize(new DepartmentFilter());
			var department2 = departmentsViewModel.Models.FirstOrDefault(x => x.UID == department.UID);
			var childDepartment2 = departmentsViewModel.Models.FirstOrDefault(x => x.UID == childDepartment.UID);
			Assert.IsFalse(department2.IsDeleted || childDepartment2.IsDeleted);
		}
예제 #9
0
		public OrganisationUserViewModel(Organisation organisation, User user)
		{
			Organisation = organisation;
			User = user;
			if (Organisation != null)
			{
				if (Organisation.UserUIDs == null)
					Organisation.UserUIDs = new List<Guid>();
			}
			_isChecked = Organisation != null && Organisation.UserUIDs != null && Organisation.UserUIDs.Contains(user.UID);
		}
예제 #10
0
        private void InitializeOrganisation(Organisation organisation)
        {
            UID = organisation.UID;
	        OrganisationUID = organisation.UID;
            Name = organisation.Name;
            FIO = organisation.Name;
            IsOrganisation = true;
            IsExpanded = true;
            IsDeleted = organisation.IsDeleted;
            RemovalDate = IsDeleted ? organisation.RemovalDate.ToString("d MMM yyyy") : "";
            Level = 0;
            IsLeaf = true;
        }
예제 #11
0
		public EmployeeCardViewModel(Organisation organisation, EmployeeCardsViewModel employeeCardsViewModel, SKDCard card)
		{
			RemoveCommand = new RelayCommand(OnRemove, CanEditDelete);
			EditCommand = new RelayCommand(OnEdit, CanEditDelete);
			PrintCommand = new RelayCommand(OnPrint, CanPrint);
			SelectCardCommand = new RelayCommand(OnSelectCard, CanSelectCard);

			Organisation = organisation;
			EmployeeCardsViewModel = employeeCardsViewModel;
			Card = card;

			SetCardDoors();
		}
		public EmployeeCardDetailsViewModel(Organisation organisation, ShortEmployee employee, SKDCard card = null)
		{
			_employee = employee;

			ChangeReaderCommand = new RelayCommand(OnChangeReader);
			ShowUSBCardReaderCommand = new RelayCommand(OnShowUSBCardReader);

			Organisation = OrganisationHelper.GetSingle(organisation.UID);
			if (card == null)
			{
				IsNewCard = true;
				Title = "Создание пропуска";
				card = new SKDCard()
				{
					EndDate = DateTime.Now.AddYears(1),
					GKCardType = GKCardType.Employee
				};
			}
			else
			{
				Title = string.Format("Свойства пропуска: {0}", card.Number);
			}
			Card = card;
			CopyProperties();
			InitializeGKSchedules();
			AccessDoorsSelectationViewModel = new AccessDoorsSelectationViewModel(Organisation, Card.CardDoors, GKSchedules);
			InitializeAccessTemplates();

			var cards = CardHelper.Get(new CardFilter() { DeactivationType = LogicalDeletationType.Deleted });

			StopListCards = new ObservableCollection<SKDCard>();
			foreach (var item in cards.Where(x => x.IsInStopList))
				StopListCards.Add(item);
			SelectedStopListCard = StopListCards.FirstOrDefault();

			CanChangeCardType = _employee.Type == PersonType.Employee && ClientManager.CheckPermission(RubezhAPI.Models.PermissionType.Oper_SKD_Employees_Edit_CardType);
			GKCardTypes = new ObservableCollection<GKCardType>(Enum.GetValues(typeof(GKCardType)).OfType<GKCardType>());
			SelectedGKCardType = Card.GKCardType;

			AvailableGKControllers = new ObservableCollection<GKControllerViewModel>();
			foreach (var device in GKManager.Devices.Where(x => x.DriverType == GKDriverType.GK))
			{
				var controllerViewModel = new GKControllerViewModel(device);
				controllerViewModel.IsChecked = IsNewCard || (card.GKControllerUIDs != null && card.GKControllerUIDs.Contains(device.UID));
				AvailableGKControllers.Add(controllerViewModel);
			}
		}
		public OrganisationSelectionViewModel(Organisation organisation)
		{
			Title = "Выбор организации";
			Organisations = new ObservableCollection<OrganisationViewModel>();
			var userOrganisations = OrganisationHelper.GetByCurrentUser();
			foreach (var userOrganisation in userOrganisations)
			{
				if (userOrganisation != null)
				{
					Organisations.Add(new OrganisationViewModel(userOrganisation));
				}
			}
			if (organisation != null)
				SelectedOrganisation = Organisations.FirstOrDefault(x => x.Organisation.UID == organisation.UID);
			if (SelectedOrganisation == null)
				SelectedOrganisation = Organisations.FirstOrDefault();
		}
예제 #14
0
        public Organisation SetUserChecked(Organisation organisation)
        {
            if (IsChecked)
            {
                if (!organisation.UserUIDs.Contains(User.UID))
                    organisation.UserUIDs.Add(User.UID);
            }
            else
            {
                if (organisation.UserUIDs.Contains(User.UID))
                    organisation.UserUIDs.Remove(User.UID);
            }

            OrganisationHelper.SaveUsers(organisation);

            return organisation;
        }
		public AccessDoorsSelectationViewModel(Organisation organisation, List<CardDoor> cardDoors, IEnumerable<GKSchedule> schedules)
		{
			Organisation = organisation;
			CardDoors = cardDoors;
			if (CardDoors == null)
				CardDoors = new List<CardDoor>();

			Doors = new ObservableCollection<AccessDoorViewModel>();
			foreach (var door in GKManager.DeviceConfiguration.Doors)
			{
				if (Organisation.DoorUIDs.Any(y => y == door.UID))
				{
					var accessDoorViewModel = new AccessDoorViewModel(door, CardDoors, x => { SelectedDoor = x; }, schedules);
					Doors.Add(accessDoorViewModel);
				}
			}
			SelectedDoor = Doors.FirstOrDefault(x => x.IsChecked);
		}
		public OrganisationDetailsViewModel(OrganisationsViewModel organisationsViewModel, Organisation organisation = null)
		{
			OrganisationsViewModel = organisationsViewModel;
			if (organisation == null)
			{
				IsNew = true;
				Title = "Создание новой организации";
				OrganisationDetails = new OrganisationDetails()
				{
					Name = "Организация",
				};
				OrganisationDetails.UserUIDs.Add(ClientManager.CurrentUser.UID);
			}
			else
			{
				Title = string.Format("Свойства организации: {0}", organisation.Name);
				OrganisationDetails = OrganisationHelper.GetDetails(organisation.UID);

			}
			CopyProperties();
			ChiefViewModel = new EmployeeSelectationViewModel(OrganisationDetails.ChiefUID, new EmployeeFilter { OrganisationUIDs = new List<Guid> { OrganisationDetails.UID } });
			HRChiefViewModel = new EmployeeSelectationViewModel(OrganisationDetails.HRChiefUID, new EmployeeFilter { OrganisationUIDs = new List<Guid> { OrganisationDetails.UID } });
		}
예제 #17
0
		void OnEditOrganisation(Organisation newOrganisation)
		{
			var organisation = RootItems.FirstOrDefault(x => x.Organisation != null && x.Organisation.UID == newOrganisation.UID);
			if (organisation != null)
			{
				organisation.Update(newOrganisation);
			}
			OnPropertyChanged(() => RootItems);
		}
예제 #18
0
		public OperationResult<bool> SaveOrganisationUsers(Guid clientUID, Organisation organisation)
		{
			return SafeOperationCall(clientUID, () => RubezhService.SaveOrganisationUsers(clientUID, organisation), "SaveOrganisationUsers");
		}
예제 #19
0
		public OperationResult<bool> RemoveOrganisationDoor(Guid clientUID, Organisation organisation, Guid doorUID)
		{
			return SafeOperationCall(clientUID, () => RubezhService.RemoveOrganisationDoor(clientUID, organisation, doorUID), "RemoveOrganisationDoor");
		}
예제 #20
0
 public static bool MarkDeleted(Organisation organisation)
 {
     return MarkDeleted(organisation.UID, organisation.Name);
 }
예제 #21
0
 public OrganisationUserViewModel(Organisation organisation, User user)
 {
     User = user;
     IsChecked = organisation != null && organisation.UserUIDs != null && organisation.UserUIDs.Contains(user.UID);
 }
예제 #22
0
        public JsonNetResult SetDoorsChecked(Organisation organisation, OrganisationDoorViewModel door)
        {
            organisation = door.SetDoorChecked(organisation);

            return new JsonNetResult { Data = organisation };
        }
예제 #23
0
		public OrganisationViewModel(Organisation organisation)
		{
			Organisation = organisation;
			IsDeleted = organisation.IsDeleted;
		}
예제 #24
0
        public JsonNetResult SetUsersChecked(Organisation organisation, OrganisationUserViewModel user)
        {
            organisation = user.SetUserChecked(organisation);

            return new JsonNetResult { Data = organisation };
        }
예제 #25
0
        public JsonNetResult GetOrganisationUsers(Organisation organisation)
        {
            var users = RubezhClient.ClientManager.SecurityConfiguration.Users.Select(u => new OrganisationUserViewModel(organisation, u));

            return new JsonNetResult { Data = new {Users = users } };
        }
예제 #26
0
		void OnOrganisationUsersChanged(Organisation newOrganisation)
		{
			if (newOrganisation.UserUIDs.Any(x => x == ClientManager.CurrentUser.UID))
			{
				if (!RootItems.Any(x => x.IsOrganisation && x.Organisation.UID == newOrganisation.UID))
				{
					var organisationViewModel = new CardViewModel(newOrganisation);
					var cardFilter = new CardFilter();
					cardFilter.EmployeeFilter = new EmployeeFilter { OrganisationUIDs = new System.Collections.Generic.List<Guid> { newOrganisation.UID } };
					var cards = CardHelper.Get(cardFilter);
					if (cards == null || cards.Count() == 0)
						return;
					RootItems.Add(organisationViewModel);
					foreach (var card in cards.Where(x => x.OrganisationUID == newOrganisation.UID))
					{
						organisationViewModel.AddChild(new CardViewModel(card));
					}
					OnPropertyChanged(() => RootItems);
					OnPropertyChanged(() => RootItemsArray);
				}
			}
			else
			{
				var organisationViewModel = RootItems.FirstOrDefault(x => x.IsOrganisation && x.Organisation.UID == newOrganisation.UID);
				if (organisationViewModel != null)
				{
					RootItems.Remove(organisationViewModel);
					OnPropertyChanged(() => RootItems);
					OnPropertyChanged(() => RootItemsArray);
				}
			}
		}
예제 #27
0
 public static bool Restore(Organisation organisation)
 {
     return Restore(organisation.UID, organisation.Name);
 }
예제 #28
0
		public OperationResult<bool> RemoveOrganisationDoor(Organisation item, Guid doorUID)
		{
			return SafeOperationCall(() =>
			{
				var rubezhService = RubezhServiceFactory.Create(TimeSpan.FromMinutes(10));
				using (rubezhService as IDisposable)
					return rubezhService.RemoveOrganisationDoor(RubezhServiceFactory.UID, item, doorUID);
			}, "RemoveOrganisationDoor");
		}
예제 #29
0
        public JsonNetResult GetOrganisationDoors(Organisation organisation)
        {
            var doors = GKManager.DeviceConfiguration.Doors.Select(u => new OrganisationDoorViewModel(organisation, u));

            return new JsonNetResult { Data = new {Doors = doors } };
        }
예제 #30
0
		public OperationResult<bool> SaveOrganisationUsers(Organisation item)
		{
			return SafeOperationCall(() =>
			{
				var rubezhService = RubezhServiceFactory.Create(TimeSpan.FromMinutes(10));
				using (rubezhService as IDisposable)
					return rubezhService.SaveOrganisationUsers(RubezhServiceFactory.UID, item);
			}, "SaveOrganisationUsers");
		}