public void Initialize(Guid organisationId, Guid? id)
        {
            if (id.HasValue)
            {
                var filter = new AccessTemplateFilter {UIDs = new List<Guid> {id.Value}};
                AccessTemplate = AccessTemplateHelper.Get(filter).Single();
            }
            else
            {
                AccessTemplate = new AccessTemplate()
                {
                    Name = "Новый шаблон доступа",
                    OrganisationUID = organisationId
                };
            }

            var organisation = OrganisationHelper.Get(new OrganisationFilter { UIDs = new List<Guid> { organisationId } }).FirstOrDefault();

            Doors = GKManager.DeviceConfiguration.Doors.Where(door => organisation.DoorUIDs.Any(y => y == door.UID))
                .Select(door => new AccessDoorModel(door, AccessTemplate.CardDoors, GKScheduleHelper.GetSchedules()))
                .ToList();
        }
Example #2
0
		private void AddRow(EmployeeAccessDataSet ds, EmployeeInfo employee, SKDCard card, CardDoor door, AccessTemplate template, Dictionary<Guid, Tuple<Tuple<GKSKDZone, string>, Tuple<GKSKDZone, string>>> zoneMap, List<Guid> addedZones)
		{
			if (!zoneMap.ContainsKey(door.DoorUID))
				return;
			var zones = zoneMap[door.DoorUID];
			var dataRow = ds.Data.NewDataRow();
			dataRow.Type = card.GKCardType.ToDescription();
			dataRow.Number = card.Number.ToString();
			if (employee != null)
			{
				dataRow.Employee = employee.Name;
				dataRow.Organisation = employee.Organisation;
				dataRow.Department = employee.Department;
				dataRow.Position = employee.Position;
			}
			if (template != null)
				dataRow.Template = template.Name;
			if (zones.Item1 != null && !addedZones.Contains(zones.Item1.Item1.UID))
			{
				var row1 = ds.Data.NewDataRow();
				row1.ItemArray = dataRow.ItemArray;
				row1.Zone = zones.Item1.Item2;
				row1.No = zones.Item1.Item1.No;
				ds.Data.AddDataRow(row1);
				addedZones.Add(zones.Item1.Item1.UID);
			}
			if (zones.Item2 != null && !addedZones.Contains(zones.Item2.Item1.UID))
			{
				var row2 = ds.Data.NewDataRow();
				row2.ItemArray = dataRow.ItemArray;
				row2.Zone = zones.Item2.Item2;
				row2.No = zones.Item2.Item1.No;
				ds.Data.AddDataRow(row2);
				addedZones.Add(zones.Item2.Item1.UID);
			}
		}
Example #3
0
		public static bool Restore(AccessTemplate accessTemplate)
		{
			var operationResult = ClientManager.RubezhService.RestoreAccessTemplate(accessTemplate);
			return Common.ThrowErrorIfExists(operationResult);
		}
Example #4
0
		public static bool MarkDeleted(AccessTemplate accessTemplate)
		{
			var result = ClientManager.RubezhService.MarkDeletedAccessTemplate(accessTemplate);
			return Common.ThrowErrorIfExists(result) != null;
			return true;
		}
Example #5
0
		public static bool Save(AccessTemplate accessTemplate, bool isNew)
		{
			var result = ClientManager.RubezhService.SaveAccessTemplate(accessTemplate, isNew);
			Common.ThrowErrorIfExists(result);
			return result.Result;
		}
Example #6
0
		public OperationResult<bool> RestoreAccessTemplate(Guid clientUID, AccessTemplate item)
		{
			return SafeOperationCall(clientUID, () => RubezhService.RestoreAccessTemplate(clientUID, item), "RestoreAccessTemplate");
		}
Example #7
0
		public OperationResult<List<string>> MarkDeletedAccessTemplate(Guid clientUID, AccessTemplate item)
		{
			return SafeOperationCall(clientUID, () => RubezhService.MarkDeletedAccessTemplate(clientUID, item), "MarkDeletedAccessTemplate");
		}
Example #8
0
		public OperationResult<bool> SaveAccessTemplate(Guid clientUID, AccessTemplate item, bool isNew)
		{
			return SafeOperationCall(clientUID, () => RubezhService.SaveAccessTemplate(clientUID, item, isNew), "SaveAccessTemplate");
		}
