Exemple #1
0
        public async Task <RoleCategoryForListDto> Create(RoleCategoryForCreationAndUpdateDto roleCategoryForCreationAndUpdateDto)
        {
            var checkFromRepo = await roleCategoryDal.GetAsync(x => x.Name == roleCategoryForCreationAndUpdateDto.Name);

            if (checkFromRepo != null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { RoleCategoryListNotFound = Messages.AlreadyExist });
            }

            var roleCategoryCreated = mapper.Map <RoleCategory>(roleCategoryForCreationAndUpdateDto);
            await roleCategoryDal.Add(roleCategoryCreated);

            return(mapper.Map <RoleCategory, RoleCategoryForListDto>(roleCategoryCreated));
        }
Exemple #2
0
        public async Task <Role> CheckPublicRole(IRoleDal roleDal, IRoleCategoryDal roleCategoryDal)
        {
            var publicRole = await roleDal.GetAsync(x => x.Name.ToLower() == "public");

            if (publicRole == null)
            {
                var checkRoleCategory = await roleCategoryDal.GetAsync(x => x.Name.ToLower() == "public");

                if (checkRoleCategory == null)
                {
                    checkRoleCategory = new RoleCategory
                    {
                        Name        = "Users",
                        Description = "Kullanıcı ile ilgili yetkiler"
                    };

                    await roleCategoryDal.Add(checkRoleCategory);
                }

                var role = new Role
                {
                    Name           = "Public",
                    RoleCategoryId = checkRoleCategory.Id,
                    Description    = "Public Kullanıcı Yetkileri.."
                };

                await roleDal.Add(role);
            }

            return(await roleDal.GetAsync(x => x.Name.ToLower() == "public"));
        }