public async Task <ActionResult <CallbackResult <List <OrderCallbackResult> > > > GetOrders(
            [FromQuery] PaginationModel paginationModel)
        {
            try
            {
                var userId = HttpContext.User.Claims.First(t => t.Type == "UserId").Value;

                var sendOptions = new SendOptions();
                sendOptions.SetDestination(
                    ApplicationConfiguration.Instance.GetValue <string>("OrderService:CallbacksReceiverEndpointName"));
                sendOptions.RequireImmediateDispatch();

                var tokenSource = new CancellationTokenSource();
                tokenSource.CancelAfter(TimeSpan.FromSeconds(5));

                var result = await _endpointInstance.Request <CallbackResult <List <OrderCallbackResult> > >(
                    new OrderViewRequest(Guid.Parse(userId), paginationModel.PageSize, paginationModel.PageNumber),
                    sendOptions, tokenSource.Token).ConfigureAwait(false);

                return(Ok(result));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "");
                return(Ok(CallbackResult <string> .ErrorResult("", "Bilinmeyen bir hata oluştu")));
            }
        }
        public async Task Handle(OrderViewRequest message, IMessageHandlerContext context)
        {
            try
            {
                var result = await OrderRepository.FilterBy(t => t.UserId == message.UserId.ToString(),
                                                            message.PageNumber, message.PageSize);

                var orderCallbackResults = result.ToList().Select(t => new OrderCallbackResult()
                {
                    DeliveryAddress = t.DeliveryAddress,
                    InvoiceAddress  = t.InvoiceAddress,
                    OrderDate       = t.OrderDate,
                    UserId          = t.UserId,
                    UserName        = t.UserName,
                    Products        = t.Products.Select(a => new ProductInformationsInOrder()
                    {
                        Count = a.Count,
                        Name  = a.Name,
                        Price = a.Price
                    }).ToList()
                }).ToList();

                await context.Reply(CallbackResult <List <OrderCallbackResult> > .SuccessResult(orderCallbackResults));
            }
            catch (Exception e)
            {
                Logger.LogError(e, "");
                await context.Reply(CallbackResult <List <OrderCallbackResult> > .ErrorResult(null,
                                                                                              "Bilinmeyen Bir Hatadan Dolayı Siparişlerinizi Görüntüleyemiyoruz"));
            }
        }
        public async Task <ActionResult <CallbackResult <string> > > SaveProduct(
            SaveProductRequestModel saveProductRequestModel)
        {
            try
            {
                var userId = HttpContext.User.Claims.First(t => t.Type == "UserId").Value;

                var sendOptions = new SendOptions();
                sendOptions.SetDestination(
                    ApplicationConfiguration.Instance.GetValue <string>("ProductService:CallbacksReceiverEndpointName"));
                sendOptions.RequireImmediateDispatch();

                var tokenSource = new CancellationTokenSource();
                tokenSource.CancelAfter(TimeSpan.FromSeconds(5));

                var result = await _endpointInstance.Request <CallbackResult <string> >(
                    new SaveProductRequest(saveProductRequestModel.Name, saveProductRequestModel.Stock,
                                           saveProductRequestModel.Price, Guid.Parse(userId)), sendOptions, tokenSource.Token)
                             .ConfigureAwait(false);

                return(Ok(result));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "");
                return(Ok(CallbackResult <string> .ErrorResult("", "Bilinmeyen bir hata oluştu")));
            }
        }
Esempio n. 4
0
        public async Task Handle(SaveProductRequest message, IMessageHandlerContext context)
        {
            var result = await ProductRepository.SaveProduct(new Product
            {
                Id               = Guid.NewGuid(),
                Name             = message.ProductName,
                Price            = message.Price,
                Stock            = message.Stock,
                AuditInformation = new AuditInformation
                {
                    CreatedBy = message.CreatedUserId, CreatedDate = DateTime.UtcNow
                }
            });

            if (result == 1)
            {
                Logger.LogInformation(
                    $"Product Created by User:{message.CreatedUserId} , ProductName:{message.ProductName}  Stock:{message.Stock}  Price:{message.Stock}");
                await context.Reply(CallbackResult <string> .SuccessResult("Product created"));

                return;
            }

            await context.Reply(CallbackResult <string> .ErrorResult("Failed", " SaveProduct Failed"));
        }
Esempio n. 5
0
        public async Task Handle(UpdateStockRequest message, IMessageHandlerContext context)
        {
            var updateResult = await ProductRepository.UpdateStock(message.ProductId, message.Stock);

            if (updateResult == 1)
            {
                Logger.LogInformation(
                    $"User:{message.UpdatedById} updated stock that {message.Stock} this product:{message.ProductId}");

                await context.Reply(CallbackResult <string> .SuccessResult("Stock updated"));

                return;
            }

            await context.Reply(CallbackResult <string> .ErrorResult("Failed", " UpdateStock Failed"));
        }
        public async Task <ActionResult <CallbackResult <string> > > SaveOrder(
            [FromBody] SaveOrderRequestModel saveOrderRequestModel)
        {
            try
            {
                var userId   = HttpContext.User.Claims.First(t => t.Type == "UserId").Value;
                var userName = HttpContext.User.Claims.First(t => t.Type == "UserName").Value;

                var sendOptions = new SendOptions();
                sendOptions.SetDestination(
                    ApplicationConfiguration.Instance.GetValue <string>("ProductService:EndpointName"));
                sendOptions.RequireImmediateDispatch();

                var tokenSource = new CancellationTokenSource();
                tokenSource.CancelAfter(TimeSpan.FromSeconds(5));

                var products = saveOrderRequestModel.Products.Select(t => new ProductInformationsInOrder
                {
                    Id    = t.Id,
                    Count = t.Count,
                    Name  = t.Name,
                    Price = t.Price
                }).ToList();

                await _endpointInstance.Send(
                    new OrderControlCommand(Guid.Parse(userId), userName, saveOrderRequestModel.DeliveryAddress,
                                            saveOrderRequestModel.InvoiceAddress, products), sendOptions);

                return(Ok(CallbackResult <string> .SuccessResult("Sipariş Talebiniz Alınmıştır. Teşekkür ederiz.")));
            }
            catch (Exception e)
            {
                _logger.LogError(e, "");
                return(Ok(CallbackResult <string> .ErrorResult("", "Bilinmeyen bir hata oluştu")));
            }
        }