Exemplo n.º 1
0
        public async Task <IActionResult> SignUp(AppUserAddDto appUserAddDto, [FromServices] IAppRoleService appRoleService,
                                                 [FromServices] IAppUserRoleService appUserRoleService)
        {
            var appUser = await _appUserService.FindByUserNameAsync(appUserAddDto.UserName);

            if (appUser != null)
            {
                return(BadRequest($"{appUserAddDto.UserName} already exists"));
            }

            await _appUserService.InsertAsync(_mapper.Map <AppUser>(appUserAddDto));

            var createdUser = await _appUserService.FindByUserNameAsync(appUserAddDto.UserName);

            var userRole = await appRoleService.FindByName(RoleInfo.Member);

            await appUserRoleService.InsertAsync(new AppUserRole
            {
                AppRoleId = userRole.Id,
                AppUserId = createdUser.Id
            });


            return(Created("", appUserAddDto));
        }
        public async static Task Seed(IAppUserService appUserService, IAppUserRoleService appUserRoleService,
                                      IAppRoleService appRoleService)
        {
            var adminRole = await appRoleService.FindByName("Admin");

            var memberRole = await appRoleService.FindByName("Member");

            if (adminRole == null)
            {
                await appRoleService.InsertAsync(new AppRole
                {
                    Name = RoleInfo.Admin
                });
            }

            if (memberRole == null)
            {
                await appRoleService.InsertAsync(new AppRole
                {
                    Name = RoleInfo.Member
                });
            }

            var adminUser = await appUserService.FindByUserNameAsync("pcparticle");

            if (adminUser == null)
            {
                await appUserService.InsertAsync(new AppUser
                {
                    FullName = "Erol Aksoy",
                    Password = "******",
                    UserName = "******"
                });

                var admin = await appUserService.FindByUserNameAsync("pcparticle");

                var role = await appRoleService.FindByName("Admin");

                await appUserRoleService.InsertAsync(new AppUserRole
                {
                    AppRoleId = role.Id,
                    AppUserId = admin.Id
                });
            }
        }