Как добавить идентификатор localStorage в список? ⇐ C#
-
Anonymous
Как добавить идентификатор localStorage в список?
In my code, the List ids did not take the data.Id value, taken from @bind=@data.Id. The reason for that is unknown. Please, is there any suggestions, because I am new to data binding? The list was printed out by the last Console... line and one got only the ids I added in the begining:
ids.Add(123456); ids.Add(1234); ids.Add(123); Everything worked fine regarding the logic. However, I am trying to check if the current input id is in the ids list.
@code{ private DataModel data = new DataModel(); private List ids = new List(); private async void HandleLogin() { var currentId = await LocalStorage.GetItemAsync("id"); ids.Add(123456); ids.Add(1234); ids.Add(123); if(currentId!=0) { // var usersid = data.Id; // var user = users.Where(x => x.Id == data.Id).First(); // if (usersid == user.Id) // { Console.WriteLine("Already logged in!"); await Task.Delay(1500); // confirmation = true; NavManager.NavigateTo("/enviar"); // } } else { if (!ids.Contains(data.Id)) { var randomId = Guid.NewGuid().ToString(); var usersid = data.Id; ids.Add(usersid); users.Add(new DataModel { Id = data.Id, UserId = randomId, SMSCode = null, Token = null }); Console.WriteLine("New User Welcome!"); // Random rnd = new Random(); // int num = rnd.Next(); // var num = psw.Value; await LocalStorage.SetItemAsync("id", data.Id); await LocalStorage.SetItemAsync("userId", randomId); await AuthStateProvider.GetAuthenticationStateAsync(); NavManager.NavigateTo("/verificar"); } else if(ids.Contains(data.Id)) { var usersid = data.Id; var user = users.Where(x => x.Id == usersid).First(); await LocalStorage.SetItemAsync("id", usersid); await LocalStorage.SetItemAsync("userId", user.UserId); await AuthStateProvider.GetAuthenticationStateAsync(); Console.WriteLine("Logged In!"); NavManager.NavigateTo("/enviar"); } } Console.Write(string.Join(System.Environment.NewLine, ids)); } } Is there any solution?
Источник: https://stackoverflow.com/questions/780 ... -to-a-list
In my code, the List ids did not take the data.Id value, taken from @bind=@data.Id. The reason for that is unknown. Please, is there any suggestions, because I am new to data binding? The list was printed out by the last Console... line and one got only the ids I added in the begining:
ids.Add(123456); ids.Add(1234); ids.Add(123); Everything worked fine regarding the logic. However, I am trying to check if the current input id is in the ids list.
@code{ private DataModel data = new DataModel(); private List ids = new List(); private async void HandleLogin() { var currentId = await LocalStorage.GetItemAsync("id"); ids.Add(123456); ids.Add(1234); ids.Add(123); if(currentId!=0) { // var usersid = data.Id; // var user = users.Where(x => x.Id == data.Id).First(); // if (usersid == user.Id) // { Console.WriteLine("Already logged in!"); await Task.Delay(1500); // confirmation = true; NavManager.NavigateTo("/enviar"); // } } else { if (!ids.Contains(data.Id)) { var randomId = Guid.NewGuid().ToString(); var usersid = data.Id; ids.Add(usersid); users.Add(new DataModel { Id = data.Id, UserId = randomId, SMSCode = null, Token = null }); Console.WriteLine("New User Welcome!"); // Random rnd = new Random(); // int num = rnd.Next(); // var num = psw.Value; await LocalStorage.SetItemAsync("id", data.Id); await LocalStorage.SetItemAsync("userId", randomId); await AuthStateProvider.GetAuthenticationStateAsync(); NavManager.NavigateTo("/verificar"); } else if(ids.Contains(data.Id)) { var usersid = data.Id; var user = users.Where(x => x.Id == usersid).First(); await LocalStorage.SetItemAsync("id", usersid); await LocalStorage.SetItemAsync("userId", user.UserId); await AuthStateProvider.GetAuthenticationStateAsync(); Console.WriteLine("Logged In!"); NavManager.NavigateTo("/enviar"); } } Console.Write(string.Join(System.Environment.NewLine, ids)); } } Is there any solution?
Источник: https://stackoverflow.com/questions/780 ... -to-a-list
Мобильная версия