private static IQueryable <OrderViewModel> GetOrders() { var orderServiceFactory = new HttpOrderServiceChannelFactory(); IOrderService service = orderServiceFactory.CreateChannel(); var request2 = new ServiceRequestWithData <ISingleSignOnToken, OrderServiceGetAllOrdersParameters> { AuthenticationToken = new SingleSignOnToken(), CorrelationId = Guid.NewGuid(), Data = new OrderServiceGetAllOrdersParameters() }; // Act IServiceResponseWithResultData <IEnumerable <OrderEntity> > response = service.GetAllOrders(request2); IQueryable <OrderViewModel> orders = response.ResultData.Select(order => new OrderViewModel { CustomerID = order.CustomerId, OrderID = order.OrderId, EmployeeID = order.EmployeeId, OrderDate = order.OrderDate, ShipCountry = order.ShipCountry, ShipVia = order.ShipViaId, ShippedDate = order.ShippedDate, ShipName = order.ShipName, ShipAddress = order.ShipAddress, ShipCity = order.ShipCity, ShipPostalCode = order.ShipPostalCode }).AsQueryable(); return(orders); }
public ActionResult Orders_Create([DataSourceRequest] DataSourceRequest request, OrderViewModel order) { if (ModelState.IsValid) { order.OrderID = new Random(Guid.NewGuid().GetHashCode()).Next(); var orderServiceFactory = new HttpOrderServiceChannelFactory(); IOrderService service = orderServiceFactory.CreateChannel(); var request2 = new ServiceRequestWithData <ISingleSignOnToken, OrderEntity> { AuthenticationToken = new SingleSignOnToken(), CorrelationId = Guid.NewGuid(), Data = new OrderEntity { OrderId = order.OrderID, CustomerId = order.CustomerID, EmployeeId = order.EmployeeID, OrderDate = order.OrderDate, ShipCountry = order.ShipCountry, ShipViaId = order.ShipVia, ShippedDate = order.ShippedDate, ShipName = order.ShipName, ShipAddress = order.ShipAddress, ShipCity = order.ShipCity, ShipPostalCode = order.ShipPostalCode } }; // Act IServiceResponseWithResultData <OrderEntity> response2 = service.CreateOrder(request2); Guid correlationId = response2.CorrelationId; var request3 = new ServiceRequestWithData <ISingleSignOnToken, Guid> { AuthenticationToken = new SingleSignOnToken(), Data = correlationId }; IEnumerable <EventData> result; int loopCount = 0; // We're using an in-process bus so this isn't actually necassary, but it demonstrates how to wait for the command and event bus to complete their processes do { // Wait 0.5 of a second and ask again if (loopCount > 0) { System.Threading.Thread.Sleep(500); } IServiceResponseWithResultData <IEnumerable <EventData> > response3 = service.GetEventData(request3); result = response3.ResultData; result = result.Where(x => x.EventType == typeof(OrderCreated).AssemblyQualifiedName); } while (!result.Any() && loopCount++ < 10); } return(Json(new[] { order }.ToDataSourceResult(request, ModelState))); }