예제 #1
0
        public bool UpsertPaceageActivityConfig(PackageActivityConfig data, string user)
        {
            var    result = false;
            string msg    = "";

            try
            {
                dbScopeManager.CreateTransaction(conn =>
                {
                    var flag = false;
                    if (data.ActivityId != Guid.Empty)
                    {
                        msg  = "更新活动配置";
                        flag = DALPackageActivity.UpdatePackageActivityConfig(conn, data, user);
                    }
                    else
                    {
                        msg             = "添加活动配置";
                        data.ActivityId = Guid.NewGuid();
                        flag            = DALPackageActivity.InsertPackageActivityConfig(conn, data, user);
                    }

                    if (flag)
                    {
                        DALPackageActivity.DeletePackageActivitySceneConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityShopConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityProductConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityVehicleConfig(conn, data.ActivityId);
                        DALPackageActivity.DeletePackageActivityPriceConfig(conn, data.ActivityId);
                        if (data.RoundConfig != null && data.RoundConfig.Any())
                        {
                            foreach (var item in data.RoundConfig)
                            {
                                item.ActivityId = data.ActivityId;
                                DALPackageActivity.InsertPackageActivitySceneConfig(conn, item);
                            }
                        }
                        if (data.ProductConfig != null && data.ProductConfig.Any())
                        {
                            foreach (var item in data.ProductConfig)
                            {
                                item.ActivityId = data.ActivityId;
                                DALPackageActivity.InsertPackageActivityProductConfig(conn, item);
                            }
                        }
                        if (data.ShopConfig != null && data.ShopConfig.Any())
                        {
                            foreach (var item in data.ShopConfig)
                            {
                                item.ActivityId = data.ActivityId;
                                DALPackageActivity.InsertPackageActivityShopConfig(conn, item);
                            }
                        }
                        if (data.VehicleConfig != null && data.VehicleConfig.Any())
                        {
                            var vehicleIds = data.VehicleConfig.Select(x => x.VehicleID).Distinct();
                            foreach (var vehicleId in vehicleIds)
                            {
                                DALPackageActivity.InsertPackageActivityVehicleConfig(conn, data.ActivityId, vehicleId);
                            }
                        }
                        if (data.PriceConfig != null && data.PriceConfig.Any())
                        {
                            var priceConfigs = data.PriceConfig;
                            foreach (var priceConfig in priceConfigs)
                            {
                                DALPackageActivity.InsertPackageActivityPriceConfig(conn, data.ActivityId, priceConfig);
                            }
                        }
                        result = true;
                    }
                });
            }
            catch (Exception ex)
            {
                logger.Error(ex);
            }

            if (result)
            {
                data.ProductConfig = new List <PackageActivityProductConfig>();
                data.RoundConfig   = new List <PackageActivityRoundConfig>();
                data.VehicleConfig = new List <PackageActivityVehicleConfig>();
                RecordActivityTypeLog(data.ActivityId, data.StartTime, data.EndTime);
                InsertLog("UpsertPaceageActivityConfig", data.ActivityId.ToString(), JsonConvert.SerializeObject(data), msg, user, LogType);
                Thread.Sleep(2000);
                RefreshPackageBaoYangCache(data.ActivityId);
            }

            return(result);
        }