#pragma checksum "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "891e108a84d4b56ddf82973d55c35cd0e6a02690"
// <auto-generated/>
#pragma warning disable 1591
#pragma warning disable 0414
#pragma warning disable 0649
#pragma warning disable 0169

namespace SPWA.Pages
{
    #line hidden
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Microsoft.AspNetCore.Components;
#nullable restore
#line 3 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Authorization;

#line default
#line hidden
#nullable disable
#nullable restore
#line 4 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Authorization;

#line default
#line hidden
#nullable disable
#nullable restore
#line 5 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Forms;

#line default
#line hidden
#nullable disable
#nullable restore
#line 6 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Routing;

#line default
#line hidden
#nullable disable
#nullable restore
#line 7 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.Components.Web;

#line default
#line hidden
#nullable disable
#nullable restore
#line 8 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.JSInterop;

#line default
#line hidden
#nullable disable
#nullable restore
#line 9 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using SPWA;

#line default
#line hidden
#nullable disable
#nullable restore
#line 10 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using SPWA.Shared;

#line default
#line hidden
#nullable disable
#nullable restore
#line 11 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using MatBlazor;

#line default
#line hidden
#nullable disable
#nullable restore
#line 12 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using BlazorInputFile;

#line default
#line hidden
#nullable disable
#nullable restore
#line 14 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using Microsoft.AspNetCore.DataProtection;

#line default
#line hidden
#nullable disable
#nullable restore
#line 15 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\_Imports.razor"
using SPWA.LoginFeatures.Account.Pages.GoogleLogin;

#line default
#line hidden
#nullable disable
#nullable restore
#line 2 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
using System.IO;

#line default
#line hidden
#nullable disable
#nullable restore
#line 6 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
using System.Net.Http;

#line default
#line hidden
#nullable disable
#nullable restore
#line 9 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
using Microsoft.AspNetCore.Identity;

#line default
#line hidden
#nullable disable
#nullable restore
#line 10 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
using SPWA.DataAccess.Data;

#line default
#line hidden
#nullable disable
    [Microsoft.AspNetCore.Components.RouteAttribute("/users")]
    [Microsoft.AspNetCore.Components.RouteAttribute("/uploadfile")]
    public partial class CsvUserLoader : Microsoft.AspNetCore.Components.ComponentBase
    {
        #pragma warning disable 1998
        protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
        {
        }
        #pragma warning restore 1998
#nullable restore
#line 57 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
      

    string status;
    IFileListEntry file1;
    string st;
    List<ApplicationUser> ColUsers = new List<ApplicationUser>();
    // Property used to add or edit the currently selected user
    ApplicationUser objUser = new ApplicationUser();
    // To hold any possible errors
    string strError = "";

    void HandleFileSelected(IFileListEntry[] files)
    {
        file1 = files.FirstOrDefault();
        
    }

    async Task CountLines()
    {
        st = "";
        ColUsers = new List<ApplicationUser>();

        using (var reader = new System.IO.StreamReader(file1.Data))
        {

            st = await reader.ReadToEndAsync();
            foreach (string dataLine in st.Split('\n'))
            {
            
                string[] values = dataLine.Split(',');
                //System.Diagnostics.Debug.WriteLine("value 0 = " + values[0]);
                //System.Diagnostics.Debug.WriteLine("value 1 = " + values[1]);
               // System.Diagnostics.Debug.WriteLine("value ");
                var NewUser = new ApplicationUser{
                              UserName = values[0],
                              Email = values[1]
                                               };
           
                ColUsers.Add(NewUser);

            }
        }
    }

    async Task SaveUser()
    {
        try
        {
            // Is this an existing user?
           
            foreach (var user in ColUsers)
            {
                System.Diagnostics.Debug.WriteLine("user name: " + user.Email);
                //System.Diagnostics.Debug.WriteLine(" firtNewUser name: " + NewUser.Id);
                // Insert new user
                var NewUser =
                    new ApplicationUser
                    {
                        UserName = user.Email.Trim(),
                        Email = user.Email.Trim(),
                        PasswordHash = (user.Email.Substring(0,4).ToUpper() + "10.")
                    };
                System.Diagnostics.Debug.WriteLine("NewUser name: " + NewUser.Email);
                System.Diagnostics.Debug.WriteLine("NewUser ID: " + NewUser.Id);
                var CreateResult =
                    await _UserManager
                    .CreateAsync(NewUser);//, objUser.PasswordHash);
                 System.Diagnostics.Debug.WriteLine("NewUser Succeeded: " + CreateResult.Succeeded);
                if (!CreateResult.Succeeded)
                {
                    if (CreateResult
                        .Errors
                        .FirstOrDefault() != null)
                    {
                        strError =
                            CreateResult
                            .Errors
                            .FirstOrDefault()
                            .Description;
                    }
                    else
                    {
                        strError = "Create error";
                    }
                    // Keep the popup opened
                    
                }
                
            }
            
        
        }
        catch (Exception ex)
        {
            strError = ex.GetBaseException().Message;
        }
    }

#line default
#line hidden
#nullable disable
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private NavigationManager UriHelper { get; set; }
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private HttpClient Http { get; set; }
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private UserManager<ApplicationUser> _UserManager { get; set; }
        [global::Microsoft.AspNetCore.Components.InjectAttribute] private IJSRuntime JSrn { get; set; }
    }
}
#pragma warning restore 1591
