#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
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)
        {
            __builder.AddMarkupContent(0, "<!DOCTYPE html>\r\n\r\n");
            __builder.OpenElement(1, "html");
            __builder.AddMarkupContent(2, "\r\n");
            __builder.AddMarkupContent(3, "<head>\r\n    <title>Reading Data from a File</title>\r\n</head>\r\n");
            __builder.OpenElement(4, "body");
            __builder.AddMarkupContent(5, "\r\n    ");
            __builder.AddMarkupContent(6, "<p>Choose file to upload.</p>\r\n    ");
            __builder.OpenComponent<BlazorInputFile.InputFile>(7);
            __builder.AddAttribute(8, "OnChange", Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<Microsoft.AspNetCore.Components.EventCallback<BlazorInputFile.IFileListEntry[]>>(Microsoft.AspNetCore.Components.EventCallback.Factory.Create<BlazorInputFile.IFileListEntry[]>(this, 
#nullable restore
#line 20 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                         HandleFileSelected

#line default
#line hidden
#nullable disable
            )));
            __builder.CloseComponent();
            __builder.AddMarkupContent(9, "\r\n\r\n\r\n");
#nullable restore
#line 23 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
     if (file1 != null)
    {

#line default
#line hidden
#nullable disable
            __builder.AddContent(10, "        ");
            __builder.OpenElement(11, "p");
            __builder.AddMarkupContent(12, "\r\n            Name: ");
            __builder.AddContent(13, 
#nullable restore
#line 26 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                   file1.Name

#line default
#line hidden
#nullable disable
            );
            __builder.AddMarkupContent(14, "<br>\r\n            Size in bytes: ");
            __builder.AddContent(15, 
#nullable restore
#line 27 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                            file1.Size

#line default
#line hidden
#nullable disable
            );
            __builder.AddMarkupContent(16, "<br>\r\n            Last modified date: ");
            __builder.AddContent(17, 
#nullable restore
#line 28 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                                 file1.LastModified.ToShortDateString()

#line default
#line hidden
#nullable disable
            );
            __builder.AddMarkupContent(18, "\r\n        ");
            __builder.CloseElement();
            __builder.AddMarkupContent(19, "\r\n        ");
            __builder.OpenElement(20, "button");
            __builder.AddAttribute(21, "onclick", Microsoft.AspNetCore.Components.EventCallback.Factory.Create<Microsoft.AspNetCore.Components.Web.MouseEventArgs>(this, 
#nullable restore
#line 30 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                          CountLines

#line default
#line hidden
#nullable disable
            ));
            __builder.AddContent(22, "Load File");
            __builder.CloseElement();
            __builder.AddMarkupContent(23, "\r\n        ");
            __builder.OpenElement(24, "button");
            __builder.AddAttribute(25, "onclick", Microsoft.AspNetCore.Components.EventCallback.Factory.Create<Microsoft.AspNetCore.Components.Web.MouseEventArgs>(this, 
#nullable restore
#line 31 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                          SaveUser

#line default
#line hidden
#nullable disable
            ));
            __builder.AddContent(26, "ADD Users");
            __builder.CloseElement();
            __builder.AddMarkupContent(27, "\r\n");
#nullable restore
#line 32 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"

    }

#line default
#line hidden
#nullable disable
            __builder.AddMarkupContent(28, "\r\n    ");
            __builder.OpenElement(29, "table");
            __builder.AddAttribute(30, "class", "table");
            __builder.AddMarkupContent(31, "\r\n        ");
            __builder.AddMarkupContent(32, "<thead>\r\n            <tr>\r\n\r\n                <th>User Name</th>\r\n                <th>Email</th>\r\n            </tr>\r\n        </thead>\r\n        ");
            __builder.OpenElement(33, "tbody");
            __builder.AddMarkupContent(34, "\r\n");
#nullable restore
#line 44 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
             foreach (var user in ColUsers)
            {

#line default
#line hidden
#nullable disable
            __builder.AddContent(35, "                ");
            __builder.OpenElement(36, "tr");
            __builder.AddMarkupContent(37, "\r\n\r\n                    ");
            __builder.OpenElement(38, "td");
            __builder.AddContent(39, 
#nullable restore
#line 48 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                         user.UserName

#line default
#line hidden
#nullable disable
            );
            __builder.CloseElement();
            __builder.AddMarkupContent(40, "\r\n                    ");
            __builder.OpenElement(41, "td");
            __builder.AddContent(42, 
#nullable restore
#line 49 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
                         user.Email

#line default
#line hidden
#nullable disable
            );
            __builder.CloseElement();
            __builder.AddMarkupContent(43, "\r\n\r\n                ");
            __builder.CloseElement();
            __builder.AddMarkupContent(44, "\r\n");
#nullable restore
#line 52 "C:\Users\jayt7\Source\Repos\Senior-Project\SPWA\Pages\CsvUserLoader.razor"
            }

#line default
#line hidden
#nullable disable
            __builder.AddContent(45, "        ");
            __builder.CloseElement();
            __builder.AddMarkupContent(46, "\r\n    ");
            __builder.CloseElement();
            __builder.AddMarkupContent(47, "\r\n");
            __builder.CloseElement();
            __builder.AddMarkupContent(48, "\r\n");
            __builder.CloseElement();
        }
        #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
