コード例 #1
0
        public DE.OrderHistory GetOrderHistoryByHistoryId(Guid historyId)
        {
            if (Guid.Empty.Equals(historyId))
            {
                throw new ArgumentNullException("historyId");
            }

            try
            {
                var orderHistory = this.GetOrderHistoryFromMongo(historyId);
                if (orderHistory == null)
                {
                    return(null);
                }

                var result     = new DE.OrderHistory();
                var orderItems = new List <DE.OrderItem>();

                Mapper.Map(orderHistory, result);

                if (orderHistory.Items != null)
                {
                    Mapper.Map(orderHistory.Items, orderItems);
                    orderItems.ForEach(i => result.AddOrderItem(i));
                }

                return(result);
            }
            catch (Exception e)
            {
                throw new RepositoryException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRetrievingOrderHistoryByHistoryId, historyId), e);
            }
        }
コード例 #2
0
        public ICollection <DE.OrderHistory> GetOrdersHistories(int customerId)
        {
            try
            {
                var histories = this.GetOrderHistoriesFromMongo(new Dictionary <string, object> {
                    { "customerId", customerId }
                }).ToList();
                if (histories == null || histories.Count() == 0)
                {
                    return(null);
                }

                var result = new List <DE.OrderHistory>();

                foreach (var history in histories)
                {
                    var orderHistory = new DE.OrderHistory();
                    Mapper.Map(history, orderHistory);

                    var orderItems = new List <DE.OrderItem>();
                    Mapper.Map(history.Items, orderItems);
                    orderItems.ForEach(i => orderHistory.AddOrderItem(i));

                    result.Add(orderHistory);
                }

                return(result);
            }
            catch (Exception e)
            {
                throw new RepositoryException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRetrievingOrdersHistoryForCustomerId, customerId), e);
            }
        }
コード例 #3
0
        public DE.OrderHistory GetOrderHistoryByTrackingId(Guid trackingId)
        {
            if (Guid.Empty.Equals(trackingId))
            {
                throw new ArgumentNullException("trackingId");
            }

            try
            {
                var orderHistory = this.GetOrderHistoriesFromMongo(new Dictionary <string, object> {
                    { "orderCode", trackingId }
                }).FirstOrDefault();

                if (orderHistory == null)
                {
                    return(null);
                }

                var result     = new DE.OrderHistory();
                var orderItems = new List <DE.OrderItem>();

                Mapper.Map(orderHistory, result);
                if (orderHistory.Items != null)
                {
                    Mapper.Map(orderHistory.Items, orderItems);
                    orderItems.ForEach(i => result.AddOrderItem(i));
                }

                return(result);
            }
            catch (Exception e)
            {
                throw new RepositoryException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRetrievingOrderByTrackingId, trackingId), e);
            }
        }
コード例 #4
0
        public void SaveOrderHistory(DE.OrderHistory orderHistory)
        {
            if (orderHistory == null)
            {
                throw new ArgumentNullException("orderHistory");
            }

            try
            {
                var savedOrderHistory = new OrderHistory(orderHistory.HistoryId, orderHistory.TrackingId);
                Mapper.Map(orderHistory, savedOrderHistory);
                this.SaveOrderHistoryToMongo(savedOrderHistory);
            }
            catch (Exception e)
            {
                throw new RepositoryException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorSavingOrderHistory, orderHistory.TrackingId), e);
            }
        }
コード例 #5
0
        public DE.Order GetPendingOrderByTrackingId(Guid trackingId)
        {
            if (Guid.Empty.Equals(trackingId))
            {
                throw new ArgumentNullException("trackingId");
            }

            try
            {
                IMongoQuery query      = null;
                var         collection = GetDatabase().GetCollection <OrderHistory>(MongoCollection);
                query = Query.And(
                    Query <OrderHistory> .EQ(e => e.OrderCode, trackingId),
                    Query <OrderHistory> .EQ(e => e.Status, DE.OrderStatus.Pending));
                var mongoHistory = collection.Find(query).FirstOrDefault();

                if (mongoHistory == null)
                {
                    return(null);
                }

                var orderHistory     = new DE.OrderHistory();
                var domainOrderItems = new List <DE.OrderItem>();

                Mapper.Map(mongoHistory, orderHistory);
                if (mongoHistory.Items != null)
                {
                    Mapper.Map(mongoHistory.Items, domainOrderItems);
                    domainOrderItems.ForEach(i => orderHistory.AddOrderItem(i));
                }

                if (orderHistory != null)
                {
                    var newOrder = new DE.Order()
                    {
                        BillToAddress   = orderHistory.BillToAddress,
                        CreditCard      = orderHistory.CreditCard,
                        CustomerId      = orderHistory.CustomerId,
                        DueDate         = orderHistory.DueDate,
                        Freight         = orderHistory.Freight,
                        OrderDate       = orderHistory.OrderDate,
                        ShippingAddress = orderHistory.ShippingAddress,
                        Status          = orderHistory.Status,
                        TrackingId      = orderHistory.TrackingId,
                    };

                    foreach (var shoppingCartItem in orderHistory.OrderItems)
                    {
                        newOrder.AddOrderItem(new DE.OrderItem()
                        {
                            Product   = shoppingCartItem.Product,
                            Quantity  = (short)shoppingCartItem.Quantity,
                            UnitPrice = shoppingCartItem.UnitPrice
                        });
                    }

                    return(newOrder);
                }

                return(null);
            }
            catch (Exception e)
            {
                throw new RepositoryException(string.Format(CultureInfo.CurrentCulture, Strings.ErrorRetrievingOrderByTrackingId, trackingId), e);
            }
        }