Exemple #1
0
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request);

            var role = _mapper.Map <Role>(request);

            _context.Roles.Add(role);
            _context.SaveChanges();
        }
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request);
            var role = new Role
            {
                Name = request.Name
            };

            _context.Roles.Add(role);
            _context.SaveChanges();
        }
        public void Execute(CreateRoleDto request)
        {
            _validator.ValidateAndThrow(request);

            if ((request.RoleType == RoleType.Administrator || request.RoleType == RoleType.Moderator) && _actor.RoleType != RoleType.Administrator)
            {
                throw new NotAllowedException(UseCase.getUseCase(this.Id), _actor, $"Only administrator can create role with type {request.RoleType}.");
            }

            var role = _mapper.Map <Role>(request);

            _context.Roles.Add(role);

            _context.SaveChanges(_actor.Id);
        }
Exemple #4
0
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request);

            var role = new Role
            {
                Name      = request.Name,
                CreatedAt = DateTime.Now,
                IsActive  = true
            };

            _context.Roles.Add(role);

            _context.SaveChanges();
        }
Exemple #5
0
        public void Execute(RoleDto request)
        {
            _validator.ValidateAndThrow(request); //ValidationException
            var role = new Roles()
            {
                Id       = request.Id,
                RoleName = request.RoleName
            };

            foreach (var item in request.PerimissionIds)
            {
                var rolePermission = new RolePermissions()
                {
                    PermissionId = item,
                    RoleId       = request.Id
                };
                _context.Entry(rolePermission).State = EntityState.Added;
            }
            _context.Entry(role).State = EntityState.Added;

            _context.SaveChanges();
        }