My issue lies in this bit of code below. It functions as expected for null or whitespace issue but after porting my staff member login details over to an SQLite db, I'm now struggling to correctly test if the input is a mismatch to all other known member passes[passcodes]. This was obvs much simpler with passcode vars for each staff member in the code sheet with names in there etc, but rudimemtary and I've written in a way to add new staff to this db and it would be good to know how to correctly qualify they dont exist/ match with the input found in the Entry object entPassword.Text and stored in the variable pass in the "code behind".
Any direction would be great as I feel like I'm missing or have previously miss coded some obvious solution.
below is the code snippet where the code just effectively falls through the implemented foreach
check, making it tough to follow the breakpoint as it just waits ready for more input [which if is the correct passcode, it logs in absolutely fine ].
Maybe the entire approach is wrong, I dunno:/
here is a youtube screen recording of it too, so you can see the non-functioning issue if you wanted for extra clarity - EDIT: please MUTE the video if you watch it, its got horrible notification bell noises that are recorded badly :)
Code snippet below:
private async void BtnLogin_Clicked(object sender, EventArgs e)
{
string pass = entPassword.Text;
if (string.IsNullOrWhiteSpace(pass))
{
InputError($"Passcode: ?{pass} ? Shows nothing was entered: Entry DENIED!");
}
else
{
List<Member> members = await App.Db.GetMembersAsync();
IEnumerable<string> memberPasses = from m in members where m.Pass == pass select m.Pass;
//the trouble ahead...
foreach (string p in memberPasses)
{
if (pass != p)
{
InputError($"Passcode: {pass} was NOT a recognized code");
}
else
{
IEnumerable<Member> member = from m in members
where m.Pass == p
select m;
Member mem = (Member)member.FirstOrDefault();
mem.DateStamp = DateTime.Now.ToShortDateString();
mem.TimeStamp = DateTime.Now.ToShortTimeString();
memberDetails = new string($" {mem.Usr} @ {mem.TimeStamp} on {mem.DateStamp}");
await App.Db.UpdateMemberAsync(mem);
NextPage();
}
}
}
}
CodePudding user response:
To search a list of members to find out if any match a given property.
Here, "pass" compared to "member.Pass":
var matchingMembers = (from m in members where m.Pass == pass).ToList();
if (matchingMembers.Count > 0 )
{
foreach (var member in matchingMembers)
{
//...
}
} else
{
//..tell user no match for "pass"..
}