Ejemplo n.º 1
0
        public static bool CreatOrder(List <OrderInfo> orderInfos)
        {
            if (orderInfos.Count <= 0)
            {
                return(false);
            }
            bool     result   = false;
            Database database = DatabaseFactory.CreateDatabase();

            using (DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    foreach (OrderInfo orderInfo in orderInfos)
                    {
                        if (orderInfo == null)
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        ShoppingProcessor.MoveOrderItemImages(orderInfo);
                        OrderDao orderDao = new OrderDao();
                        if (orderInfo.CountDownBuyId > 0)
                        {
                            orderInfo.OrderType = OrderType.CountDown;
                            if (orderDao.ExistCountDownOverbBought(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                            if (!orderDao.UpdateCountDownBuyNum(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                        if (orderInfo.FightGroupActivityId > 0)
                        {
                            orderInfo.OrderType = OrderType.FightGroup;
                            if (!ShoppingProcessor.ManageFightGroupOrder(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                        if (orderInfo.PreSaleId > 0)
                        {
                            orderInfo.OrderType = OrderType.PreSale;
                        }
                        if (orderInfo.GroupBuyId > 0)
                        {
                            orderInfo.OrderType = OrderType.GroupOrder;
                        }
                        if (!orderDao.CreatOrder(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (orderInfo.LineItems.Count > 0 && orderInfo.ParentOrderId != "-1" && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (orderInfo.Gifts.Count > 0)
                        {
                            OrderGiftDao orderGiftDao = new OrderGiftDao();
                            if (!orderGiftDao.AddOrderGift(orderInfo.OrderId, orderInfo.Gifts, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                        if (orderInfo.InputItems != null && orderInfo.InputItems.Count > 0 && !new OrderInputItemDao().AddItems(orderInfo.OrderId, orderInfo.InputItems, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (orderInfo.ParentOrderId == "0" || orderInfo.ParentOrderId == "-1")
                        {
                            if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                            if (orderInfo.DeductionPoints.HasValue && orderInfo.DeductionPoints > 0 && !ShoppingProcessor.CutNeedPoint(orderInfo.DeductionPoints.Value, orderInfo.OrderId, PointTradeType.ShoppingDeduction, orderInfo.UserId))
                            {
                                dbTransaction.Rollback();
                                return(false);
                            }
                        }
                    }
                    dbTransaction.Commit();
                    result = true;
                }
                catch (Exception ex)
                {
                    result = false;
                    Globals.WriteExceptionLog(ex, null, "OrderCreate");
                    dbTransaction.Rollback();
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static bool CreatOrder(OrderInfo orderInfo)
        {
            if (orderInfo == null)
            {
                return(false);
            }
            bool     result   = false;
            Database database = DatabaseFactory.CreateDatabase();

            using (DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    OrderDao orderDao = new OrderDao();
                    if (orderInfo.CountDownBuyId > 0)
                    {
                        orderInfo.OrderType = OrderType.CountDown;
                        if (orderDao.ExistCountDownOverbBought(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                        if (!orderDao.UpdateCountDownBuyNum(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                    }
                    if (orderInfo.FightGroupActivityId > 0)
                    {
                        orderInfo.OrderType = OrderType.FightGroup;
                        if (!ShoppingProcessor.ManageFightGroupOrder(orderInfo, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                    }
                    if (orderInfo.PreSaleId > 0)
                    {
                        orderInfo.OrderType = OrderType.PreSale;
                    }
                    if (orderInfo.GroupBuyId > 0)
                    {
                        orderInfo.OrderType = OrderType.GroupOrder;
                    }
                    if (!orderDao.CreatOrder(orderInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    if (orderInfo.LineItems.Count > 0 && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    if (orderInfo.Gifts.Count > 0)
                    {
                        OrderGiftDao orderGiftDao = new OrderGiftDao();
                        if (!orderGiftDao.AddOrderGift(orderInfo.OrderId, orderInfo.Gifts, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            return(false);
                        }
                    }
                    if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    if (orderInfo.DeductionPoints.HasValue && orderInfo.DeductionPoints > 0 && !ShoppingProcessor.CutNeedPoint(orderInfo.DeductionPoints.Value, orderInfo.OrderId, PointTradeType.ShoppingDeduction, orderInfo.UserId))
                    {
                        dbTransaction.Rollback();
                        return(false);
                    }
                    dbTransaction.Commit();
                    result = true;
                }
                catch
                {
                    dbTransaction.Rollback();
                    throw;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }