Exemple #1
0
        public async Task <StatusCodes> CreateItemAsync(ProcessTypeViewModel modelObject, string requestId = "")
        {
            _logger.LogInformation($"RequestId: {requestId} - Process_CreateItemAsync called.");

            Guard.Against.Null(modelObject, nameof(modelObject), requestId);
            Guard.Against.NullOrEmpty(modelObject.ProcessType, nameof(modelObject.ProcessType), requestId);
            try
            {
                var entityObject = MapToProcessEntity(modelObject, requestId);

                var result = await _processRepository.CreateItemAsync(entityObject, requestId);

                Guard.Against.NotStatus201Created(result, "Process_CreateItemAsync", requestId);
                //Granular Access Start
                try
                {
                    var channelName = modelObject.Channel.Replace(" ", "").ToString();

                    var permissionReadObj = new Permission()
                    {
                        Id   = string.Empty,
                        Name = $"{channelName}_Read"
                    };
                    var permissionReadWriteObj = new Permission()
                    {
                        Id   = string.Empty,
                        Name = $"{channelName}_ReadWrite"
                    };
                    var read = await _permissionRepository.CreateItemAsync(permissionReadObj, requestId);

                    var readWrite = await _permissionRepository.CreateItemAsync(permissionReadWriteObj, requestId);
                }
                catch (Exception ex)
                {
                    _logger.LogError($"RequestId: {requestId} - Process_CreateItemAsync Service Exception, error while creating permissions: {ex}");
                }
                //Granular Access End


                //Adding new role
                try
                {
                    var roleObj = new Role()
                    {
                        Id          = string.Empty,
                        DisplayName = modelObject.ProcessStep
                    };
                    var read = await _roleRepository.CreateItemAsync(roleObj, requestId);
                }
                catch (Exception ex)
                {
                    _logger.LogError($"RequestId: {requestId} - Process_CreateItemAsync Service Exception, error while creating permissions: {ex}");
                }
                //Adding new role

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogError($"RequestId: {requestId} - Process_CreateItemAsync Service Exception: {ex}");
                throw new ResponseException($"RequestId: {requestId} - Process_CreateItemAsync Service Exception: {ex}");
            }
        }