Exemplo n.º 1
0
        public Result Create(OrderRequest orderRequest)
        {
            if (!string.IsNullOrWhiteSpace(orderRequest.CouponId))
            {
                var couponResult = DomainRegistry.SellingPriceService().IsCouponCanUse(orderRequest.CouponId, orderRequest.OrderTime);
                if (!couponResult.IsSuccess)
                {
                    return(Result.Fail(couponResult.Msg));
                }
            }

            var orderId = DomainRegistry.OrderRepository().NextIdentity();
            var order   = Domain.Order.Aggregate.Order.Create(orderId, orderRequest.UserId, orderRequest.Receiver,
                                                              orderRequest.CountryId, orderRequest.CountryName, orderRequest.ProvinceId, orderRequest.ProvinceName,
                                                              orderRequest.CityId, orderRequest.CityName, orderRequest.DistrictId, orderRequest.DistrictName,
                                                              orderRequest.Address, orderRequest.Mobile, orderRequest.Phone, orderRequest.Email,
                                                              orderRequest.PaymentMethodId, orderRequest.PaymentMethodName, orderRequest.ExpressId,
                                                              orderRequest.ExpressName, orderRequest.Freight, orderRequest.CouponId, orderRequest.CouponName, orderRequest.CouponValue, orderRequest.OrderTime);

            foreach (var orderItemRequest in orderRequest.OrderItems)
            {
                order.AddOrderItem(orderItemRequest.ProductId, orderItemRequest.Quantity, orderItemRequest.UnitPrice, orderItemRequest.JoinedMultiProductsPromotionId, orderItemRequest.ProductName);
            }

            DomainRegistry.OrderRepository().Save(order);
            DomainEventBus.Instance().Publish(new OrderCreated(order.ID, order.UserId, order.Receiver));
            return(Result.Success());
        }
Exemplo n.º 2
0
        public static Order Create(string id, string userId, string receiver, string countryId, string countryName, string provinceId, string provinceName, string cityId, string cityName, string districtId, string districtName, string address, string mobile, string phone, string email, string paymentMethodId, string paymentMethodName, string expressId, string expressName, decimal freight, string couponId, string couponName, decimal couponValue, DateTime orderTime)
        {
            var order = new Order(id, userId, receiver, countryId, countryName, provinceId, provinceName, cityId, cityName, districtId, districtName, address, mobile, phone, email, paymentMethodId, paymentMethodName, expressId, expressName, freight, couponId, couponName, couponValue, orderTime, default(DateTime));

            DomainEventBus.Instance().Publish(new OrderCreated(order.ID, order.UserId, order.Receiver));

            return(order);
        }
        public static void Initialize()
        {
            var types = Assembly.Load("Mall.Domain.Order.DomainEventSubscribers").GetTypes().Where(ent => !ent.IsGenericType && ent.GetInterface(typeof(IDomainEventSubscriber).FullName) != null).ToList();

            foreach (var type in types)
            {
                var subscriberInstance = Activator.CreateInstance(AppDomain.CurrentDomain, type.Assembly.FullName, type.FullName).Unwrap();
                var subscriber         = (IDomainEventSubscriber)subscriberInstance;
                DomainEventBus.Instance().Subscribe(subscriber);
            }
        }