Exemple #1
0
        public static int AddPromotion(PromotionInfo promotion)
        {
            Database database = DatabaseFactory.CreateDatabase();
            int      result;

            using (System.Data.Common.DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                System.Data.Common.DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    PromotionDao promotionDao = new PromotionDao();
                    int          num          = promotionDao.AddPromotion(promotion, dbTransaction);
                    if (num <= 0)
                    {
                        dbTransaction.Rollback();
                        result = -1;
                    }
                    else
                    {
                        if (!promotionDao.AddPromotionMemberGrades(num, promotion.MemberGradeIds, dbTransaction))
                        {
                            dbTransaction.Rollback();
                            result = -2;
                        }
                        else
                        {
                            dbTransaction.Commit();
                            result = num;
                        }
                    }
                }
                catch (Exception var_5_76)
                {
                    dbTransaction.Rollback();
                    result = 0;
                }
                finally
                {
                    dbConnection.Close();
                }
            }
            return(result);
        }
        public static int AddPromotion(PromotionInfo promotion, bool IsMobileExclusive = false)
        {
            bool     flag     = PromoteHelper.ProcessStoreType4PromotionInfo(promotion);
            Database database = DatabaseFactory.CreateDatabase();

            using (DbConnection dbConnection = database.CreateConnection())
            {
                dbConnection.Open();
                DbTransaction dbTransaction = dbConnection.BeginTransaction();
                try
                {
                    PromotionDao promotionDao = new PromotionDao();
                    int          num          = (int)promotionDao.Add(promotion, null);
                    if (num <= 0)
                    {
                        dbTransaction.Rollback();
                        return(-1);
                    }
                    if (flag)
                    {
                        StoreActivityHelper.SaveStoreActivity(promotion.StoreIds, num, 1);
                    }
                    if (!IsMobileExclusive && !promotionDao.AddPromotionMemberGrades(num, promotion.MemberGradeIds, dbTransaction))
                    {
                        dbTransaction.Rollback();
                        return(-2);
                    }
                    dbTransaction.Commit();
                    return(num);
                }
                catch (Exception)
                {
                    dbTransaction.Rollback();
                    return(0);
                }
                finally
                {
                    dbConnection.Close();
                }
            }
        }