public string CreateJson(string orderID, string sellerId) { var date1 = new DateTime(); var obj = new OrderDelivered(); obj.OrderId = orderID; obj.SellerId = sellerId; obj.ActualDeliveryDate = date1; return(JsonSerializer.Serialize(obj)); }
public OrderDelivered OrderDeliver(OrderDelivered orderDelivered) { try { return(this.orderDeliveredRepo.OrderDeliver(orderDelivered)); } catch (Exception e) { throw new Exception(e.Message); } }
public OrderDelivered UpdateDeliveryStatus(OrderDelivered orderDelivered) { try { return(this.orderDeliveredRepo.UpdateDeliveryStatus(orderDelivered)); } catch (Exception e) { throw new Exception(e.Message); } }
public async Task <IHttpActionResult> GetOrderDelivered(int id) { OrderDelivered orderDelivered = await db.OrderDelivereds.FindAsync(id); if (orderDelivered == null) { return(NotFound()); } return(Ok(orderDelivered)); }
public async Task <IHttpActionResult> DeleteOrderDelivered(int id) { OrderDelivered orderDelivered = await db.OrderDelivereds.FindAsync(id); if (orderDelivered == null) { return(NotFound()); } db.OrderDelivereds.Remove(orderDelivered); await db.SaveChangesAsync(); return(Ok(orderDelivered)); }
private IEnumerable <EventBase> Handle(OrderDelivered e) { OrderHistory orderDelivered = new OrderHistory(); orderDelivered.BookingOrderId = e.BookingId; orderDelivered.DateTime = e.Date.ToString(); orderDelivered.Description = e.Description; orderDelivered.OrderState = typeof(OrderDelivered).ToString(); orderDelivered.SignedBy = e.SignedBy; orderHistory.Add(orderDelivered); return(new EventBase[] { e }); }
public void ProcessEvent() { OrderDelivered orderDelivered = JsonSerializer.Deserialize <OrderDelivered>(JsonString); var db = mongo.GetDatabase("SellersDatabase"); var collection = db.GetCollection <Object>("SellersOrders"); var findSellerFilter = Builders <Object> .Filter.Eq("SellerId", orderDelivered.SellerId); var sellerDocument = (Seller)collection.Find <Object>(findSellerFilter).FirstOrDefault(); if (sellerDocument == null) { Seller seller = new Seller(); seller.SellerId = orderDelivered.SellerId; collection.InsertOne(seller); sellerDocument = (Seller)collection.Find <Object>(findSellerFilter).FirstOrDefault(); } var findOrderFilter = Builders <Object> .Filter.Eq("OrderId", orderDelivered.OrderId); var orderDocument = (Order)collection.Find <Object>(findOrderFilter).FirstOrDefault(); if (orderDocument == null) { try { // adding a new order Order order = new Order(); order.OrderId = orderDelivered.OrderId; order.ActualDeliveryDate = orderDelivered.ActualDeliveryDate; order.SellerId = sellerDocument.Id.ToString(); // insert collection.InsertOne(order); } catch (Exception e) { Console.WriteLine(e.Message); } } else { // update information in the order var updmanyresult = collection.UpdateMany( Builders <Object> .Filter.Eq("OrderId", orderDelivered.OrderId), Builders <Object> .Update .Set("ActualDeliveryDate", orderDelivered.ActualDeliveryDate)); } }
public async Task Handle(OrderDeliveredIntegrationEvent eventMsg) { List <EventBase> events = new List <EventBase>(); if (eventMsg.Id != Guid.Empty) { try { Track trackings = await _trackingContext.GetTrackingAsync(eventMsg.BookingId); if (trackings == null) { trackings = new Track(); } var messageType = _assemblyTypes .Where(t => t.Name.Contains("OrderDelivered")).FirstOrDefault(). Name.ToString(); OrderDelivered orderDelivered = new OrderDelivered(eventMsg.BookingId, eventMsg.Description, eventMsg.Id , messageType, eventMsg.CreationDate, eventMsg.SignedBy); events.AddRange(trackings.OrderDelivered(orderDelivered)); await _trackingContext.SaveTrackingAsync(eventMsg.BookingId, trackings.OriginalVersion, trackings.Version, events); //Publish the event here //Create Integration Event var orderStatusChanged = new OrderStatusChangedIntegrationEvent(eventMsg.BookingId, "OrderDelivered"); _eventBus.Publish(orderStatusChanged); } catch (Exception e) { var ExceptionTelemetry = new ExceptionTelemetry(e); ExceptionTelemetry.Properties.Add("OrderDeliveredIntegrationEvent", eventMsg.BookingId); ExceptionTelemetry.SeverityLevel = SeverityLevel.Critical; telemetry.TrackException(ExceptionTelemetry); throw; } } }
public IActionResult OrderDeliver(OrderDelivered orderDelivered) { try { var userId = TokenUserId(); orderDelivered.UserId = userId; var result = this.orderDeliverManager.OrderDeliver(orderDelivered); if (result != null) { return(this.Ok(new { Status = true, Message = "Order delivered add Successfully", Data = result })); } return(this.BadRequest(new { Status = true, Message = "Unable to delivered add order" })); } catch (Exception e) { return(this.BadRequest(new { Status = false, Message = e.Message })); } }
public IActionResult UpdateDeliveryStatus(OrderDelivered orderDelivered) { try { var userId = TokenUserId(); orderDelivered.UserId = userId; var result = this.orderDeliverManager.UpdateDeliveryStatus(orderDelivered); if (result != null) { return(this.Ok(new { Status = true, Message = "Update Delivery Status", Data = result })); } return(this.BadRequest(new { Status = true, Message = "Unable Update Delivery Status" })); } catch (Exception e) { return(this.BadRequest(new { Status = false, Message = e.Message })); } }
public async Task Given() { saga = new BillingSaga { Data = new SagaData() }; context = new TestableMessageHandlerContext(); var billCustomer = new BillCustomer { OrderId = orderId }; var orderDelivered = new OrderDelivered { OrderId = orderId }; await saga.Handle(billCustomer, context); await saga.Handle(orderDelivered, context); }
public void When_DeliverOrder_OrderDelivered() { Given(InitialEvents); var command = new DeliverOrder(id); command.Metadata.CausationId = command.Metadata.CommandId; command.Metadata.CorrelationId = causationAndCorrelationId; When(command); var expectedEvent = new OrderDelivered(id); expectedEvent.Metadata.CausationId = command.Metadata.CommandId; expectedEvent.Metadata.CorrelationId = causationAndCorrelationId; expectedEvent.Metadata.ProcessId = command.Metadata.ProcessId; Then(expectedEvent); }
public async Task <IHttpActionResult> PostOrderDelivered(OrderDeliveredBinding orderDeliveredModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } ApplicationUser appuser = await _userManager.FindByIdAsync(User.Identity.GetUserId()); var orderDelivered = new OrderDelivered() { OrderStatus = await db.OrderStatus.FindAsync(orderDeliveredModel.OrderStatusId), Order = await db.Orders.FindAsync(orderDeliveredModel.OrderId), Comment = orderDeliveredModel.Comment, User = appuser }; db.OrderDelivereds.Add(orderDelivered); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = orderDelivered.Id }, orderDelivered)); }
public void When_OrderDelivered_NotifyAdmin() { var notificationId = Guid.NewGuid(); AggregateRepository.CreateGuid = () => notificationId; SetupPreviousEvents(); orderId = AddProcessedEvent <BasketAggregate>(new BasketCheckedOut(basketId, OrderLines, shippingAddress)); AddProcessedEvent <OrderAggregate>(new OrderCreated(orderId, basketId, shippingAddress), orderId); AddProcessedEvent <ProductAggregate>(new ProductReserved(productOneId, 10), orderId); AddProcessedEvent <OrderAggregate>(new OrderLineAdded(orderId, OrderLines[0]), orderId); AddProcessedEvent <ProductAggregate>(new ProductReserved(productTwoId, 20), orderId); AddProcessedEvent <OrderAggregate>(new OrderLineAdded(orderId, OrderLines[1]), orderId); AddProcessedEvent <OrderAggregate>(new OrderReadyForShipping(orderId), orderId); AddProcessedEvent <OrderAggregate>(new OrderShipped(orderId), orderId); var evt = new OrderDelivered(orderId); AddPreviousEvent <OrderAggregate>(evt); SetInitalMetadata(); Given(_initialEvents.ToArray()); WhenProcessed(evt); var expectedCommands = new List <ICommand> { new NotifyAdmin(notificationId) }; var expectedEvents = new List <IEvent> { new EventProcessed(orderId, evt) }; SetMetadata(evt, expectedCommands, expectedEvents); Then(expectedCommands.ToArray()); Then(expectedEvents.ToArray()); }
public async Task Handle(OrderDelivered message, IMessageHandlerContext context) { Data.OrderDeliveredReceived = true; await CheckForAllMessagesReceivedAndComplete(context); }
private void Apply(OrderDelivered evt) { _status = Status.Delivered; }
private void AddOrderDeliveredDomainEvent() { var orderDeliveredDomainEvent = new OrderDelivered(this); AddDomainEvent(orderDeliveredDomainEvent); }
public async Task HandleAsync(OrderDelivered @event) { await ExecuteSaveAsync(@event.AggregateId, model => model.Deliver()); }
private void Apply(OrderDelivered obj) { status = Status.Complete; }
private void OnOrderDelivered(OrderDelivered evt) { _orderProcessEventHandler.HandleEvent <OrderDelivered, OrderProcessManager>(evt); SetLastEventNumber(evt); }
private void Handle(OrderDelivered @event) { IsComplete = true; }
private void Apply(OrderDelivered evt) { State = OrderState.Delivered; }
private void Apply(OrderDelivered obj) { _state = OrderAggregate.OrderState.Delivered; DispatchCommand <DummyNotifier>(new NotifyAdmin(AggregateRepository.CreateGuid())); }
public static void ProduceEvents() { List <int> eventorder; eventorder = new List <int>(); eventorder.Add(1); //Order Created eventorder.Add(2); //Order Shipped eventorder.Add(3); //Order Delivered eventorder.Add(4); //Order Cancelled eventorder.Add(5); //Order Returned var conf = new ProducerConfig { BootstrapServers = "localhost:9092" }; Action <DeliveryReport <Null, string> > handler = r => Console.WriteLine(r.Error.IsError ? $"Delivery Error: {r.Error.Reason}" : $"Delivered message to {r.TopicPartitionOffset}"); using (var p = new ProducerBuilder <Null, string>(conf).Build()) { var random = new Random(); while (true) { string sellerId = Guid.NewGuid().ToString(); //seller can repeat //userId is randomly generated //The events should also be generated in random order //shuffle the list //7 orders per seller for (int i = 0; i < 7; ++i) { eventorder = eventorder.OrderBy(x => Guid.NewGuid()).ToList(); var orderId = Guid.NewGuid().ToString(); foreach (var num in eventorder) { var message = ""; switch (num) { case 1: //Order Created var orderCreated = new OrderCreated(); message = orderCreated.CreateJson(orderId, sellerId); Console.WriteLine("order-created " + message); p.Produce("order-created", new Message <Null, string> { Value = message }, handler); break; case 2: //Order Shipped var orderShipped = new OrderShipped(); message = orderShipped.createJson(orderId, sellerId); Console.WriteLine("order-shipped " + message); p.Produce("order-shipped", new Message <Null, string> { Value = message }, handler); break; case 3: //Order Delivered var orderDelivered = new OrderDelivered(); message = orderDelivered.CreateJson(orderId, sellerId); Console.WriteLine("order-delivered " + message); p.Produce("order-delivered", new Message <Null, string> { Value = message }, handler); break; case 4: //Order Cancelled var orderCancelled = new OrderCancelled(); message = orderCancelled.createJson(orderId, sellerId, "customer", "The reason for cancellation"); Console.WriteLine("order-cancelled " + message); p.Produce("order-cancelled", new Message <Null, string> { Value = message }, handler); break; case 5: //Order Returned var orderReturned = new OrderReturned(); message = orderReturned.createJson(orderId, sellerId); Console.WriteLine("order-returned " + message); p.Produce("order-returned", new Message <Null, string> { Value = message }, handler); break; } Thread.Sleep(1000); } Thread.Sleep(1000); } } } }
public void When(OrderDelivered @event) { }
public OrderDeliveredDetails GetOrderDeliveredDetails(int tenantId, int userId, OrderDeliveredFilterRequest orderDeliveredFilter) { DataSet ds = new DataSet(); OrderDeliveredDetails objdetails = new OrderDeliveredDetails(); List <OrderDelivered> orderDelivered = new List <OrderDelivered>(); int TotalCount = 0; try { conn.Open(); MySqlCommand cmd = new MySqlCommand("SP_PHYGetOrderDeliveredDetails", conn) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.AddWithValue("@_tenantID", tenantId); cmd.Parameters.AddWithValue("@_UserID", userId); cmd.Parameters.AddWithValue("@_SearchText", orderDeliveredFilter.SearchText); cmd.Parameters.AddWithValue("@_pageno", orderDeliveredFilter.PageNo); cmd.Parameters.AddWithValue("@_pagesize", orderDeliveredFilter.PageSize); cmd.Parameters.AddWithValue("@_FilterStatus", orderDeliveredFilter.FilterStatus); MySqlDataAdapter da = new MySqlDataAdapter { SelectCommand = cmd }; da.Fill(ds); if (ds != null && ds.Tables[0] != null) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { OrderDelivered obj = new OrderDelivered { ID = Convert.ToInt32(ds.Tables[0].Rows[i]["ID"]), InvoiceNo = Convert.ToString(ds.Tables[0].Rows[i]["InvoiceNo"]), CustomerName = Convert.ToString(ds.Tables[0].Rows[i]["CustomerName"]), MobileNumber = Convert.ToString(ds.Tables[0].Rows[i]["MobileNumber"]), Date = Convert.ToString(ds.Tables[0].Rows[i]["Date"]), Time = Convert.ToString(ds.Tables[0].Rows[i]["Time"]), StatusName = Convert.ToString(ds.Tables[0].Rows[i]["StatusName"]), ActionTypeName = Convert.ToString(ds.Tables[0].Rows[i]["ActionTypeName"]), orderDeliveredItems = new List <OrderDeliveredItem>() }; obj.orderDeliveredItems = ds.Tables[1].AsEnumerable().Where(x => (x.Field <int>("OrderID")).Equals(obj.ID)).Select(x => new OrderDeliveredItem() { ItemID = Convert.ToString(x.Field <string>("ItemID")), ItemName = Convert.ToString(x.Field <string>("ItemName")), ItemPrice = x.Field <double>("ItemPrice"), Quantity = x.Field <int>("Quantity") }).ToList(); orderDelivered.Add(obj); } } if (ds != null && ds.Tables[2] != null) { TotalCount = ds.Tables[2].Rows[0]["TotalOrder"] == DBNull.Value ? 0 : Convert.ToInt32(ds.Tables[2].Rows[0]["TotalOrder"]); } objdetails.orderDelivereds = orderDelivered; objdetails.TotalCount = TotalCount; } catch (Exception) { throw; } finally { if (conn != null) { conn.Close(); } if (ds != null) { ds.Dispose(); } } return(objdetails); }
public void DeliverOrder() { OrderDelivered?.Invoke(this); }
public async Task UpdateBookingModelInCache(Message msg) { RedisCacheService rCache = new RedisCacheService(); List <EventBase> events = new List <EventBase>(); Track tracking = new Track(); var bookingId = string.Empty; List <OrderHistory> trackingHistory = new List <OrderHistory>(); try { if (msg.Label == "BookingAdd") { BookingAddIntegrationEvent eventMsg = JsonConvert.DeserializeObject <BookingAddIntegrationEvent>(Encoding.UTF8.GetString(msg.Body)); string messageType = "BookingCreated"; BookingCreated bookingCreated = new BookingCreated(eventMsg.BookingId, string.Empty, eventMsg.Id , messageType, eventMsg.CreationDate, eventMsg.Origin, eventMsg.Destination); bookingId = eventMsg.BookingId; tracking.BookingAdd(bookingCreated); } else if (msg.Label == "OrderPicked") { OrderPickedIntegrationEvent eventMsg = JsonConvert.DeserializeObject <OrderPickedIntegrationEvent>(Encoding.UTF8.GetString(msg.Body)); string messageType = "OrderPicked"; OrderPicked orderPicked = new OrderPicked(eventMsg.BookingId, eventMsg.Description, eventMsg.Id , messageType, eventMsg.CreationDate); bookingId = eventMsg.BookingId; tracking.OrderPicked(orderPicked); } else if (msg.Label == "OrderTransit") { OrderTransitIntegrationEvent eventMsg = JsonConvert.DeserializeObject <OrderTransitIntegrationEvent>(Encoding.UTF8.GetString(msg.Body)); string messageType = "OrderInTransit"; OrderInTransit orderInTransit = new OrderInTransit(eventMsg.BookingId, eventMsg.Description, eventMsg.Id , messageType, eventMsg.CreationDate); bookingId = eventMsg.BookingId; tracking.OrderInTransit(orderInTransit); } else if (msg.Label == "OrderDelivered") { OrderDeliveredIntegrationEvent eventMsg = JsonConvert.DeserializeObject <OrderDeliveredIntegrationEvent>(Encoding.UTF8.GetString(msg.Body)); string messageType = "OrderDelivered"; OrderDelivered orderDelivered = new OrderDelivered(eventMsg.BookingId, eventMsg.Description, eventMsg.Id , messageType, eventMsg.CreationDate, eventMsg.SignedBy); bookingId = eventMsg.BookingId; tracking.OrderDelivered(orderDelivered); } else if (msg.Label == "PaymentProcessed") { PaymentProcessedIntegrationEvent eventMsg = JsonConvert.DeserializeObject <PaymentProcessedIntegrationEvent>(Encoding.UTF8.GetString(msg.Body)); string messageType = "PaymentProcessed"; string description = string.Empty; if (eventMsg.PaymentStatus == PaymetStatus.Completed) { description = "Payment Done"; } else if (eventMsg.PaymentStatus == PaymetStatus.Canceled) { description = "Payment Failed"; } else if (eventMsg.PaymentStatus == PaymetStatus.Pending) { description = "Payment Pending"; } PaymentProcessed eventPaymentProcessed = new PaymentProcessed(eventMsg.BookingOrderId, description, eventMsg.Id, messageType, eventMsg.CreationDate); bookingId = eventMsg.BookingOrderId; tracking.PaymentProcessed(eventPaymentProcessed); } //If Booking ID Exists if (!string.IsNullOrEmpty(bookingId)) { if (!string.IsNullOrEmpty(rCache.Get(bookingId))) { trackingHistory = JsonConvert.DeserializeObject <List <OrderHistory> >(rCache.Get(bookingId)); } //Append new event to old events trackingHistory.AddRange(tracking.orderHistory); //Serialze the result var result = JsonConvert.SerializeObject(trackingHistory); await rCache.Remove(bookingId); //Update the Cache if (!string.IsNullOrEmpty(result)) { await rCache.Save(bookingId, result); } } } catch (Exception ex) { throw ex; } }
public IEnumerable <EventBase> OrderDelivered(OrderDelivered e) { return(HandleEvent(e)); }