public static OperationResult<bool> AddOrEditCard(GKControllerCardSchedule controllerCardSchedule, SKDCard card, string employeeName, int gkCardNo = 0, bool isNew = true, RubezhDAL.DataClasses.DbService dbService = null) { if (gkCardNo == 0) { if (dbService == null) { using (var skdDatabaseService = new RubezhDAL.DataClasses.DbService()) { gkCardNo = skdDatabaseService.GKCardTranslator.GetFreeGKNo(controllerCardSchedule.ControllerDevice.GetGKIpAddress(), card.Number, out isNew); } } else gkCardNo = dbService.GKCardTranslator.GetFreeGKNo(controllerCardSchedule.ControllerDevice.GetGKIpAddress(), card.Number, out isNew); } var user = new GKUser { GkNo = (ushort)gkCardNo, ExpirationDate = card.EndDate, Fio = employeeName, GkLevel = (byte)card.GKLevel, GkLevelSchedule = (byte)card.GKLevelSchedule, Password = card.Number, UserType = card.GKCardType }; var result = AddOrEditUser(user, controllerCardSchedule.ControllerDevice, isNew, controllerCardSchedule.CardSchedules); if (result.HasError) return result; using (var skdDatabaseService = new RubezhDAL.DataClasses.DbService()) { skdDatabaseService.GKCardTranslator.AddOrEdit(controllerCardSchedule.ControllerDevice.GetGKIpAddress(), gkCardNo, card.Number, employeeName); } return new OperationResult<bool>(true); }
public static List<GKControllerCardSchedule> GetGKControllerCardSchedules(SKDCard card, List<CardDoor> accessTemplateDoors) { var cardSchedules = new List<GKCardSchedule>(); var cardDoors = new List<CardDoor>(); cardDoors.AddRange(accessTemplateDoors); cardDoors.AddRange(card.CardDoors.ToList()); foreach (var cardDoor in cardDoors) { var door = GKManager.Doors.FirstOrDefault(x => x.UID == cardDoor.DoorUID); if (door != null) { if (door.EnterDevice != null) { var enterCardSchedule = cardSchedules.FirstOrDefault(x => x.Device.UID == door.EnterDevice.UID); if (enterCardSchedule == null) { enterCardSchedule = new GKCardSchedule(); cardSchedules.Add(enterCardSchedule); } enterCardSchedule.Device = door.EnterDevice; enterCardSchedule.ScheduleNo = cardDoor.EnterScheduleNo; } if (door.DoorType != GKDoorType.OneWay && door.ExitDevice != null) { var exitCardSchedule = cardSchedules.FirstOrDefault(x => x.Device.UID == door.ExitDevice.UID); if (exitCardSchedule == null) { exitCardSchedule = new GKCardSchedule(); cardSchedules.Add(exitCardSchedule); } exitCardSchedule.Device = door.ExitDevice; exitCardSchedule.ScheduleNo = cardDoor.ExitScheduleNo; } } } cardSchedules = cardSchedules.OrderBy(x => x.Device.GKDescriptorNo).ToList(); var controllerCardSchedules = new List<GKControllerCardSchedule>(); foreach (var cardSchedule in cardSchedules) { var gkParent = cardSchedule.Device.GKParent; if (gkParent != null) { var controllerCardSchedule = controllerCardSchedules.FirstOrDefault(x => x.ControllerDevice.UID == gkParent.UID); if (controllerCardSchedule == null) { controllerCardSchedule = new GKControllerCardSchedule(); controllerCardSchedule.ControllerDevice = gkParent; controllerCardSchedules.Add(controllerCardSchedule); } controllerCardSchedule.CardSchedules.Add(cardSchedule); } } foreach (var controllerUID in card.GKControllerUIDs) { var controllerDevice = GKManager.Devices.FirstOrDefault(x => x.UID == controllerUID); if (controllerDevice != null) { if (!controllerCardSchedules.Any(x => x.ControllerDevice.UID == controllerUID) && card.GKCardType != GKCardType.Employee) { var controllerCardSchedule = new GKControllerCardSchedule() { ControllerDevice = controllerDevice }; controllerCardSchedules.Add(controllerCardSchedule); } } } return controllerCardSchedules; }