Esempio n. 1
0
        public async Task <List <TDestination> > GetAsync <TSource, TDestination>(bool include = false) where TSource : class where TDestination : class
        {
            try
            {
                GetProperties <TSource>();
                string uri = FormatUriWithoutIds <TSource>();
                token = await _jwt.CheckTokenAsync(token);

                return(await _http.GetListAsync <TDestination>($"{uri}?include={include.ToString()}", "AdminClient", token.Token));
            }
            catch
            {
                throw;
            }
        }
Esempio n. 2
0
        public async Task <int> CreateAsync <TSource, TDestination>(TSource item)
            where TSource : class
            where TDestination : class
        {
            try
            {
                GetProperties(item);
                string uri = FormatUriWithIds <TDestination>();
                token = await _jwt.CheckTokenAsync(token);

                var response = await _http.PostAsync <TSource, TSource>(item,
                                                                        uri, "AdminClient", token.Token);

                return((int)response.GetType().GetProperty("Id").GetValue(response));
            }
            catch
            {
                throw;
            }
        }
Esempio n. 3
0
        public async Task <int> CreateAsync <TSource, TDestination>(TSource item)
            where TSource : class
            where TDestination : class
        {
            try
            {
                GetProperties(item);
                string uri = FormatUriWithIds <TDestination>();
                _token = await _jwtTokenService.CheckTokenAsync(_token);

                var response = await _http.PostAsync <TSource, TDestination>(item, uri, AppConstants.HttpClientName, _token.Token);

                return((int)response.GetType()
                       .GetProperty("Id")
                       .GetValue(response));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private async Task <GrpcChannel> CreateAuthenticatedChannel(string address)
        {
            _token = await _jwtTokenService.CheckTokenAsync(_token);

            var credentials = CallCredentials.FromInterceptor((context, metadata) =>
            {
                if (!string.IsNullOrEmpty(_token.Token))
                {
                    metadata.Add("Authorization", $"Bearer {_token.Token}");
                }
                return(Task.CompletedTask);
            });

            // SslCredentials is used here because this channel is using TLS.
            // CallCredentials can't be used with ChannelCredentials.Insecure on non-TLS channels.
            var channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions
            {
                Credentials = ChannelCredentials.Create(new SslCredentials(), credentials)
            });

            return(channel);
        }
        public async Task <int> CreateAsync(CourseDTO item)
        {
            _token = await _jwtTokenService.CheckTokenAsync(_token);

            var headers = new Metadata();

            headers.Add("Authorization", $"Bearer {_token.Token}");

            var course = _mapper.Map <CourseMessage>(item);//new CourseMessage { Title = "BestTitle" }

            var reply = await _coursesClient.CreateCourseAsync(course, headers);

            return(reply.Id);
        }