public ResourceScopeEntity Create(AddResourceScopeViewModel vm)
        {
            ValidationUtils.ValidateViewModel(vm);

            if (!_resourceRepository.Exists(vm.ResourceId))
            {
                throw new EntityValidationException("No resources with the given ID exists!");
            }

            var scope = _scopeRepository.Get(vm.Name);

            if (null == scope)
            {
                scope = new ScopeEntity()
                {
                    Name        = vm.Name,
                    Description = vm.Description,
                    Active      = true
                };
                scope = _scopeRepository.Create(scope);
            }
            else
            {
                if (_resourceScopeRepository.ExistsOnResource(vm.ResourceId, scope.ScopeId))
                {
                    throw new EntityValidationException("This scope already exists on this resource!");
                }
            }

            var resourceScope = new ResourceScopeEntity()
            {
                ResourceId  = vm.ResourceId,
                ScopeEntity = scope
            };

            return(_resourceScopeRepository.Create(resourceScope));
        }
Пример #2
0
 public IActionResult Create([FromBody] ScopeVm scopeVm)
 {
     _scopeRepository.Create(scopeVm);
     return(Ok());
 }