Example #9
0
		public OperationResult<bool> RestoreAccessTemplate(AccessTemplate item)
		{
			return SafeOperationCall(() =>
			{
				var rubezhService = RubezhServiceFactory.Create(TimeSpan.FromMinutes(10));
				using (rubezhService as IDisposable)
					return rubezhService.RestoreAccessTemplate(RubezhServiceFactory.UID, item);
			}, "RestoreAccessTemplate");
		}
Example #10
0
		public OperationResult<List<string>> MarkDeletedAccessTemplate(AccessTemplate item)
		{
			return SafeOperationCall(() =>
			{
				var rubezhService = RubezhServiceFactory.Create(TimeSpan.FromMinutes(10));
				using (rubezhService as IDisposable)
					return rubezhService.MarkDeletedAccessTemplate(RubezhServiceFactory.UID, item);
			}, "MarkDeletedAccessTemplate");
		}
Example #11
0
		public OperationResult<bool> RestoreAccessTemplate(Guid clientUID, AccessTemplate accessTemplate)
		{
			AddJournalMessage(JournalEventNameType.Редактирование_шаблона_доступа, accessTemplate.Name, accessTemplate.UID, clientUID, JournalEventDescriptionType.Восстановление_шаблона_доступ, JournalObjectType.AccessTemplate);
			using (var databaseService = new RubezhDAL.DataClasses.DbService())
			{
				return databaseService.AccessTemplateTranslator.Restore(accessTemplate.UID);
			}
		}
Example #12
0
		public OperationResult<List<string>> MarkDeletedAccessTemplate(Guid clientUID, AccessTemplate accessTemplate)
		{
			var operationResult = new OperationResult<List<string>>();
			var warnings = new List<string>();
			AddJournalMessage(JournalEventNameType.Редактирование_шаблона_доступа, accessTemplate.Name, accessTemplate.UID, clientUID, JournalEventDescriptionType.Удаление_шаблона_доступ, JournalObjectType.AccessTemplate);
			using (var databaseService = new RubezhDAL.DataClasses.DbService())
			{
				var cardsResult = databaseService.CardTranslator.GetByAccessTemplateUID(accessTemplate.UID);
				if (!cardsResult.HasError && cardsResult.Result.IsNotNullOrEmpty())
				{
					var cards = cardsResult.Result;
					var removeFromCardsResult = databaseService.CardTranslator.RemoveAccessTemplate(cards.Select(x => x.UID).ToList());
					if (removeFromCardsResult.HasError)
						return OperationResult<List<string>>.FromError(removeFromCardsResult.Error);
					var cardsToUpdate = cards.Where(x => x.CardDoors.Count > 0).ToList();
					foreach (var card in cardsToUpdate)
					{
						warnings.AddRange(EditGKCard(clientUID, card, accessTemplate, card, null, databaseService));
					}
					var cardsToRemove = cards.Where(x => x.CardDoors.Count == 0).ToList();
					foreach (var card in cardsToRemove)
					{
						warnings.AddRange(DeleteGKCard(clientUID, card, accessTemplate.CardDoors, databaseService));
					}
				}
				var markDeletedResult = databaseService.AccessTemplateTranslator.MarkDeleted(accessTemplate.UID);
				if (markDeletedResult.HasError)
					operationResult = OperationResult<List<string>>.FromError(markDeletedResult.Error);
				operationResult = new OperationResult<List<string>>(warnings);
				return operationResult;
			}
		}
Example #13
0
		public OperationResult<bool> SaveAccessTemplate(Guid clientUID, AccessTemplate accessTemplate, bool isNew)
		{
			using (var databaseService = new RubezhDAL.DataClasses.DbService())
			{
				if (isNew)
					AddJournalMessage(JournalEventNameType.Редактирование_шаблона_доступа, accessTemplate.Name, accessTemplate.UID, clientUID, JournalEventDescriptionType.Добавление_шаблона_доступ, JournalObjectType.AccessTemplate);
				else
					AddJournalMessage(JournalEventNameType.Редактирование_шаблона_доступа, accessTemplate.Name, accessTemplate.UID, clientUID, JournalEventDescriptionType.Редактирование_шаблона_доступ, JournalObjectType.AccessTemplate);
				var oldGetAccessTemplateOperationResult = databaseService.AccessTemplateTranslator.GetSingle(accessTemplate.UID);
				var saveResult = databaseService.AccessTemplateTranslator.Save(accessTemplate);

				var errors = new List<string>();
				if (saveResult.HasError)
					errors.Add(saveResult.Error);

				var operationResult = databaseService.CardTranslator.GetByAccessTemplateUID(accessTemplate.UID);
				if (operationResult.Result != null)
				{
					foreach (var card in operationResult.Result)
					{
						errors.AddRange(EditGKCard(clientUID, card, oldGetAccessTemplateOperationResult.Result, card, accessTemplate, databaseService));
					}
				}

				return OperationResult<bool>.FromError(errors, !saveResult.HasError);
			}
		}
