コード例 #1
0
        public bool DeleteNewCouponConfigByActivityId(Guid activityId, string user)
        {
            var result = false;

            try
            {
                if (activityId != Guid.Empty)
                {
                    dbScopeManager.CreateTransaction(conn =>
                    {
                        DALNewCoupon.DeleteNewCouponConfigByActivityId(conn, activityId);
                        DALNewCoupon.DeleteRecommendActivityByActivityId(conn, activityId);
                        DALNewCoupon.DeleteCouponRulesConfig(conn, activityId);
                        result = true;
                    });
                    if (result)
                    {
                        InsertLog("DeleteNewCouponConfigByActivityId", activityId.ToString(), "删除配置", "删除配置", user, LogType);
                        Thread.Sleep(2000);
                        RefreshRandomCouponCache(activityId);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(result);
        }
コード例 #2
0
        public bool UpsertNewConponConfig(NewCouponActivity model, string user)
        {
            var result = false;
            var msg    = string.Empty;

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var flag = false;
                    if (model != null)
                    {
                        if (model.ActivityId != Guid.Empty)
                        {
                            msg  = "更新配置";
                            flag = DALNewCoupon.UpdateNewCouponConfig(conn, model, user) > 0;
                        }
                        else
                        {
                            msg = "添加配置";
                            model.ActivityId = Guid.NewGuid();
                            flag             = DALNewCoupon.InsertNewCouponConfig(conn, model, user) > 0;
                        }

                        if (model.RecommendActivityForInit != null && model.RecommendActivityForInit.Any())
                        {
                            model.AllRecommendActivity.AddRange(model.RecommendActivityForInit);
                        }
                        if (model.RecommendActivityForSuccess != null && model.RecommendActivityForSuccess.Any())
                        {
                            model.AllRecommendActivity.AddRange(model.RecommendActivityForSuccess);
                        }

                        if (flag)
                        {
                            DALNewCoupon.DeleteRecommendActivityByActivityId(conn, model.ActivityId);
                            DALNewCoupon.DeleteCouponRulesConfig(conn, model.ActivityId);
                            if (model.AllRecommendActivity != null && model.AllRecommendActivity.Any())
                            {
                                foreach (var item in model.AllRecommendActivity)
                                {
                                    item.ActivityId = model.ActivityId;
                                    DALNewCoupon.InsertRecommendActivityConfig(conn, item);
                                }
                            }
                            if (model.CouponRulesConfig != null && model.CouponRulesConfig.Any())
                            {
                                foreach (var item in model.CouponRulesConfig)
                                {
                                    item.ActivityId = model.ActivityId;
                                    DALNewCoupon.InsertCouponRulesConfig(conn, item);
                                }
                            }
                        }
                        result = true;
                    }
                });
                if (result)
                {
                    model.AllRecommendActivity = new List <RecommendActivityConfig>();
                    InsertLog("UpsertNewConponConfig", model.ActivityId.ToString(), JsonConvert.SerializeObject(model), msg, user, LogType);
                    Thread.Sleep(2000);
                    RefreshRandomCouponCache(model.ActivityId);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            return(result);
        }