/// <summary> /// Prompts the user for input. /// Calls ValidateInput() to check for 4 digits. /// Then looks up Entries in PINS.txt /// </summary> /// <returns>Returns True for a Valid PIN that is found in PINS.txt</returns> private string[] CheckPIN() { string Input = _t.GetString(); if (IsValidInput(Input)) { { List <User> Employs; using (var context = new thistimeitwillworkforsure.DBContext()) { Employs = context.Users.ToList(); } List <User> tmpUsers = new List <User>(); foreach (var User in Employs) { tmpUsers.Add(JsonConvert.DeserializeObject <User>(User.JSON)); } bool matchingPIN = tmpUsers.Any(User => User.PIN == Input); try { User currentuser = tmpUsers.Single(x => x.PIN == Input); //from User in Employs.Single //where User.PIN == Input //select User; return(new string[2] { currentuser.Status, currentuser.FirstName }); } catch (Exception) { throw; } } } else { _t.Display("Invalid Input<br />"); } return(new string[2] { "error", "error" }); }
public void SaveAllLists(object[] lists) { SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; Initial Catalog = thistimeitwillworkforsure.DBContext; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"); con.Open(); string sql = @"TRUNCATE TABLE Users;"; SqlCommand cmd = new SqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); cmd.Dispose(); con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; Initial Catalog = thistimeitwillworkforsure.DBContext; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"); con.Open(); sql = @"TRUNCATE TABLE FireFighters;"; cmd = new SqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); cmd.Dispose(); con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; Initial Catalog = thistimeitwillworkforsure.DBContext; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"); con.Open(); sql = @"TRUNCATE TABLE Vehicles;"; cmd = new SqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); cmd.Dispose(); con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; Initial Catalog = thistimeitwillworkforsure.DBContext; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"); con.Open(); sql = @"TRUNCATE TABLE Deployments;"; cmd = new SqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); cmd.Dispose(); con = new SqlConnection(@"Data Source = (LocalDB)\MSSQLLocalDB; Initial Catalog = thistimeitwillworkforsure.DBContext; Integrated Security = True; Connect Timeout = 30; Encrypt = False; TrustServerCertificate = False; ApplicationIntent = ReadWrite; MultiSubnetFailover = False"); con.Open(); sql = @"TRUNCATE TABLE Resources;"; cmd = new SqlCommand(sql, con); cmd.ExecuteNonQuery(); con.Close(); cmd.Dispose(); using (var context = new thistimeitwillworkforsure.DBContext()) { foreach (var User in (List <User>)lists[Employees]) { User.JSON = JsonConvert.SerializeObject(User, Formatting.None); } foreach (var User in (List <User>)lists[Employees]) { context.Users.Add(User); } context.SaveChanges(); } using (var context = new thistimeitwillworkforsure.DBContext()) { foreach (var fireFighter in (List <FireFighter>)lists[Firefighters]) { fireFighter.JSON = JsonConvert.SerializeObject(fireFighter, Formatting.None); } foreach (var fireFighter in (List <FireFighter>)lists[Firefighters]) { context.FireFighters.Add(fireFighter); } context.SaveChanges(); } using (var context = new thistimeitwillworkforsure.DBContext()) { foreach (var vehicle in (List <Vehicle>)lists[Vehicles]) { vehicle.JSON = JsonConvert.SerializeObject(vehicle, Formatting.None); } foreach (var vehicle in (List <Vehicle>)lists[Vehicles]) { context.Vehicles.Add(vehicle); } context.SaveChanges(); } using (var context = new thistimeitwillworkforsure.DBContext()) { foreach (var deployment in (List <Deployment>)lists[Deployments]) { deployment.JSON = JsonConvert.SerializeObject(deployment, Formatting.None); } foreach (var deployment in (List <Deployment>)lists[Deployments]) { context.Deployments.Add(deployment); } context.SaveChanges(); } using (var context = new thistimeitwillworkforsure.DBContext()) { foreach (var resources in (List <Resource>)lists[Resources]) { resources.JSON = JsonConvert.SerializeObject(resources, Formatting.None); } foreach (var resources in (List <Resource>)lists[Resources]) { context.Resources.Add(resources); } context.SaveChanges(); Globals.textout = ""; //resets text } }
public object[] ReadAllLists() { if (Globals.sql == true) { List <Deployment> Deploys; using (var context = new thistimeitwillworkforsure.DBContext()) { Deploys = context.Deployments.ToList(); } List <Deployment> tmpDeploys = new List <Deployment>(); foreach (var Deployment in Deploys) { tmpDeploys.Add(JsonConvert.DeserializeObject <Deployment>(Deployment.JSON)); } List <Resource> Resources; using (var context = new thistimeitwillworkforsure.DBContext()) { Resources = context.Resources.ToList(); } List <object> tmpResources = new List <object>(); foreach (var Resource in Resources) { tmpResources.Add(ObjectCast <Resource>(Resource.JSON)); } Resources = ConvertList <Resource>(tmpResources); List <Vehicle> Vehicles; using (var context = new thistimeitwillworkforsure.DBContext()) { Vehicles = context.Vehicles.ToList(); } List <object> tmpVehicles = new List <object>(); foreach (var Vehicle in Vehicles) { tmpVehicles.Add(ObjectCast <Vehicle>(Vehicle.JSON)); } Vehicles = ConvertList <Vehicle>(tmpVehicles); List <User> Employs; using (var context = new thistimeitwillworkforsure.DBContext()) { Employs = context.Users.ToList(); } List <User> tmpUsers = new List <User>(); foreach (var User in Employs) { tmpUsers.Add(JsonConvert.DeserializeObject <User>(User.JSON)); } List <FireFighter> FireFighters; using (var context = new thistimeitwillworkforsure.DBContext()) { FireFighters = context.FireFighters.ToList(); } List <FireFighter> tmpFireFighters = new List <FireFighter>(); foreach (var FireFighter in FireFighters) { tmpFireFighters.Add(JsonConvert.DeserializeObject <FireFighter>(FireFighter.JSON)); } return(new object[] { tmpDeploys, tmpUsers, Vehicles, Resources, tmpFireFighters }); } }