Пример #1
0
        public JsonNetResult EmployeeCardDetails(EmployeeCardModel cardModel, string employeeName, bool isNew)
		{
			cardModel.Save();

			bool operationResult;

			if (isNew)
			{
				operationResult = CardHelper.Add(cardModel.Card, employeeName);
			}
			else
			{
				operationResult = CardHelper.Edit(cardModel.Card, employeeName);
			}

			return new JsonNetResult { Data = operationResult };
		}
Пример #2
0
        public JsonNetResult GetEmployeeCardDetails(Guid? organisationId, Guid? cardId)
		{
			if (!organisationId.HasValue)
			{
				return new JsonNetResult { Data = new EmployeeCardModel
					{
						Card = new SKDCard(),
						//SelectedStopListCard = new SKDCard(),
						//SelectedSchedule = new GKSchedule(),
						//SelectedAccessTemplate = new AccessTemplate(),
					} 
				};
			}

			SKDCard card;
			if (cardId.HasValue)
			{
				card = CardHelper.GetSingle(cardId.Value);
			}
			else
			{
				card = new SKDCard
				{
					EndDate = DateTime.Now.AddYears(1),
					GKCardType = GKCardType.Employee,
				};
			}

			var cardModel = new EmployeeCardModel();

			cardModel.Card = card;

			cardModel.Schedules = GKScheduleHelper.GetSchedules();
	        cardModel.SelectedSchedule = cardModel.Schedules.FirstOrDefault(s => s.No == cardModel.Card.GKLevelSchedule);

			var operationResult = CardHelper.Get(new CardFilter { DeactivationType = LogicalDeletationType.Deleted });
			cardModel.StopListCards = operationResult.Where(x => x.IsInStopList).ToList();

			cardModel.AvailableGKControllers = GKManager.Devices.Where(x => x.DriverType == GKDriverType.GK)
																.Select(d =>
																{
																	var isChecked = !cardId.HasValue;
																	isChecked |= card.GKControllerUIDs != null && card.GKControllerUIDs.Contains(d.UID);
																	return new GKControllerModel(d.UID, isChecked, d.PresentationName);
																}).ToList();

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

			cardModel.Doors = GKManager.DeviceConfiguration.Doors.Where(door => organisation.DoorUIDs.Any(y => y == door.UID))
				.Select(door => new AccessDoorModel(door, card.CardDoors, cardModel.Schedules))
				.ToList();

			var accessTemplateFilter = new AccessTemplateFilter { OrganisationUIDs = new List<Guid> { organisationId.Value } };
			cardModel.AvailableAccessTemplates = new List<AccessTemplate> { new AccessTemplate { UID = Guid.Empty, Name = "<нет>" } }
				.Concat(AccessTemplateHelper.Get(accessTemplateFilter))
				.ToList();
            var selectedAccessTemplate = cardModel.AvailableAccessTemplates.FirstOrDefault(x => x.UID == cardModel.Card.AccessTemplateUID);
            cardModel.SelectedAccessTemplate = selectedAccessTemplate;

            return new JsonNetResult { Data = cardModel };
		}