Exemple #1
0
        /// <summary>
        /// 新增/复制/编辑广告
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult AddAdvertisingConfig(AdvertisingConfigModel model)
        {
            var manager = new AdvertisingConfigManager();

            if (!string.IsNullOrEmpty(model.StartVersion))
            {
                Version startVersion;
                if (!Version.TryParse(model.StartVersion, out startVersion))
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        state = "failure",
                        message = "开始版本的类型有误",
                        data = ""
                    })));
                }
            }
            if (!string.IsNullOrEmpty(model.EndVersion))
            {
                Version endVersion;
                if (!Version.TryParse(model.EndVersion, out endVersion))
                {
                    return(Content(JsonConvert.SerializeObject(new
                    {
                        state = "failure",
                        message = "结束版本的类型有误",
                        data = ""
                    })));
                }
            }
            //根据区域信息和产品线判断配置是否存在
            var exsitConfigInfo = manager.GetAdvertisingConfigInfo(model.ProvinceID, model.CityID, model.ProductLine, model.AdType);

            if (exsitConfigInfo != null && exsitConfigInfo.PKID != model.PKID)
            {
                exsitConfigInfo.Status = 0;//禁用
                manager.UpdateAdvertisingConfig(exsitConfigInfo);
                #region 日志记录
                using (var client = new ConfigLogClient())
                {
                    var response = client.InsertDefaultLogQueue("CommonConfigLog", JsonConvert.SerializeObject(new
                    {
                        ObjectId    = model.PKID,
                        ObjectType  = "AdvertisingConfig",
                        BeforeValue = "",
                        AfterValue  = JsonConvert.SerializeObject(exsitConfigInfo),
                        Remark      = "禁用广告配置",
                        Creator     = User.Identity.Name,
                    }));
                }
                #endregion
            }
            //新增
            if (model.PKID == 0)
            {
                model.AdLocation = 1;//下单完成页
                model.Status     = 1;
                model.Creator    = User.Identity.Name;
                manager.AddAdvertisingConfig(model);
                #region 日志记录
                using (var client = new ConfigLogClient())
                {
                    var response = client.InsertDefaultLogQueue("CommonConfigLog", JsonConvert.SerializeObject(new
                    {
                        ObjectId    = model.PKID,
                        ObjectType  = "AdvertisingConfig",
                        BeforeValue = "",
                        AfterValue  = JsonConvert.SerializeObject(model),
                        Remark      = "新增广告配置",
                        Creator     = User.Identity.Name,
                    }));
                }
                #endregion
            }
            //编辑
            else
            {
                var configInfo = manager.GetAdvertisingConfigInfo(model.PKID);
                model.AdLocation = configInfo.AdLocation;; //下单完成页
                model.Status     = 1;                      //启用
                model.Creator    = configInfo.Creator;
                manager.UpdateAdvertisingConfig(model);
                #region 日志记录
                using (var client = new ConfigLogClient())
                {
                    var response = client.InsertDefaultLogQueue("CommonConfigLog", JsonConvert.SerializeObject(new
                    {
                        ObjectId    = model.PKID,
                        ObjectType  = "AdvertisingConfig",
                        BeforeValue = JsonConvert.SerializeObject(configInfo),
                        AfterValue  = JsonConvert.SerializeObject(model),
                        Remark      = "修改广告配置",
                        Creator     = User.Identity.Name,
                    }));
                }
                #endregion
            }
            //等待1秒,写库同步到读库
            Thread.Sleep(1000);
            return(Content(JsonConvert.SerializeObject(new
            {
                state = "success",
                message = "操作成功",
                data = ""
            })));
        }