Exemple #1
0
        public static List <MOrderItem> MListOrderItem(this List <BoOrderItem> pListOrderItem)
        {
            var lListOrderItem = new List <MOrderItem>();

            pListOrderItem.ForEach(x => {
                var lMOrderItem = new MOrderItem
                {
                    LProduct = new MProduct
                    {
                        LNameProduct = x.LProduct.LNameProduct,
                        LIdProduct   = x.LProduct.LIdProduct
                    },
                    LOrder = new MOrder {
                        LIdOrder = x.LOrder.LIdOrder
                    },
                    LIdOrderItem   = x.LIdOrderItem,
                    LQty           = x.LQty,
                    LValueProduct  = x.LValueProduct,
                    LValueSupplier = x.LValueSupplier,
                    LValueTaxes    = x.LValueTaxes,
                    LValueDesc     = x.LValueDesc,
                    LCreationDate  = x.LCreationDate,
                    LValueTotal    = x.LValueTotal
                };
                lListOrderItem.Add(lMOrderItem);
            });
            return(lListOrderItem);
        }
Exemple #2
0
        public async Task <MOrder> CreateOrderAsync(OrderParams orderParams)
        {
            MOrder order = MOrder.FromParams(orderParams);

            order.Seller = await usersRepository.GetUserAsync <Seller>(order.SellerId);

            order.Status          = OrderConstants.Status.Pending;
            order.Currency        = "USD";
            order.PaymentMethod   = orderParams.PaymentMethod;
            order.PaymentReceiver = order.GetReceiver(order.PaymentMethod);


            foreach (var itemParams in orderParams.Items)
            {
                MOrderItem item = MOrderItem.FromParams(itemParams);

                item.Product = await productsRepository.GetProductAsync(item.ProductId, order.BuyerId);

                if (item.Product == null)
                {
                    return(null);
                }

                if (order.SellerId != item.Product.SellerId)
                {
                    return(null);
                }

                if (item.Product.Customer != null)
                {
                    return(null);
                }

                item.ProductName = item.Product.Name;
                item.Price       = item.Product.Price;

                order.TotalPrice += item.Price;
                order.Items.Add(item);
            }

            Payment payment = Payment.Create(order.PaymentMethod, string.Empty,
                                             order.GetReceiver(order.PaymentMethod), order.Currency, order.TotalPrice);

            foreach (MOrderItem item in order.Items)
            {
                payment.AddItem(item.ProductName, 1, item.Price);
            }

            order.PaymentId = await PaymentGatewayClient.CreatePaymentAsync(payment);

            return(await ordersRepository.AddOrderAsync(order));
        }