コード例 #1
0
        public async Task Should_Be_Able_To_Create_A_Customer()
        {
            var userCreateDto = new UserCreateDto
            {
                Name         = "CustomerOne",
                Surname      = "Consumer",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "0760000000",
                UserName     = "******",
                Password     = "******"
            };

            await CustomerAccountAppService.RegisterAsync(userCreateDto);

            var userDto = await IdentityUserAppService.FindByUsernameAsync(userCreateDto.UserName);

            userDto.ShouldNotBeNull();

            userDto.Name.ShouldBe(userCreateDto.Name);
            userDto.Surname.ShouldBe(userCreateDto.Surname);
            userDto.Email.ShouldBe(userCreateDto.EmailAddress);
            userDto.PhoneNumber.ShouldBe(userCreateDto.PhoneNumber);

            var roles = (await IdentityUserAppService.GetRolesAsync(userDto.Id)).Items;

            roles.ShouldContain(role => role.Name == RolesConsts.Customer);

            var customerDto = await CustomerAppService.GetCustomerByUserId(userDto.Id);

            customerDto.ShouldNotBeNull("CustomerEntity must not be null");
            customerDto.Status.ShouldBe(EntityStatusConsts.Active);
        }
コード例 #2
0
        public virtual async Task <IActionResult> OnGetAsync()
        {
            UserInfo = new UserInfoViewModel();

            var roleDtoList = (await IdentityUserAppService.GetAssignableRolesAsync()).Items;

            Roles = ObjectMapper.Map <IReadOnlyList <IdentityRoleDto>, AssignedRoleViewModel[]>(roleDtoList);

            foreach (var role in Roles)
            {
                role.IsAssigned = role.IsDefault;
            }

            var departmentDtoList = (await DepartmentAppService.GetListAsync(new GetDepartmentsInput {
                MaxResultCount = 1000,
                SkipCount = 0
            }));

            Departments = departmentDtoList.Items.Select(d => new SelectListItem {
                Text  = d.Name,
                Value = d.Code
            }).ToList();

            return(Page());
        }
コード例 #3
0
        public virtual async Task <IActionResult> OnPostAsync()
        {
            ValidateModel();

            var input = ObjectMapper.Map <UserInfoViewModel, IdentityUserUpdateDto>(UserInfo);

            input.RoleNames = Roles.Where(r => r.IsAssigned).Select(r => r.Name).ToArray();
            await IdentityUserAppService.UpdateAsync(UserInfo.Id, input);

            return(NoContent());
        }
コード例 #4
0
        public virtual async Task OnGetAsync(Guid id)
        {
            UserInfo = ObjectMapper.Map <IdentityUserDto, UserInfoViewModel>(await IdentityUserAppService.GetAsync(id));

            Roles = ObjectMapper.Map <IReadOnlyList <IdentityRoleDto>, AssignedRoleViewModel[]>((await IdentityRoleAppService.GetAllListAsync()).Items);

            var userRoleNames = (await IdentityUserAppService.GetRolesAsync(UserInfo.Id)).Items.Select(r => r.Name).ToList();

            foreach (var role in Roles)
            {
                if (userRoleNames.Contains(role.Name))
                {
                    role.IsAssigned = true;
                }
            }
        }
コード例 #5
0
        public async Task Should_Be_Able_To_Create_A_Rider()
        {
            var districtId    = "Colombo";
            var cityCreateDto = new CityCreateDto
            {
                CityName    = "Delkanda",
                DistrictID  = districtId,
                Geolocation = "6.784568:79.546545"
            };

            var cityDto = await CityAppService.CreateAsync(cityCreateDto);

            var userCreateDto = new UserCreateDto
            {
                Name         = "RiderOne",
                Surname      = "Rider",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "0760000000",
                UserName     = "******",
                Password     = "******"
            };

            await WithUnitOfWorkAsync(async() =>
            {
                //await RiderAccountAppService.RegisterAsync(userCreateDto, cityDto.Id);
            });

            var userDto = await IdentityUserAppService.FindByUsernameAsync(userCreateDto.UserName);

            userDto.ShouldNotBeNull();

            userDto.Name.ShouldBe(userCreateDto.Name);
            userDto.Surname.ShouldBe(userCreateDto.Surname);
            userDto.Email.ShouldBe(userCreateDto.EmailAddress);
            userDto.PhoneNumber.ShouldBe(userCreateDto.PhoneNumber);

            var roles = (await IdentityUserAppService.GetRolesAsync(userDto.Id)).Items;

            roles.ShouldContain(role => role.Name == RolesConsts.Rider);

            // var riderDto = await RiderAppService.GetRiderByUserId(userDto.Id);

            //riderDto.ShouldNotBeNull();
            //riderDto.Status.ShouldBe(EntityStatusConsts.Active);
            //riderDto.Geolocation.ShouldBe(cityCreateDto.Geolocation);
        }
