Ejemplo n.º 1
0
        public ActionResult EditAdvertising(AdvertisingEditModel advertisingEditModel)
        {
            Stream stream = null;
            HttpPostedFileBase uploadImageFileName = Request.Files["UploadImageFileName"];
            Advertising advertising = advertisingService.GetAdvertising(advertisingEditModel.AdvertisingId);
            if (uploadImageFileName != null && !string.IsNullOrEmpty(uploadImageFileName.FileName))
            {
                TenantLogoSettings tenantLogoSettings = TenantLogoSettings.GetRegisteredSettings(TenantTypeIds.Instance().Advertising());
                if (!tenantLogoSettings.ValidateFileLength(uploadImageFileName.ContentLength))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, string.Format("文件大小不允许超过{0}", Formatter.FormatFriendlyFileSize(tenantLogoSettings.MaxLogoLength * 1024)));
                    return View(advertisingEditModel);
                }

                LogoSettings logoSettings = DIContainer.Resolve<ISettingsManager<LogoSettings>>().Get();
                if (!logoSettings.ValidateFileExtensions(uploadImageFileName.FileName))
                {
                    ViewData["StatusMessageData"] = new StatusMessageData(StatusMessageType.Error, "不支持的文件类型,仅支持" + logoSettings.AllowedFileExtensions);
                    return View(advertisingEditModel);
                }

                stream = uploadImageFileName.InputStream;
                advertisingEditModel.UploadImageFileName = uploadImageFileName.FileName;
            }
            else        //当取不到上传的图片文件名时UploadFileName值保持不变
            {
                advertisingEditModel.UploadImageFileName = advertising != null ? advertising.AttachmentUrl : string.Empty;
            }
            var positionIds = advertisingEditModel.PositionIds ?? new List<string>();
            if (advertisingEditModel.AdvertisingId <= 0)
            {

                if (advertisingService.CreateAdvertising(advertisingEditModel.AsAdvertising(), positionIds, stream))
                {
                    return Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Success, "创建广告成功!")));
                }
                return Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Error, "创建广告失败!")));
            }
            advertisingService.UpdateAdvertising(advertisingEditModel.AsAdvertising(), positionIds, stream);
            return Content(System.Web.Helpers.Json.Encode(new StatusMessageData(StatusMessageType.Success, "编辑广告成功!")));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 转化为EditModel
        /// </summary>
        /// <param name="advertising"></param>
        /// <returns></returns>
        public static AdvertisingEditModel AsEditModel(this Advertising advertising)
        {
            AdvertisingEditModel editModel = new AdvertisingEditModel();

            editModel.AdvertisingId   = advertising.AdvertisingId;
            editModel.AdvertisingType = advertising.AdvertisingType;
            editModel.DisplayOrder    = advertising.DisplayOrder;
            editModel.EndDate         = advertising.EndDate;
            editModel.IsEnable        = advertising.IsEnable;
            editModel.LastModified    = advertising.LastModified;
            editModel.Name            = advertising.Name ?? string.Empty;
            editModel.StartDate       = advertising.StartDate;
            editModel.TextStyle       = advertising.TextStyle;
            editModel.PositionIds     = new AdvertisingService().GetPositionsByAdvertisingId(advertising.AdvertisingId).Select(n => n.PositionId);
            switch (advertising.AdvertisingType)
            {
            case AdvertisingType.Image:
            {
                //判断链接不以http和https开头,则为上传图片
                if (!advertising.AttachmentUrl.StartsWith("http://") && !advertising.AttachmentUrl.StartsWith("https://"))
                {
                    editModel.isUploadImage       = true;
                    editModel.UploadImageFileName = advertising.AttachmentUrl;
                    editModel.NetImageUrl         = string.Empty;
                }
                else
                {
                    editModel.isUploadImage       = false;
                    editModel.NetImageUrl         = advertising.AttachmentUrl;
                    editModel.UploadImageFileName = string.Empty;
                }
                editModel.ImageWidth     = advertising.Width;
                editModel.ImageHeight    = advertising.Height;
                editModel.IsImageBlank   = advertising.IsBlank;
                editModel.IsTextBlank    = true;
                editModel.ImageLinkedUrl = advertising.Url;
                editModel.TextContent    = string.Empty;
                editModel.ScriptContent  = string.Empty;
                editModel.TextLinkedUrl  = string.Empty;
                editModel.FlashUrl       = string.Empty;
            }
            break;

            case AdvertisingType.Script:
            {
                editModel.IsImageBlank        = true;
                editModel.IsTextBlank         = true;
                editModel.isUploadImage       = true;
                editModel.UploadImageFileName = string.Empty;
                editModel.NetImageUrl         = string.Empty;
                editModel.ImageLinkedUrl      = string.Empty;
                editModel.TextContent         = string.Empty;
                editModel.ScriptContent       = advertising.Body;
                editModel.TextLinkedUrl       = string.Empty;
                editModel.FlashUrl            = string.Empty;
            }
            break;

            case AdvertisingType.Flash:
            {
                editModel.IsImageBlank        = true;
                editModel.IsTextBlank         = true;
                editModel.isUploadImage       = true;
                editModel.UploadImageFileName = string.Empty;
                editModel.NetImageUrl         = string.Empty;
                editModel.ImageLinkedUrl      = string.Empty;
                editModel.TextContent         = string.Empty;
                editModel.ScriptContent       = advertising.Body;
                editModel.TextLinkedUrl       = string.Empty;
                editModel.FlashUrl            = advertising.AttachmentUrl;
                editModel.FlashWidth          = advertising.Width;
                editModel.FlashHeight         = advertising.Height;
            }
            break;

            case AdvertisingType.Text:
            {
                editModel.IsImageBlank        = true;
                editModel.IsTextBlank         = advertising.IsBlank;
                editModel.isUploadImage       = true;
                editModel.UploadImageFileName = string.Empty;
                editModel.NetImageUrl         = string.Empty;
                editModel.ImageLinkedUrl      = string.Empty;
                editModel.TextContent         = advertising.Body;
                editModel.TextLinkedUrl       = advertising.Url;
                editModel.ScriptContent       = string.Empty;
                editModel.FlashUrl            = string.Empty;
            }
            break;
            }

            return(editModel);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 转化为EditModel
        /// </summary>
        /// <param name="advertising"></param>
        /// <returns></returns>
        public static AdvertisingEditModel AsEditModel(this Advertising advertising)
        {
            AdvertisingEditModel editModel = new AdvertisingEditModel();
            editModel.AdvertisingId = advertising.AdvertisingId;
            editModel.AdvertisingType = advertising.AdvertisingType;
            editModel.DisplayOrder = advertising.DisplayOrder;
            editModel.EndDate = advertising.EndDate;
            editModel.IsEnable = advertising.IsEnable;
            editModel.LastModified = advertising.LastModified;
            editModel.Name = advertising.Name ?? string.Empty;
            editModel.StartDate = advertising.StartDate;
            editModel.TextStyle = advertising.TextStyle;
            editModel.PositionIds = new AdvertisingService().GetPositionsByAdvertisingId(advertising.AdvertisingId).Select(n => n.PositionId);
            switch (advertising.AdvertisingType)
            {
                case AdvertisingType.Image:
                    {
                        //判断链接不以http和https开头,则为上传图片
                        if (!advertising.AttachmentUrl.StartsWith("http://") && !advertising.AttachmentUrl.StartsWith("https://"))
                        {
                            editModel.isUploadImage = true;
                            editModel.UploadImageFileName = advertising.AttachmentUrl;
                            editModel.NetImageUrl = string.Empty;
                        }
                        else
                        {
                            editModel.isUploadImage = false;
                            editModel.NetImageUrl = advertising.AttachmentUrl;
                            editModel.UploadImageFileName = string.Empty;
                        }
                        editModel.ImageWidth = advertising.Width;
                        editModel.ImageHeight = advertising.Height;
                        editModel.IsImageBlank = advertising.IsBlank;
                        editModel.IsTextBlank = true;
                        editModel.ImageLinkedUrl = advertising.Url;
                        editModel.TextContent = string.Empty;
                        editModel.ScriptContent = string.Empty;
                        editModel.TextLinkedUrl = string.Empty;
                        editModel.FlashUrl = string.Empty;
                    }
                    break;
                case AdvertisingType.Script:
                    {
                        editModel.IsImageBlank = true;
                        editModel.IsTextBlank = true;
                        editModel.isUploadImage = true;
                        editModel.UploadImageFileName = string.Empty;
                        editModel.NetImageUrl = string.Empty;
                        editModel.ImageLinkedUrl = string.Empty;
                        editModel.TextContent = string.Empty;
                        editModel.ScriptContent = advertising.Body;
                        editModel.TextLinkedUrl = string.Empty;
                        editModel.FlashUrl = string.Empty;
                    }
                    break;
                case AdvertisingType.Flash:
                    {
                        editModel.IsImageBlank = true;
                        editModel.IsTextBlank = true;
                        editModel.isUploadImage = true;
                        editModel.UploadImageFileName = string.Empty;
                        editModel.NetImageUrl = string.Empty;
                        editModel.ImageLinkedUrl = string.Empty;
                        editModel.TextContent = string.Empty;
                        editModel.ScriptContent = advertising.Body;
                        editModel.TextLinkedUrl = string.Empty;
                        editModel.FlashUrl = advertising.AttachmentUrl;
                        editModel.FlashWidth = advertising.Width;
                        editModel.FlashHeight = advertising.Height;
                    }
                    break;
                case AdvertisingType.Text:
                    {
                        editModel.IsImageBlank = true;
                        editModel.IsTextBlank = advertising.IsBlank;
                        editModel.isUploadImage = true;
                        editModel.UploadImageFileName = string.Empty;
                        editModel.NetImageUrl = string.Empty;
                        editModel.ImageLinkedUrl = string.Empty;
                        editModel.TextContent = advertising.Body;
                        editModel.TextLinkedUrl = advertising.Url;
                        editModel.ScriptContent = string.Empty;
                        editModel.FlashUrl = string.Empty;
                    }
                    break;
            }

            return editModel;
        }