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 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")); }
public async Task UpdateStock_CallbackTest() { var product = new Product() { Id = Guid.NewGuid(), Name = "test3", Price = 15, Stock = 164, AuditInformation = new AuditInformation() { CreatedBy = Guid.NewGuid(), CreatedDate = DateTime.UtcNow } }; await _testFixture.ProductRepository.SaveProduct(product); var request = new UpdateStockRequest(product.Id, product.AuditInformation.CreatedBy, -100); var simulatedResponse = CallbackResult <string> .SuccessResult("Stock updated"); var session = new TestableCallbackAwareSession(); session.When( matcher: (UpdateStockRequest message) => message == request, response: simulatedResponse); var result = await session.Request <CallbackResult <string> >(request) .ConfigureAwait(false); result.Payload.Should().Be(simulatedResponse.Payload); }
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 SaveProduct_CallbackTest() { var request = new SaveProductRequest("test2", 10, 12, Guid.NewGuid()); var simulatedResponse = CallbackResult <string> .SuccessResult("Product created"); var session = new TestableCallbackAwareSession(); session.When( matcher: (SaveProductRequest message) => message == request, response: simulatedResponse); var result = await session.Request <CallbackResult <string> >(request) .ConfigureAwait(false); result.Payload.Should().Be(simulatedResponse.Payload); }
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"))); } }