Пример #1
0
        public ActionResult Manage(string act, string position, int id = 0)
        {
            SWfsBrandAdsInfo      model   = new SWfsBrandAdsInfo();
            SWfsBrandIndexService service = SWfsBrandIndexService.GetInstance();

            ViewBag.Act = act;
            switch (act)
            {
            case "add":    //新建
                model.StartTime = Convert.ToDateTime("1900-1-1");
                model.Position  = Convert.ToInt16(position);
                return(View("/Areas/Shangpin/Views/BrandIndex/ManageAd.cshtml", model));

            case "edit":    //修改
                model = service.GetModel(id);
                return(View("/Areas/Shangpin/Views/BrandIndex/ManageAd.cshtml", model));
            }
            return(View());
        }
Пример #2
0
        public JsonResult ManagerAd()
        {
            string        imgSize             = AppSettingManager.AppSettings["BrandAdPic"].ToString();
            CommonService commonService       = new CommonService();
            Dictionary <string, string> rsPic = new Dictionary <string, string>();
            int                   id          = Convert.ToInt32(Request["ID"]);
            string                position    = Request["Position"];
            string                picUrl      = Request["PicUrl"];
            SWfsBrandAdsInfo      model       = new SWfsBrandAdsInfo();
            SWfsBrandIndexService service     = SWfsBrandIndexService.GetInstance();

            if (id != 0)
            {
                model = service.GetModel(id);
                if (null == model)
                {
                    return(Json(new { reslut = -1, msg = "记录不存在" }));
                }
            }
            string startTime = Request["StartTime"];

            model.AdName = Request["AdName"];
            if (!string.IsNullOrEmpty(picUrl) && !picUrl.StartsWith("http://"))
            {
                return(Json(new { reslut = -1, msg = "图片链接地址格式不正确" }));
            }
            else
            {
                model.PicUrl = picUrl;
            }
            model.Status       = 0;
            model.UpdateDate   = DateTime.Now;
            model.UpdateUserId = PresentationHelper.GetPassport().UserName;
            if (position == "2")
            {
                imgSize = AppSettingManager.AppSettings["BrandAdPic2"].ToString();
            }
            if (id == 0) //创建
            {
                SWfsBrandAdsInfo adInfo = service.GetByTime(startTime, position);
                if (adInfo != null)
                {
                    return(Json(new { reslut = -1, msg = "此运营当前时间已存在数据!" }, "text/plain", Encoding.UTF8));
                }
                model.StartTime = Convert.ToDateTime(startTime);
                model.Position  = Convert.ToInt16(position);
                if (null != Request.Files["PicFile"] && Request.Files["PicFile"].ContentLength > 0)
                {
                    rsPic = commonService.PostImg(Request.Files["PicFile"], imgSize, ".jpg");
                    if (rsPic.Keys.Contains("error"))
                    {
                        return(Json(new { reslut = -1, msg = rsPic["error"] }, "text/plain", Encoding.UTF8));
                    }
                    if (rsPic.Keys.Contains("success"))
                    {
                        model.PicNo = rsPic["success"];
                    }
                }
                else
                {
                    return(Json(new { reslut = -1, msg = "请选择图片" }, "text/plain", Encoding.UTF8));
                }
                try
                {
                    model.CreateUserId = PresentationHelper.GetPassport().UserName;
                    model.CreateDate   = DateTime.Now;
                    service.Add(model);
                    return(Json(new { reslut = 1, msg = "添加成功" }, "text/plain", Encoding.UTF8));
                }
                catch (Exception e)
                {
                    return(Json(new { reslut = 1, msg = e.Message }, "text/plain", Encoding.UTF8));
                }
            }
            else //修改
            {
                if (model.StartTime != Convert.ToDateTime(startTime))
                {
                    SWfsBrandAdsInfo adInfo = service.GetByTime(startTime, position);
                    if (adInfo != null)
                    {
                        return(Json(new { reslut = -1, msg = "此运营位当前时间已存在数据!" }, "text/plain", Encoding.UTF8));
                    }
                }
                if (model.Position.ToString() != position) //说明修改了广告位置
                {
                    if (null == Request.Files["PicFile"] || Request.Files["PicFile"].ContentLength <= 0)
                    {
                        return(Json(new { reslut = -1, msg = "修改广告位置后请重新上传广告图" }));
                    }
                }
                model.StartTime = Convert.ToDateTime(startTime);
                model.Position  = Convert.ToInt16(position);
                if (null != Request.Files["PicFile"] && Request.Files["PicFile"].ContentLength > 0)
                {
                    rsPic = commonService.PostImg(Request.Files["PicFile"], imgSize, ".jpg");
                    if (rsPic.Keys.Contains("error"))
                    {
                        return(Json(new { reslut = -1, msg = rsPic["error"] }, "text/plain", Encoding.UTF8));
                    }
                    if (rsPic.Keys.Contains("success"))
                    {
                        model.PicNo = rsPic["success"];
                    }
                }
                model.ID = id;
                bool rs = service.Update(model);
                return(Json(new { reslut = rs ? 1 : -1, msg = rs ? "修改成功" : "修改失败" }, "text/plain", Encoding.UTF8));
            }
        }