Exemple #1
0
        private static void CreateAdminRole(AppDbContext context, RoleManager <HotelRole> _roleManager, UserManager <HotelUser> _userManager)
        {
            bool roleExists = _roleManager.RoleExistsAsync("Admin").Result;

            if (roleExists)
            {
                return;
            }

            var role = new HotelRole()
            {
                Name = "Admin"
            };

            _roleManager.CreateAsync(role).Wait();

            var user = new HotelUser()
            {
                UserName         = "******",
                Email            = "*****@*****.**",
                HotelId          = 1,
                EmailConfirmed   = true,
                ConfirmedByAdmin = true,
                Id = Guid.NewGuid().ToString(),
            };

            string adminPassword = "******";
            var    userResult    = _userManager.CreateAsync(user, adminPassword).Result;

            if (userResult.Succeeded)
            {
                _userManager.AddToRoleAsync(user, "Admin").Wait();
            }
        }
        public HotelRoleDataObject GetRoleByKey(Guid id)
        {
            HotelRole           hotelRole           = hotelRoleRepository.GetByKey(id);
            HotelRoleDataObject hotelRoleDataObject = AutoMapper.Mapper.Map <HotelRole, HotelRoleDataObject>(hotelRole);

            return(hotelRoleDataObject);
        }
        public HotelRoleDataObject GetRoleByName(string name)
        {
            HotelRole           hotelRole           = hotelRoleRepository.Find(Specification <HotelRole> .Eval(cr => cr.Name.Equals(name)));
            HotelRoleDataObject hotelRoleDataObject = AutoMapper.Mapper.Map <HotelRole, HotelRoleDataObject>(hotelRole);

            return(hotelRoleDataObject);
        }
        public HotelRoleDataObject GetUserRoleByUserName(string userName)
        {
            HotelUser hotelUser = hotelUserRepository.GetUserByName(userName);
            HotelRole hotelrole = hotelRoleRepository.GetByKey(hotelUser.HotelRoleId);

            return(AutoMapper.Mapper.Map <HotelRole, HotelRoleDataObject>(hotelrole));
        }
Exemple #5
0
        private static void CreateRole(string name, AppDbContext context, RoleManager <HotelRole> _roleManager)
        {
            if (_roleManager.RoleExistsAsync(name).Result)
            {
                return;
            }
            var role = new HotelRole()
            {
                Name = name
            };

            _roleManager.CreateAsync(role).Wait();
        }