コード例 #1
0
        public async Task <IActionResult> Post([FromBody] RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new TransferUser
                {
                    UserName    = model.userName,
                    Name        = model.firstName + ' ' + model.lastName,
                    PhoneNumber = model.phoneNumber,
                    Email       = model.email,
                    Country     = model.country
                };
                var result = await userManager.CreateAsync(user, model.password);

                if (result.Succeeded)
                {
                    await signInManager.SignInAsync(user, false);

                    return(Ok(user));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error.Description);
                    }
                }
            }
            return(BadRequest());
        }
コード例 #2
0
 public User Map(TransferUser transferUser)
 {
     if (transferUser == null)
     {
         return(null);
     }
     return(new User
     {
         UserId = transferUser.UserId,
         Login = transferUser.Login,
         PrompterStatus = transferUser.PrompterStatus,
         Password = transferUser.Password,
         Disabled = transferUser.Disabled,
         RoleId = transferUser.RoleId,
         EntityState = transferUser.EntityState,
         //Role = _roleMapper.Map(transferUser.Role)
     });
 }
コード例 #3
0
 public User Map(TransferUser transferUser)
 {
     if (transferUser == null)
     {
         return null;
     }
     return new User
     {
         UserId = transferUser.UserId,
         Login = transferUser.Login,
         PrompterStatus = transferUser.PrompterStatus,
         Password = transferUser.Password,
         Disabled = transferUser.Disabled,
         RoleId = transferUser.RoleId,
         EntityState = transferUser.EntityState,
         //Role = _roleMapper.Map(transferUser.Role)
     };
 }
コード例 #4
0
ファイル: TransferSeeder.cs プロジェクト: m4rk4n/Transfer
        public async Task Seed()
        {
            ctx.Database.EnsureCreated();


            if (ctx.Vehicles.Count() == 0)
            {
                ctx.Vehicles.Add(
                    new Vehicle
                {
                    Name             = "Auto1",
                    Note             = "poyy",
                    RegistrationDate = DateTime.Now,
                    PlateNumber      = "12321"
                });
            }

            ctx.SaveChanges();
            if (ctx.Partners.Count() == 0)
            {
                ctx.Partners.Add(
                    new Partner
                {
                    Name      = "Partner Prvi",
                    Phone     = "3456787",
                    Email     = "*****@*****.**",
                    VehicleId = 1
                });
            }


            ctx.SaveChanges();

            bool x = await roleManager.RoleExistsAsync("Admin");

            if (!x)
            {
                var role = new IdentityRole();
                role.Name = "Admin";
                await roleManager.CreateAsync(role);
            }

            ctx.SaveChanges();

            var user = await userManager.FindByEmailAsync("*****@*****.**");

            if (user == null)
            {
                user = new TransferUser()
                {
                    Name     = "Admin",
                    UserName = "******",
                    Email    = "*****@*****.**"
                };
                var result = await userManager.CreateAsync(user, "P@ssw0rd!");

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed To create default admin user");
                }
                else if (result.Succeeded)
                {
                    var result1 = await userManager.AddToRoleAsync(user, "Admin");
                }
            }

            // user2 has no roles
            var user2 = await userManager.FindByEmailAsync("*****@*****.**");

            if (user2 == null)
            {
                user2 = new TransferUser()
                {
                    Name     = "Test2",
                    UserName = "******",
                    Email    = "*****@*****.**"
                };
                var result = await userManager.CreateAsync(user2, "P@ssw0rd!");

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Failed to create test user");
                }
            }

            ctx.SaveChanges();
        }