/// <summary> /// 設定右側廣告Card /// </summary> /// <param name="datas"></param> /// <param name="item"></param> /// <param name="Position"></param> private void SetRightSideAdCard(List <ZonesModels> datas, AdvertisementRenderIndex item, int Position, string TargetDataType) { foreach (var zone in datas) { long cardNo = AdvertisementRenderTools.QueryCardNoByZoneNoAndTypeStr(zone.No, TargetDataType); if (cardNo != 0) { ZonesModels zonemodel = GenZoneModel(item, Position); CardsModels cardmodel = AdvertisementRenderTools.GenCard(zonemodel).FirstOrDefault(); if (zone.CardsModels == null) { zone.CardsModels = new List <CardsModels>(); } zone.CardsModels.Add(cardmodel); zone.StyleID = 9; break; } } }
/// <summary> /// 根據DataType調整ads主檔內容 /// For 單一DataType 多個廣告位置設定 /// </summary> /// <param name="ads"></param> private void RenderWithDataType(ref IEnumerable <AdvertisementRenderIndex> ads) { if (string.IsNullOrWhiteSpace(_DataType)) { return; } if (ads == null) { return; } switch (_DataType) { case WorkV3.Areas.Backend.Models.AreaSetDataType.Article: if (AdvertisementRenderTools.CheckPostitionIsChild(_PageNo)) { // 20180703 neil 因廣告區選擇已由主從式架構改為獨立選擇,所以移除 parentAreaSetID 部份 if (ads.Any(m => m.AreaSetChildType == WorkV3.Areas.Backend.Models.ChildType.Inside)) { ads = ads.Where(m => m.AreaSetChildType == WorkV3.Areas.Backend.Models.ChildType.Inside); return; } } else { ads = ads.Where(m => m.AreaSetChildType == ""); } break; case WorkV3.Areas.Backend.Models.AreaSetDataType.Event: if (AdvertisementRenderTools.CheckPostitionIsChild(_PageNo)) { if (ads.Any(m => m.AreaSetChildType == WorkV3.Areas.Backend.Models.ChildType.Inside)) { ads = ads.Where(m => m.AreaSetChildType == WorkV3.Areas.Backend.Models.ChildType.Inside); return; } } else { ads = ads.Where(m => m.AreaSetChildType == ""); } break; case WorkV3.Areas.Backend.Models.AreaSetDataType.Member: string sn = AdvertisementRenderTools.QueryPageSNByPageNo(_PageNo); if (!string.IsNullOrWhiteSpace(sn) && AdvertisementRenderTools.CheckChildTypeIsExist(sn)) { //會員位置設定中, 當dbo.ChildType = null, 代表存會員主頁。在dbo.Pages當中, 會員主頁的SN為Desktop //所以不是Desktop才需要去讀取ChildType部分 if (sn != WorkV3.Areas.Backend.Models.ChildType.Desktop) { ads = ads.Where(m => m.AreaSetChildType == WorkV3.Areas.Backend.Models.ChildType.Login); return; } else { ads = ads.Where(m => m.AreaSetChildType == ""); } } else { ads = new List <AdvertisementRenderIndex>(); } break; } //ads = ads.Any(m => m.ParentAreaSetID == null) ? ads.Where(m => m.ParentAreaSetID == null) : ads; }
/// <summary> /// 插入廣告Zone /// </summary> /// <param name="datas"></param> /// <returns></returns> public List <ZonesModels> InsertAdsZones(List <ZonesModels> datas) { // 備份 var bk = datas; if (string.IsNullOrEmpty(_DataType)) { return(bk); } //排序原有資料的Sort 並且和TempSort同步 datas = datas.OrderBy(m => m.Sort).ToList(); for (int i = 0; i < datas.Count; i++) { datas[i].TempSort = i + 1; } //取得廣告區主檔資訊 IEnumerable <AdvertisementRenderIndex> ads = AdvertisementRenderTools.GetAdvertisementRender(_MenuID); //根據DataType調整ads主檔內容 RenderWithDataType(ref ads); foreach (var item in ads) { int Position; //參考點 (同indexStr) string align; //位置代碼 ex: C or R or A string indexStr = AdvertisementRenderTools.GetPositionIndex(item.GroupPosition, _DataType); #region 檢查資料 align = indexStr.Substring(0, 1); if (!string.IsNullOrWhiteSpace(indexStr)) { indexStr = indexStr.Substring(1); //去位置代碼 } else { continue; } if (!int.TryParse(indexStr, out Position)) { continue; } #endregion //20180509 上下橫幅的部分 Zone的StyleID要用6 if (item.GroupPosition == DisplayAreaShardType.Top || item.GroupPosition == DisplayAreaShardType.Bottom) { _StyleID = 6; } switch (_DataType) { case WorkV3.Areas.Backend.Models.DataType.Intro: //首頁 if (Position == 3 || Position == 8) { if (Position == 3) { datas.Insert(0, GenZoneModel(item, Position)); } else if (Position == 8) { datas.Insert(0, GenZoneModel(item, datas.Count >= 2 ? datas.Count - 2 : 0)); } AdjustmentSort(datas, datas.Count >= 2 ? datas.Count - 2 : Position); continue; } break; case WorkV3.Areas.Backend.Models.DataType.Event: //活動 if (align == "R") //右側廣告 { SetRightSideAdCard(datas, item, Position, WorkV3.Areas.Backend.Models.DataType.Event); continue; } break; case WorkV3.Areas.Backend.Models.DataType.Article: //文章 if (align == "R") //右側廣告 { SetRightSideAdCard(datas, item, Position, WorkV3.Areas.Backend.Models.DataType.Article); continue; } break; case WorkV3.Areas.Backend.Models.DataType.ArticleIntro: //單頁 if (align == "R") //右側廣告 { SetRightSideAdCard(datas, item, Position, WorkV3.Areas.Backend.Models.DataType.ArticleIntro); continue; } //if (Position == 4 || Position == 8) //{ // if (Position == 4) // datas.Insert(0, GenZoneModel(item, Position)); // else if (Position == 8) // datas.Insert(0, GenZoneModel(item, datas.Count >= 2 ? datas.Count - 2 : 0)); // AdjustmentSort(datas, datas.Count >= 2 ? datas.Count - 2 : Position); // continue; //} break; } double enterIndex = SetReferencePoint(datas, Position); datas.Insert(0, GenZoneModel(item, enterIndex)); AdjustmentSort(datas, enterIndex, Position); } datas = datas.OrderBy(m => m.TempSort).ToList(); return(datas); }