public void LogAuthorizationAttempt(int doorId, bool result, int id) { using (BuildingSecurityContext securityContext = new BuildingSecurityContext()) { securityContext.AccessHistories.Add(new AccessHistory { DoorID = doorId, AttemptDate = DateTime.Now, EmployeeId = id, Result = result }); securityContext.SaveChanges(); } }
public void AddSecurityDevice(string securityDevice) { using (BuildingSecurityContext SecurityContext = new BuildingSecurityContext()) { if (SecurityContext.SecurityDevices.All(x => x.SecurityDeviceType != securityDevice)) { SecurityContext.SecurityDevices.Add(new SecurityDevice { SecurityDeviceType = securityDevice }); SecurityContext.SaveChanges(); } else { Console.WriteLine("This device already is installed in our system"); } } }
public void RevokeAccess() { Console.WriteLine("Please select a door to remove a credential from this list"); using (BuildingSecurityContext securityContext = new BuildingSecurityContext()) { foreach (var item in securityContext.Doors) { Console.WriteLine(item.Room); } string door = Console.ReadLine(); if (securityContext.Doors.Any(x => x.Room == door)) { var doorId = GetDoorId(door); var doorCreds = securityContext.DoorSecurityDevices.Include("SecurityDevices").Where(x => x.DoorId == doorId); Console.WriteLine("Please select a credential to remove from this list"); foreach (var item in doorCreds) { Console.WriteLine(item.SecurityDevices.SecurityDeviceType + "\t" + item.SecurityDeviceId); } string credential = Console.ReadLine(); if (doorCreds.Any(x => x.SecurityDevices.SecurityDeviceType == credential)) { var deviceId = GetSecurityDeviceId(credential); if (doorCreds.Any(x => x.SecurityDeviceId > deviceId)) { Console.WriteLine("Please delete a the device with the highest deviceId 1st "); } else { var credToRemove = securityContext.DoorSecurityDevices.FirstOrDefault(x => x.SecurityDeviceId == deviceId && x.DoorId == doorId); securityContext.DoorSecurityDevices.Remove(credToRemove); securityContext.SaveChanges(); } } else { Console.WriteLine("Please select a credential to remove from the above list"); } } else { Console.WriteLine("Please select a door from the above list"); } } }
public void GrantAccess(string door, IQueryable <DoorSecurityDevice> credentials) { using (BuildingSecurityContext securityContext = new BuildingSecurityContext()) { Console.WriteLine("These are the credentials currently with this door"); Console.WriteLine("Credential type \t CredentialId"); foreach (var item in credentials) { Console.WriteLine(item.SecurityDevices.SecurityDeviceType + "\t" + item.SecurityDeviceId); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("Type which of these credentials would you like to add"); Console.WriteLine("Credential type \t CredentialId"); foreach (var item in securityContext.SecurityDevices) { Console.WriteLine(item.SecurityDeviceType + "\t" + item.SecurityDeviceId); Console.WriteLine(); } string credential = Console.ReadLine(); if (securityContext.SecurityDevices.Any(x => x.SecurityDeviceType == credential)) { var ID = GetSecurityDeviceId(credential); if (credentials.Any(x => x.SecurityDevices.SecurityDeviceType == credential)) { Console.WriteLine("The door already has this credential"); } else if (credentials.All(x => x.SecurityDeviceId != ID)) { var doorId = GetDoorId(door); securityContext.DoorSecurityDevices.Add(new DoorSecurityDevice { DoorId = doorId, SecurityDeviceId = ID }); securityContext.SaveChanges(); } } else { Console.WriteLine("No such credential exists"); } } }