public JsonResult DelAds(int id)
        {
            Ads entity = Ads.Find(Ads._.Id == id);

            if (entity == null)
            {
                tip.Message = "系统找不到本广告!";
                return(Json(tip));
            }

            Core.Admin.WriteLogActions("删除广告(id:" + entity.Id + ");");
            entity.Delete();
            tip.Status  = JsonTip.SUCCESS;
            tip.Message = "删除广告成功";
            return(Json(tip));
        }
        public IActionResult EditAds(int id)
        {
            IList <AdsKind> list = AdsKind.FindAll(null, AdsKind._.Rank.Asc(), null, 0, 0);

            ViewBag.ListKinds = list;

            Ads entity = Ads.Find(Ads._.Id == id);

            if (entity == null)
            {
                return(EchoTipPage("系统找不到本记录!"));
            }

            Core.Admin.WriteLogActions("查看/编辑广告(" + id + ");");

            return(View(entity));
        }
        public IActionResult EditAds(Ads model)
        {
            if (string.IsNullOrEmpty(model.Title))
            {
                tip.Message = "广告标题不能为空!";
                return(Json(tip));
            }
            if (model.Id <= 0)
            {
                tip.Message = "错误参数传递!";
                Json(tip);
            }
            Ads entity = Ads.Find(Ads._.Id == model.Id);

            if (entity == null)
            {
                tip.Message = "系统找不到本记录!";
                return(Json(tip));
            }

            string   content = "";
            DateTime StartTime, EndTime;

            StartTime = Convert.ToDateTime("2000-01-01");
            EndTime   = Convert.ToDateTime("2999-01-01");

            #region 获取数据
            switch (model.TId)
            {
            case 0:    //代码
                ScriptAds script = new ScriptAds();
                script.content = Request.Form["txtScript"];
                if (string.IsNullOrEmpty(script.content))
                {
                    tip.Message = "代码不能为空!";
                    return(Json(tip));
                }
                content = JsonConvert.SerializeObject(script);
                break;

            case 1:    //文字
                TextAds text = new TextAds();
                text.txt   = Request.Form["txt_Txt"];
                text.link  = Request.Form["txt_Link"];
                text.style = Request.Form["txt_Style"];
                if (string.IsNullOrEmpty(text.txt))
                {
                    tip.Message = "文字内容不能为空!";
                    return(Json(tip));
                }
                if (string.IsNullOrEmpty(text.link))
                {
                    tip.Message = "文字链接不能为空!";
                    return(Json(tip));
                }
                content = JsonConvert.SerializeObject(text);
                break;

            case 2:    //图片
                ImgAds img = new ImgAds();
                img.img  = Request.Form["img_Img"];
                img.link = Request.Form["img_Link"];
                img.alt  = Request.Form["img_Alt"];
                string iw = Request.Form["img_Width"];
                string ih = Request.Form["img_Height"];
                if (!string.IsNullOrEmpty(iw) && Utils.IsInt(iw))
                {
                    img.width = int.Parse(iw);
                }
                if (!string.IsNullOrEmpty(ih) && Utils.IsInt(ih))
                {
                    img.height = int.Parse(ih);
                }
                if (string.IsNullOrEmpty(img.img))
                {
                    tip.Message = "图片地址不能为空!";
                    return(Json(tip));
                }
                if (string.IsNullOrEmpty(img.link))
                {
                    tip.Message = "图片链接不能为空!";
                    return(Json(tip));
                }
                content = JsonConvert.SerializeObject(img);
                break;

            case 3:    //Flash
                FlashAds flash = new FlashAds();
                flash.swf = Request.Form["flash_Swf"];
                string fw = Request.Form["flash_Width"];
                string fh = Request.Form["flash_Height"];
                if (string.IsNullOrEmpty(flash.swf))
                {
                    tip.Message = "Flash 地址不能为空!";
                    return(Json(tip));
                }

                if (string.IsNullOrEmpty(fw) || !Utils.IsInt(fw))
                {
                    tip.Message = "Flash 宽度不能为空或者不是整数!";
                    return(Json(tip));
                }
                else
                {
                    flash.width = int.Parse(fw);
                }
                if (string.IsNullOrEmpty(fh) || !Utils.IsInt(fh))
                {
                    tip.Message = "Flash 高度不能为空或者不是整数!";
                    return(Json(tip));
                }
                else
                {
                    flash.height = int.Parse(fh);
                }
                content = JsonConvert.SerializeObject(flash);
                break;

            case 4:    //幻灯片
                string sw = Request.Form["slide_Width"];
                string sh = Request.Form["slide_Height"];
                if (string.IsNullOrEmpty(sw) || !Utils.IsInt(sw))
                {
                    tip.Message = "幻灯片宽度不能为空或者不是整数!";
                    return(Json(tip));
                }
                if (string.IsNullOrEmpty(sh) || !Utils.IsInt(sh))
                {
                    tip.Message = "幻灯片高度不能为空或者不是整数!";
                    return(Json(tip));;
                }
                string[]      arrsimg  = Request.Form["slide_Img"];  // SImg.Split(new string[] { "," }, StringSplitOptions.None);
                string[]      arrslink = Request.Form["slide_Link"]; //SLink.Split(new string[] { "," }, StringSplitOptions.None);
                string[]      arralt   = Request.Form["slide_Alt"];  //SAlt.Split(new string[] { "," }, StringSplitOptions.None);
                List <ImgAds> listimg  = new List <ImgAds>();
                for (int i = 0; i < arrsimg.Length; i++)
                {
                    if (!string.IsNullOrEmpty(arrsimg[i]) && !string.IsNullOrEmpty(arrslink[i]))    //图片跟地址都不为空
                    {
                        ImgAds tplimgads = new ImgAds();
                        tplimgads.img    = arrsimg[i];
                        tplimgads.link   = arrslink[i];
                        tplimgads.height = int.Parse(sh);
                        tplimgads.width  = int.Parse(sw);
                        tplimgads.alt    = arralt[i];
                        listimg.Add(tplimgads);
                    }
                }
                if (listimg == null || listimg.Count <= 0)
                {
                    tip.Message = "幻灯片请至少添加一张图片!";
                    return(Json(tip));;
                }
                content = JsonConvert.SerializeObject(listimg);
                break;

            case 7:    //视频广告
                VideoAds video = new VideoAds();
                video.poster = Request.Form["video_Poster"];
                video.src    = Request.Form["video_Src"];
                video.title  = Request.Form["video_Title"];
                string vw = Request.Form["video_Width"];
                string vh = Request.Form["video_Height"];
                if (!string.IsNullOrEmpty(vw) && Utils.IsInt(vw))
                {
                    video.width = int.Parse(vw);
                }
                if (!string.IsNullOrEmpty(vh) && Utils.IsInt(vh))
                {
                    video.height = int.Parse(vh);
                }
                if (string.IsNullOrEmpty(video.src))
                {
                    tip.Message = "视频广告地址不能为空!";
                    return(Json(tip));
                }
                content = JsonConvert.SerializeObject(video);
                break;
            }
            #endregion

            model.StartTime = StartTime;
            model.EndTime   = EndTime;
            model.Content   = content;
            model.Update();

            tip.Status    = JsonTip.SUCCESS;
            tip.Message   = "编辑广告成功";
            tip.ReturnUrl = "close";

            Core.Admin.WriteLogActions("编辑广告(" + model.Id + ");");
            return(Json(tip));
        }