Example #14
0
		IEnumerable<string> EditGKCard(Guid clientUID, SKDCard oldCard, AccessTemplate oldAccessTemplate, SKDCard newCard, AccessTemplate newAccessTemplate, RubezhDAL.DataClasses.DbService databaseService)
		{
			var result = new List<string>();
			var employeeOperationResult = databaseService.EmployeeTranslator.GetSingle(newCard.EmployeeUID);
			if (!employeeOperationResult.HasError)
			{
				var cardDoors = oldAccessTemplate != null ? oldAccessTemplate.CardDoors : new List<CardDoor>();
				var oldControllerCardSchedules = GKSKDHelper.GetGKControllerCardSchedules(oldCard, cardDoors);
				cardDoors = newAccessTemplate != null ? newAccessTemplate.CardDoors : new List<CardDoor>();
				var newControllerCardSchedules = GKSKDHelper.GetGKControllerCardSchedules(newCard, cardDoors);
				foreach (var controllerCardSchedule in oldControllerCardSchedules)
				{
					if (!newControllerCardSchedules.Any(x => x.ControllerDevice.UID == controllerCardSchedule.ControllerDevice.UID))
					{
						var removeResult = GKSKDHelper.RemoveCard(controllerCardSchedule.ControllerDevice, newCard);
						if (removeResult.HasError)
						{
							result.Add("Не удалось удалить карту из устройства " + controllerCardSchedule.ControllerDevice.PresentationName);
							var pendingResult = databaseService.CardTranslator.DeletePending(newCard.UID, controllerCardSchedule.ControllerDevice.UID);
							if (pendingResult.HasError)
								result.Add(pendingResult.Error);
						}
					}
				}
				foreach (var controllerCardSchedule in newControllerCardSchedules)
				{
					var addResult = GKSKDHelper.AddOrEditCard(controllerCardSchedule, newCard, employeeOperationResult.Result.FIO);
					if (addResult.HasError)
					{
						result.Add("Не удалось добавить или редактировать карту в устройстве " + controllerCardSchedule.ControllerDevice.PresentationName);
						var pendingResult = databaseService.CardTranslator.AddPending(newCard.UID, controllerCardSchedule.ControllerDevice.UID);
						if (pendingResult.HasError)
							result.Add(pendingResult.Error);
					}
				}
			}
			return result;
		}
Example #15
0
		IEnumerable<string> AddGKCard(Guid clientUID, SKDCard card, AccessTemplate accessTemplate, RubezhDAL.DataClasses.DbService databaseService)
		{
			var employeeOperationResult = databaseService.EmployeeTranslator.GetSingle(card.EmployeeUID);
			if (!employeeOperationResult.HasError)
			{
				var accessTemplateCardDoors = accessTemplate != null ? accessTemplate.CardDoors : new List<CardDoor>();
				var controllerCardSchedules = GKSKDHelper.GetGKControllerCardSchedules(card, accessTemplateCardDoors);
				foreach (var controllerCardSchedule in controllerCardSchedules)
				{
					var addResult = GKSKDHelper.AddOrEditCard(controllerCardSchedule, card, employeeOperationResult.Result.FIO);
					if (addResult.HasError)
					{
						yield return "Не удалось добавить карту в устройство " + controllerCardSchedule.ControllerDevice.PresentationName;
						var pendingResult = databaseService.CardTranslator.AddPending(card.UID, controllerCardSchedule.ControllerDevice.UID);
						if (pendingResult.HasError)
							yield return pendingResult.Error;
					}
				}
			}
		}