public static bool CreatOrder(OrderInfo orderInfo)
 {
     bool flag = false;
     Database database = DatabaseFactory.CreateDatabase();
     int quantity = orderInfo.LineItems.Sum<KeyValuePair<string, LineItemInfo>>((Func<KeyValuePair<string, LineItemInfo>, int>) (item => item.Value.Quantity));
     lock (createOrderLocker)
     {
         if (orderInfo.GroupBuyId > 0)
         {
             checkCanGroupBuy(quantity, orderInfo.GroupBuyId);
         }
         using (DbConnection connection = database.CreateConnection())
         {
             connection.Open();
             DbTransaction dbTran = connection.BeginTransaction();
             try
             {
                 try
                 {
                     if (!new OrderDao().CreatOrder(orderInfo, dbTran))
                     {
                         dbTran.Rollback();
                         return false;
                     }
                     if ((orderInfo.LineItems.Count > 0) && !new LineItemDao().AddOrderLineItems(orderInfo.OrderId, orderInfo.LineItems.Values, dbTran))
                     {
                         dbTran.Rollback();
                         return false;
                     }
                     if (!string.IsNullOrEmpty(orderInfo.CouponCode) && !new CouponDao().AddCouponUseRecord(orderInfo, dbTran))
                     {
                         dbTran.Rollback();
                         return false;
                     }
                     if (orderInfo.GroupBuyId > 0)
                     {
                         GroupBuyDao dao = new GroupBuyDao();
                         GroupBuyInfo groupBuy = dao.GetGroupBuy(orderInfo.GroupBuyId, dbTran);
                         groupBuy.SoldCount += quantity;
                         dao.UpdateGroupBuy(groupBuy, dbTran);
                         dao.RefreshGroupBuyFinishState(orderInfo.GroupBuyId, dbTran);
                     }
                     dbTran.Commit();
                     flag = true;
                 }
                 catch
                 {
                     dbTran.Rollback();
                     throw;
                 }
                 return flag;
             }
             finally
             {
                 connection.Close();
             }
         }
     }
     return flag;
 }
Beispiel #2
0
 public static bool UpdateGroupBuy(GroupBuyInfo groupBuy)
 {
     bool flag;
     Globals.EntityCoding(groupBuy, true);
     Database database = DatabaseFactory.CreateDatabase();
     GroupBuyDao dao = new GroupBuyDao();
     using (DbConnection connection = database.CreateConnection())
     {
         connection.Open();
         DbTransaction dbTran = connection.BeginTransaction();
         try
         {
             if (!dao.UpdateGroupBuy(groupBuy, dbTran))
             {
                 dbTran.Rollback();
                 return false;
             }
             dbTran.Commit();
             flag = true;
         }
         catch (Exception)
         {
             dbTran.Rollback();
             flag = false;
         }
         finally
         {
             connection.Close();
         }
     }
     return flag;
 }