public void Edit(ImitatorUser imitatorUser) { try { var existingUser = Context.ImitatorUsers.Include(x => x.ImitatorUserDevices).FirstOrDefault(x => x.GKNo == imitatorUser.GKNo); if (existingUser != null) { Context.ImitatorUserDevices.RemoveRange(existingUser.ImitatorUserDevices); existingUser.GKNo = imitatorUser.GKNo; existingUser.Number = imitatorUser.Number; existingUser.Name = imitatorUser.Name; existingUser.EndDateTime = imitatorUser.EndDateTime.CheckDate(); existingUser.TotalSeconds = imitatorUser.TotalSeconds; existingUser.CardType = imitatorUser.CardType; existingUser.Level = imitatorUser.Level; existingUser.ScheduleNo = imitatorUser.ScheduleNo; existingUser.IsBlocked = imitatorUser.IsBlocked; existingUser.ImitatorUserDevices = imitatorUser.ImitatorUserDevices; Context.SaveChanges(); } } catch { } }
public void Add(ImitatorUser imitatorUser) { try { imitatorUser.EndDateTime = imitatorUser.EndDateTime.CheckDate(); Context.ImitatorUsers.Add(imitatorUser); Context.SaveChanges(); } catch { } }
void AddAccessJournalItem(ImitatorUser user, bool isAccess, short gkDescriptorNo) { var journalItem = new ImitatorJournalItem(0, isAccess ? (byte)13 : (byte)15, 0, 0); journalItem.ObjectDeviceAddress = gkDescriptorNo; if (user != null) { journalItem.ObjectFactoryNo = user.GKNo; } AddJournalItem(journalItem); }
static ImitatorUser ImitatorUserFromBytes(List<byte> bytes) { var imitatorUser = new ImitatorUser(); imitatorUser.GKNo = BytesHelper.SubstructShort(bytes, 0); imitatorUser.CardType = (GKCardType)bytes[2]; imitatorUser.IsBlocked = bytes[3] == 1; imitatorUser.Name = BytesHelper.BytesToStringDescription(bytes, 4); imitatorUser.Number = BytesHelper.SubstructInt(bytes, 36); imitatorUser.Level = bytes[40]; imitatorUser.ScheduleNo = bytes[41]; imitatorUser.TotalSeconds = BytesHelper.SubstructInt(bytes, 44); imitatorUser.EndDateTime = new DateTime(2000, 1, 1).Add(new TimeSpan(0, 0, (int)(imitatorUser.TotalSeconds))); var descriptorNos = new List<int>(); for (int i = 0; i <= 68; i++) { var descriptorNo = BytesHelper.SubstructShort(bytes, 48 + i * 2); descriptorNos.Add(descriptorNo); } var sheduleNos = new List<int>(); for (int i = 0; i <= 68; i++) { var sheduleNo = bytes[184 + i]; sheduleNos.Add(sheduleNo); } for (int i = 0; i <= 68; i++) { var descriptorNo = descriptorNos[i]; var sheduleNo = sheduleNos[i]; if (descriptorNo == 0) break; var imitatorUserDevice = new ImitatorUserDevice() { DescriptorNo = descriptorNo, ScheduleNo = sheduleNo }; imitatorUser.ImitatorUserDevices.Add(imitatorUserDevice); } return imitatorUser; }