예제 #1
0
        public async Task <User> Register(string username, string email, string password)
        {
            var user = new User
            {
                UserName    = username,
                Email       = email,
                DateCreated = DateTime.Now
            };
            var result = await _userManager.CreateAsync(user, password);

            if (!result.Succeeded)
            {
                return(null);
            }
            Console.WriteLine(result.Succeeded);
            var newUserRate = new UserRated
            {
                UserId = (await GetUserByUsername(username)).Id
            };
            await _context.UsersRated.AddAsync(newUserRate);

            var finalResult = await SaveChanges();

            return(finalResult ? user : null);
        }
예제 #2
0
        public static async Task SeedUserAsync(UserManager <User> userManager, StoreContext context)
        {
            if (!userManager.Users.Any())
            {
                var usersData = await File.ReadAllTextAsync("../Services/Seeds/Data/Users.json");

                var users = JsonSerializer.Deserialize <List <UserSeedDataDto> >(usersData);
                foreach (var userData in users)
                {
                    Console.WriteLine(userData.Username);
                    var user = new User
                    {
                        UserName       = userData.Username,
                        Email          = userData.Email,
                        EmailConfirmed = bool.Parse(userData.EmailConfirmed),
                        Description    = userData.Description,
                        PhoneNumber    = userData.PhoneNumber,
                        FirstName      = userData.FirstName,
                        LastName       = userData.LastName,
                        Gender         = userData.Gender,
                        Address        = userData.Address,
                        PictureUrl     = userData.PictureUrl,
                        FacebookUrl    = userData.FacebookUrl,
                        WhatsappUrl    = userData.WhatsappUrl,
                        TelegramUrl    = userData.TelegramUrl,
                        DateCreated    = DateTime.Now,
                    };
                    await userManager.CreateAsync(user, userData.Password);

                    var newUserRate = new UserRated
                    {
                        UserId = (await userManager.FindByNameAsync(userData.Username)).Id
                    };
                    await context.UsersRated.AddAsync(newUserRate);

                    await context.SaveChangesAsync();
                }
            }
        }