public void Confirm()
        {
            var e = new OrderConfirmed();

            Apply(e);
            AddEvent(e);
        }
Exemplo n.º 2
0
 public void Handle(OrderConfirmed @event)
 {
     if (!ProcessOrder(order => order.Id == @event.SourceId, order => order.Status = Order.OrderStatus.Paid))
     {
         logger.LogError("Failed to locate the order with {0} to apply confirmed payment.", @event.SourceId);
     }
 }
        public ActionResult DeleteConfirmed(int id)
        {
            OrderConfirmed orderConfirmed = db.OrderConfirmeds.Find(id);

            db.OrderConfirmeds.Remove(orderConfirmed);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
    public Task HandleAsync(OrderConfirmed @event)
    {
        // Save In Query Db

        Console.WriteLine("Order Confirmed");

        return(Task.CompletedTask);
    }
Exemplo n.º 5
0
        private void Apply(OrderConfirmed evt)
        {
            _orderId    = evt.AggregateId;
            _customerId = evt.CustomerId;
            _orderItems = evt.Items;

            _status = Status.OrderCreated;
        }
Exemplo n.º 6
0
        private void TestEventSourcing(IDocumentStore store)
        {
            var userId     = Guid.NewGuid();
            var streamId   = Guid.NewGuid();
            var catalogId1 = Guid.NewGuid();
            var catalogId2 = Guid.NewGuid();
            var orderId    = Guid.NewGuid();

            using var session = store.OpenSession();

            var catalogAdded1 = new CatalogAdded
            {
                CatalogId = catalogId1,
                Quantity  = 5,
                UserId    = userId
            };

            var catalogAdded2 = new CatalogAdded
            {
                CatalogId = catalogId2,
                Quantity  = 3,
                UserId    = userId
            };

            // Assume user adds 2 catalog first
            session.Events.StartStream(streamId, catalogAdded1, catalogAdded2);
            session.SaveChanges();

            var catalogRemoved = new CatalogRemoved
            {
                CatalogId = catalogId1,
                Quantity  = 2,
                UserId    = userId
            };

            var orderCreated = new OrderCreated
            {
                UserId     = userId,
                OrderId    = orderId,
                TotalMoney = 10000000
            };

            var orderChangeStatus = new OrderStatusChangeToPaid {
                OrderId = orderId
            };
            var orderConfirmed = new OrderConfirmed {
                OrderId = orderId
            };
            var orderShipped = new OrderShipped {
                OrderId = orderId
            };
            var orderCompleted = new OrderCompleted {
                OrderId = orderId
            };

            session.Events.Append(streamId, orderCreated, catalogRemoved, orderChangeStatus, orderConfirmed, orderShipped, orderCompleted);
            session.SaveChanges();
        }
        public async Task<ConfirmOrder> Response(MessageDirectory.Request.ConfirmOrder request, MessageContext context)
        {
            ConfirmOrder response = new ConfirmOrder();
            this.dataContext = DataUtility.GetDataContext(dataContext);
            using (dataContext)
            { 
                var user = await dataContext.Users.SingleOrDefaultAsync(p => p.Id == request.UserId);

                if (user == null)
                {
                    Exception ex = new Exception("User Doesnt not exist");
                    ex.Data.Add("Email",request.UserId); 
                    throw ex;
                }

                var restaurant = await dataContext.Restaurants.SingleOrDefaultAsync(p => p.Id == request.RestaurantId);

                if (restaurant == null)
                {
                    Exception ex = new Exception("Restaurant Doesnt not exist");
                    ex.Data.Add("Id", request.RestaurantId);
                    throw ex;
                }

                var order = new Order()
                {
                    Amount = request.Amount.Value,
                    Address = request.Address,
                    User = user,
                    Restaurant = restaurant,
                    CreateDate = DateTime.Now,
                    PhoneNumber = request.PhoneNumber,
                    Email = request.Email,
                    City = request.City,
                    DeliveryType = (Data.Enum.DeliveryType)request.DeliveryType,
                    Products = request.Products.Select(p => new Product()
                    {
                        ProductId = p.ProductId,
                        Quantity = p.Quantity
                    }).ToList(),     
                };

                dataContext.Orders.Add(order);

                await dataContext.SaveChangesAsync();

                OrderConfirmed orderConfiremd = new OrderConfirmed()
                {
                    Id = order.Id
                };

                response.id = order.Id;

                await Bus.PublishAsync(orderConfiremd);
            }

            return response;
        }
        /// <summary>
        /// Message to recive a Confirmed Order , Calculate the price and let
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task Consume(OrderConfirmed message, MessageContext context)
        {
            using (OrderDataContext dataContext = new OrderDataContext())
            {
                Data.Model.Order order = dataContext.Orders.Include(p => p.Products).SingleOrDefault(p => p.Id == message.Id);
                if (order == null)
                {
                    Exception ex = new Exception("Order not found");
                    ex.Data.Add("OrderId", message.Id);
                    throw ex;
                }

                var calcualtePrice = new CalculatePrice()
                {
                    Products = order.Products.Select(p => new Product()
                    {
                        ProductId = p.Id,
                        Quantity  = p.Quantity
                    }).ToList()
                };

                //Wait for resolve Notified bug in library ticket id #56487 for adding GUID in exchange
                //var calculatedPrice = await Bus.RequestAsync<CalculatePrice, MessageDirectory.Response.CalculatePrice>(calcualtePrice);
                //order.Amount = calculatedPrice.TotalAmount;
                //dataContext.SaveChanges();

                var products = order.Products.Select(o => new Product()
                {
                    ProductId = o.ProductId, Quantity = o.Quantity
                }).ToList();

                var reqProductionInfos = new ProductInfo()
                {
                    Products = products
                };

                //var resultInfo = await Bus.RequestAsync<ProductInfo, MessageDirectory.Response.ProductInfo>(reqProductionInfos);
                OrderReadyToDeliver orderReady = new OrderReadyToDeliver()
                {
                    Address      = order.Address,
                    Amount       = order.Amount,
                    City         = order.City,
                    CreateDate   = order.CreateDate,
                    DeliveryType = (DeliveryType)order.DeliveryType,
                    Email        = order.Email,
                    PayedAmount  = order.Amount,
                    PhoneNumber  = order.PhoneNumber,
                    //ProductsToPrepare = resultInfo.Products.Select(p => new ProductToPrepare()
                    //{
                    //    ProductName = p.ProductName,
                    //    Quantity = p.Quantity
                    //}).ToList()
                };

                await Bus.PublishAsync(orderReady);
            }
        }
Exemplo n.º 9
0
        public async Task Handle(OrderPaid message, IMessageHandlerContext context)
        {
            this.log.Info($"Order {message.OrderId} confirmed.");

            var confirmedOrder = new OrderConfirmed
            {
                OrderId = message.OrderId
            };
            await context.Publish(confirmedOrder);
        }
        public void Handle(OrderConfirmed @event)
        {
            var dto = pricedOrderRepository.GetBy(p => p.OrderId == @event.SourceId).FirstOrDefault();

            if (WasNotAlreadyHandled(dto, @event.Version))
            {
                dto.ReservationExpirationDate = null;
                dto.OrderVersion = @event.Version;
                pricedOrderRepository.Update(dto);
            }
        }
        public void Handle(OrderConfirmed @event)
        {
            var dto = GetDraftOrder(@event.SourceId);

            if (WasNotAlreadyHandled(dto, @event.Version))
            {
                dto.State        = DraftOrder.States.Confirmed;
                dto.OrderVersion = @event.Version;
                draftOrderRepository.Update(dto);
            }
        }
Exemplo n.º 12
0
        public void Should_do_nothing_if_ContactMe_is_false()
        {
            var order = new Order
            {
                ContactMe = false
            };
            var @event = new OrderConfirmed(order);

            handler.Handle(@event);

            mailingListRepository.AssertWasNotCalled(r => r.SaveOrUpdate(Arg <MailingListSubscription> .Is.Anything));
        }
 public void Handle(OrderConfirmed @event)
 {
     using (var context = contextFactory.Invoke()) {
         var dto = context.Find <PricedOrder>(@event.SourceId);
         if (WasNotAlreadyHandled(dto, @event.Version))
         {
             dto.ReservationExpirationDate = null;
             dto.OrderVersion = @event.Version;
             context.Save(dto);
         }
     }
 }
        public void when_order_confirmed_then_confirms_order()
        {
            var e = new OrderConfirmed {
                SourceId = placed.SourceId
            };

            sut.Handle(e);

            var order = FindOrder(e.SourceId);

            Assert.Equal(Order.OrderStatus.Paid, order.Status);
        }
 public void Handle(OrderConfirmed @event)
 {
     using (var context = contextFactory.Invoke()) {
         var dto = context.Find <DraftOrder>(@event.SourceId);
         if (WasNotAlreadyHandled(dto, @event.Version))
         {
             dto.State        = DraftOrder.States.Confirmed;
             dto.OrderVersion = @event.Version;
             context.Save(dto);
         }
     }
 }
 public ActionResult Edit([Bind(Include = "MaDonHang,MaKH,MaSanPham,VoucherID,TongTien,NgayDatHang,SoLuong,TinhTrang")] OrderConfirmed orderConfirmed)
 {
     if (ModelState.IsValid)
     {
         db.Entry(orderConfirmed).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaKH      = new SelectList(db.KhachHangs, "MaKH", "TenKH", orderConfirmed.MaKH);
     ViewBag.MaSanPham = new SelectList(db.SanPhams, "MaSanPham", "TenSanPham", orderConfirmed.MaSanPham);
     ViewBag.VoucherID = new SelectList(db.Vouchers, "VoucherID", "TenVoucher", orderConfirmed.VoucherID);
     return(View(orderConfirmed));
 }
Exemplo n.º 17
0
        public void When_order_confirmed_then_confirms_order()
        {
            var e = new OrderConfirmed()
            {
                SourceId = _placed.SourceId
            };

            this._eventHandler.Handle(e);

            var order = this.FindOrder(e.SourceId);

            Assert.AreEqual(Order.OrderStatus.Paid, order.Status);
        }
        // GET: OrderConfirmeds/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OrderConfirmed orderConfirmed = db.OrderConfirmeds.Find(id);

            if (orderConfirmed == null)
            {
                return(HttpNotFound());
            }
            return(View(orderConfirmed));
        }
Exemplo n.º 19
0
        public void Confirm_should_raise_OrderConfirmed_event()
        {
            OrderConfirmed orderConfirmed = null;

            using (DomainEvent.TestWith(e => orderConfirmed = e as OrderConfirmed))
            {
                var order = new Order {
                    OrderStatus = OrderStatus.Pending
                };
                order.Confirm();

                orderConfirmed.ShouldNotBeNull();
                orderConfirmed.Order.ShouldBeTheSameAs(order);
            }
        }
        public void Handle(OrderConfirmed @event)
        {
            using (var context = contextFactory.Invoke()) {
                var pm = context.Find(x => x.OrderId == @event.SourceId);
                if (pm != null)
                {
                    pm.Handle(@event);

                    context.Save(pm);
                }
                else
                {
                    Trace.TraceInformation("Failed to locate the registration process manager to complete with id {0}.", @event.SourceId);
                }
            }
        }
        public void Handle(OrderConfirmed @event)
        {
            var pInfo = repository.GetBy(x => x.OrderId == @event.SourceId).FirstOrDefault();

            if (pInfo != null)
            {
                var manager = new RegistrationProcessManager(pInfo);
                manager.Handle(@event);
                context.RegisterModified(manager.ProcessInfo);
                context.Commit();
            }
            else
            {
                Trace.TraceError("Failed to locate the registration process manager handling the order with id {0}.", @event.SourceId);
            }
        }
        // GET: OrderConfirmeds/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            OrderConfirmed orderConfirmed = db.OrderConfirmeds.Find(id);

            if (orderConfirmed == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaKH      = new SelectList(db.KhachHangs, "MaKH", "TenKH", orderConfirmed.MaKH);
            ViewBag.MaSanPham = new SelectList(db.SanPhams, "MaSanPham", "TenSanPham", orderConfirmed.MaSanPham);
            ViewBag.VoucherID = new SelectList(db.Vouchers, "VoucherID", "TenVoucher", orderConfirmed.VoucherID);
            return(View(orderConfirmed));
        }
        public void Handle(OrderConfirmed @event)
        {
            if (State == ProcessState.ReservationConfirmationReceived || State == ProcessState.PaymentConfirmationReceived)
            {
                ExpirationCommandId = Guid.Empty;
                Completed           = true;

                AddCommand(new CommitSeatReservation {
                    ReservationId = ReservationId,
                    ConferenceId  = ConferenceId
                });
            }
            else
            {
                throw new InvalidOperationException("Cannot handle order confirmation at this stage.");
            }
        }
Exemplo n.º 24
0
        /*
         * public void Handle(PaymentCompleted @event)
         * {
         *  if (this.State == ProcessState.ReservationConfirmationReceived)
         *  {
         *      this.State = ProcessState.PaymentConfirmationReceived;
         *      this.AddCommand(new ConfirmOrder { OrderId = this.OrderId });
         *  }
         *  else
         *  {
         *      throw new InvalidOperationException("Cannot handle payment confirmation at this stage.");
         *  }
         * }
         */
        public void Handle(OrderConfirmed @event)
        {
            if (this.State == ProcessState.ReservationConfirmationReceived || this.State == ProcessState.PaymentConfirmationReceived)
            {
                this.ExpirationCommandId = Guid.Empty;
                this.Completed           = true;

                this.AddCommand(new CommitAnchorReservation
                {
                    ReservationId = this.ReservationID,
                    WorkshopID    = this.WorkshopID
                });
            }
            else
            {
                throw new InvalidOperationException("Cannot handle order confirmation at this stage.");
            }
        }
Exemplo n.º 25
0
        public ActionResult Confirm(int?maGH)
        {
            GioHang        gioHang = db.GioHangs.FirstOrDefault(m => m.MaGioHang == maGH);
            OrderConfirmed tmp1    = new OrderConfirmed();

            tmp1.MaKH        = gioHang.MaKH;
            tmp1.MaSanPham   = gioHang.MaSanPham;
            tmp1.SoLuong     = gioHang.SoLuong;
            tmp1.TongTien    = gioHang.TongTien;
            tmp1.TinhTrang   = "Đã Xác Nhận";
            tmp1.VoucherID   = gioHang.VoucherID;
            tmp1.NgayDatHang = DateTime.Now.ToShortDateString();
            db.OrderConfirmeds.Add(tmp1);
            db.SaveChanges();



            GioHang gioHangXoa = db.GioHangs.Find(maGH);

            db.GioHangs.Remove(gioHangXoa);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 26
0
 private void OnOrderConfirmed(OrderConfirmed e)
 {
     this.isConfirmed = true;
 }
Exemplo n.º 27
0
 private void OnOrderConfirmed(OrderConfirmed e)
 {
     this.isConfirmed = true;
 }
Exemplo n.º 28
0
 public Task HandleAsync(OrderConfirmed @event)
 {
     this.spy.Spy("OrderConfirmed");
     return(Task.FromResult(0));
 }
Exemplo n.º 29
0
 public void Confirm()
 {
     confirmed = true;
     OrderConfirmed?.Invoke();
 }
Exemplo n.º 30
0
 private void Apply(OrderConfirmed @event)
 {
     Confirmed = true;
 }
Exemplo n.º 31
0
        public void when_order_confirmed_then_confirms_order()
        {
            var e = new OrderConfirmed
            {
                SourceId = placed.SourceId,
            };

            this.sut.Handle(e);

            var order = FindOrder(e.SourceId);

            Assert.Equal(Order.OrderStatus.Paid, order.Status);
        }
Exemplo n.º 32
0
 public Task HandleAsync(OrderConfirmed @event)
 {
     return(Task.FromResult(0));
 }