Exemplo n.º 1
0
        public async Task <IActionResult> Post([FromBody] CreateProductDto dto)
        {
            var entity = dto.CreateEntity();

            _repository.Add(entity);

            await _repository.UnitOfWork.SaveChangesAsync();

            using (var client = new HttpClient())
            {
                var token = HttpContext.Request.Headers["Authorization"].ToString();

                if (!string.IsNullOrEmpty(token))
                {
                    var beareToken = token.Split("Bearer ")[1];

                    client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", beareToken);

                    var resp = await client.PostAsync("http://192.168.2.99:5002/api/notification/notify", ObjToHttpContent(entity));

                    resp.EnsureSuccessStatusCode();
                }
            }

            return(new OkObjectResult(entity));
        }