コード例 #6
0
        public virtual async Task <IActionResult> OnGetAsync(Guid id)
        {
            UserInfo = ObjectMapper.Map <IdentityUserDto, UserInfoViewModel>(await IdentityUserAppService.GetAsync(id));

            Roles = ObjectMapper.Map <IReadOnlyList <IdentityRoleDto>, AssignedRoleViewModel[]>((await IdentityUserAppService.GetAssignableRolesAsync()).Items);

            var userRoleNames = (await IdentityUserAppService.GetRolesAsync(UserInfo.Id)).Items.Select(r => r.Name).ToList();

            foreach (var role in Roles)
            {
                if (userRoleNames.Contains(role.Name))
                {
                    role.IsAssigned = true;
                }
            }

            var departmentDtoList = (await DepartmentAppService.GetListAsync(new GetDepartmentsInput
            {
                MaxResultCount = 1000,
                SkipCount = 0
            }));

            Department = ObjectMapper.Map <UserDepartmentDto, AssignedDepartmentViewModel>(await UserDepartmentAppService.GetByUserNameAsync(UserInfo.UserName));

            Departments = departmentDtoList.Items.Select(d =>
            {
                if (Department != null && !Department.DepartmentCode.IsNullOrEmpty())
                {
                    return(new SelectListItem
                    {
                        Selected = true,
                        Text = d.Name,
                        Value = d.Code
                    });
                }

                return(new SelectListItem
                {
                    Text = d.Name,
                    Value = d.Code
                });
            }).ToList();

            return(Page());
        }
コード例 #7
0
        public virtual async Task <NoContentResult> OnPostAsync()
        {
            ValidateModel();

            var input = ObjectMapper.Map <UserInfoViewModel, IdentityUserCreateDto>(UserInfo);

            input.RoleNames = Roles.Where(r => r.IsAssigned).Select(r => r.Name).ToArray();

            await IdentityUserAppService.CreateAsync(input);

            var userDepartment = new UserDepartmentCreateDto
            {
                UserName       = input.UserName,
                DepartmentCode = Department.DepartmentCode
            };

            await UserDepartmentAppService.CreateAsync(userDepartment);

            return(NoContent());
        }
        public async Task Should_Be_Able_To_Create_A_Manager()
        {
            var userCreateDto = new UserCreateDto
            {
                Name         = "ManagerOne",
                Surname      = "Manager",
                EmailAddress = "*****@*****.**",
                PhoneNumber  = "0760000000",
                UserName     = "******",
                Password     = "******"
            };

            var districtId = "Colombo";

            await WithUnitOfWorkAsync(async() =>
            {
                await ManagerAccountAppService.RegisterAsync(userCreateDto, districtId);
            });

            var userDto = await IdentityUserAppService.FindByUsernameAsync(userCreateDto.UserName);

            userDto.ShouldNotBeNull();

            userDto.Name.ShouldBe(userCreateDto.Name);
            userDto.Surname.ShouldBe(userCreateDto.Surname);
            userDto.Email.ShouldBe(userCreateDto.EmailAddress);
            userDto.PhoneNumber.ShouldBe(userCreateDto.PhoneNumber);

            var roles = (await IdentityUserAppService.GetRolesAsync(userDto.Id)).Items;

            roles.ShouldContain(role => role.Name == RolesConsts.Manager);

            //  var managerDto = await ManagerAppService.GetManagerByUserId(userDto.Id);

            //managerDto.ShouldNotBeNull();
            //managerDto.Status.ShouldBe(EntityStatusConsts.Active);
            //managerDto.DistrictID.ShouldBe(districtId);
        }