示例#1
0
        /// <summary>
        /// 获取单个浮动设置模型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BaoYangResultEntity <CouponActivityConfigV2Model> GetCouponActivityConfig(int id)
        {
            var result = new BaoYangResultEntity <CouponActivityConfigV2Model>()
            {
                Status = false
            };

            try
            {
                dbScopeManagerConfigurationRead.Execute(conn =>
                {
                    var config = DalCouponActivityConfigV2.GetCouponActivityConfigById(conn, id);
                    if (config == null)
                    {
                        result.Status = true;
                        result.Msg    = "没有查询到数据";
                    }
                    else
                    {
                        config.ChannelConfigs = DalCouponActivityConfigV2.GetChannelConfigs(conn, config.Id, string.Empty);
                        result.Status         = true;
                        result.Data           = config;
                    }
                });
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.Msg    = "程序遇见错误,请联系管理员";
                Logger.Error("GetCouponActivityConfigs", ex);
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// 修改蓄电池/加油卡浮动配置
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BaoYangResultEntity <bool> UpdateCouponActivityConfig(CouponActivityConfigV2Model configModel, string name)
        {
            var result = new BaoYangResultEntity <bool>()
            {
                Status = false
            };

            try
            {
                var oldModel = GetCouponActivityConfig(configModel.Id).Data;
                dbScopeManagerConfiguration.CreateTransaction(conn =>
                {
                    if (DalCouponActivityConfigV2.UpdateCouponActivityConfig(conn, configModel))
                    {
                        if (configModel.ChannelConfigs != null && configModel.ChannelConfigs.Any())
                        {
                            var configIds = new List <int> {
                                configModel.Id
                            };
                            DalCouponActivityConfigV2.DeleteChannelConfigsByConfigId(conn, configIds);
                            foreach (var item in configModel.ChannelConfigs)
                            {
                                DalCouponActivityConfigV2.InsertChannelConfigsById(conn, item);
                            }

                            result.Status = true;
                            result.Data   = true;
                        }
                        else
                        {
                            result.Status = true;
                            result.Data   = true;
                        }
                    }
                    else
                    {
                        result.Data = false;
                    }
                });
                if (result.Status)
                {
                    SaveCouponActivityConfigLog(oldModel, configModel, name);
                }
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.Msg    = "程序遇见错误,请联系管理员";
                Logger.Error("GetCouponActivityConfigs", ex);
            }
            return(result);
        }
示例#3
0
        /// <summary>
        /// 添加蓄电池/加油卡浮动配置
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BaoYangResultEntity <bool> InsertCouponActivityConfig(CouponActivityConfigV2Model request, string name)
        {
            var result = new BaoYangResultEntity <bool>()
            {
                Status = false
            };

            try
            {
                dbScopeManagerConfiguration.CreateTransaction(conn =>
                {
                    request.ActivityNum = Guid.NewGuid().ToString();
                    var configId        = DalCouponActivityConfigV2.InsertCouponActivityConfig(conn, request);
                    if (configId > 0)
                    {
                        if (request.ChannelConfigs != null && request.ChannelConfigs.Any())
                        {
                            foreach (var item in request.ChannelConfigs)
                            {
                                item.ConfigId = configId;
                                DalCouponActivityConfigV2.InsertChannelConfigsById(conn, item);
                            }
                        }
                        result.Status = true;
                        result.Data   = true;
                        request.Id    = configId;
                    }
                    else
                    {
                        result.Data = false;
                    }
                });
                if (result.Status)
                {
                    SaveCouponActivityConfigLog(null, request, name);
                }
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.Msg    = "程序遇见错误,请联系管理员";
                Logger.Error("GetCouponActivityConfigs", ex);
            }

            return(result);
        }
示例#4
0
        /// <summary>
        /// 获取蓄电池/加油卡浮动配置分页列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public BaoYangResultEntity <Tuple <int, List <CouponActivityConfigV2Model> > > GetCouponActivityConfigs(CouponActivityConfigPageRequestModel request)
        {
            var result = new BaoYangResultEntity <Tuple <int, List <CouponActivityConfigV2Model> > >()
            {
                Status = false
            };

            try
            {
                dbScopeManagerConfigurationRead.Execute(conn =>
                {
                    var tupleConfigs = DalCouponActivityConfigV2.GetCouponActivityConfigs(conn, request);
                    if (tupleConfigs == null || !tupleConfigs.Item2.Any() || tupleConfigs.Item1 <= 0)
                    {
                        result.Status = true;
                        result.Msg    = "未查找到数据";
                    }
                    else
                    {
                        var ChannelConfigs   = DalCouponActivityConfigV2.GetChannelConfigs(conn, tupleConfigs.Item2.Select(x => x.Id).ToList());
                        var ChannelConfigDic = ChannelConfigs.GroupBy(x => x.ConfigId).Select(x => new { x.Key, x }).ToDictionary(k => k.Key, v => v.x);
                        foreach (var item in tupleConfigs.Item2)
                        {
                            item.Channels = item.Channel == null ? new List <string>() : item.Channel.Split(',').ToList();
                            if (ChannelConfigDic.ContainsKey(item.Id))
                            {
                                item.ChannelConfigs = ChannelConfigDic[item.Id].ToList();
                            }
                        }
                        result.Status = true;
                        result.Data   = tupleConfigs;
                    }
                });
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.Msg    = "程序遇见错误,请联系管理员";
                Logger.Error("GetCouponActivityConfigs", ex);
            }
            return(result);
        }
示例#5
0
        /// <summary>
        /// 根据ID 删除单个模型
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <BaoYangResultEntity <bool> > DeleteChannelConfigsByConfigId(int id, string name)
        {
            var result = new BaoYangResultEntity <bool>()
            {
                Status = false
            };

            try
            {
                var oldModel = GetCouponActivityConfig(id).Data;
                await RemoveCouponActivityConfigCache(id);

                dbScopeManagerConfiguration.CreateTransaction(conn =>
                {
                    if (DalCouponActivityConfigV2.DeleteCouponActivityConfig(conn, id))
                    {
                        var configIds = new List <int> {
                            id
                        };
                        result.Data   = DalCouponActivityConfigV2.DeleteChannelConfigsByConfigId(conn, configIds);
                        result.Status = true;
                        result.Data   = true;
                    }
                    else
                    {
                        result.Data = false;
                    }
                });
                if (result.Status && oldModel != null)
                {
                    SaveCouponActivityConfigLog(oldModel, null, name);
                }
            }
            catch (Exception ex)
            {
                result.Status = false;
                result.Msg    = "程序遇见错误,请联系管理员";
                Logger.Error("GetCouponActivityConfigs", ex);
            }
            return(result);
        }