/// <summary> /// 事件处理方法 /// </summary> /// <param name="eventSource">事件源</param> public void Handle(PackShelvedChangedEvent eventSource) { DecorationPack currentPack = this._unitOfWork.Resolve <DecorationPack>(eventSource.PackId); #region # 处理套餐 //套餐下所有选区(选区1,选区2……) IEnumerable <DecorationPackItem> items = this._repMediator.DecorationPackItemRep.FindByPack(eventSource.PackId, null); //this._unitOfWork.ResolvePackItemsByPack(eventSource.PackId); //所有工艺和商品是否都没变价 if (items.All(x => x.AllSkuNoChanged && x.AllCraftNoChanged)) { currentPack.SetHasChangedSku(false); } else { currentPack.SetHasChangedSku(true); } //所有工艺和商品是否都上架 if (items.All(x => x.AllSkuShelved && x.AllCraftShelved)) { currentPack.SetHasOffShelvedSku(false); } else { currentPack.SetHasOffShelvedSku(true); } this._unitOfWork.RegisterSave(currentPack); #endregion this._unitOfWork.Commit(); }
/// <summary> /// 事件处理方法 /// </summary> /// <param name="eventSource">事件源</param> public void Handle(PackSkuChangedEvent eventSource) { DecorationPack currentPack = this._unitOfWork.Resolve <DecorationPack>(eventSource.PackId); //变价 if (eventSource.Changed) { currentPack.SetHasChangedSku(true); this._unitOfWork.RegisterSave(currentPack); } else { //未变价 IEnumerable <DecorationPackItem> packItems = //this._unitOfWork.ResolvePackItemsByPack(eventSource.PackId); this._repMediator.DecorationPackItemRep.FindByPack(eventSource.PackId, null); //所有工艺和商品是否都没变价 if (packItems.All(x => x.AllSkuNoChanged && x.AllCraftNoChanged)) { currentPack.SetHasChangedSku(false); this._unitOfWork.RegisterSave(currentPack); } } this._unitOfWork.Commit(); }
/// <summary> /// 套餐模板项映射 /// </summary> /// <param name="packItem">套餐模板项领域模型</param> /// <param name="packs">套餐模板字典</param> /// <returns>套餐模板项数据传输对象</returns> public static DecorationPackItemInfo ToDTO(this DecorationPackItem packItem, IDictionary <Guid, DecorationPack> packs) { DecorationPackItemInfo packItemInfo = Transform <DecorationPackItem, DecorationPackItemInfo> .Map(packItem); DecorationPack pack = packs[packItem.PackId]; packItemInfo.DecorationPackInfo = pack.ToDTO(new List <DecorationPackScheme>()); packItemInfo.PackSpaceName = pack.Spaces.Single(x => x.Id == packItem.PackSpaceId).Name; return(packItemInfo); }
/// <summary> /// 事件处理方法 /// </summary> /// <param name="eventSource">事件源</param> public void Handle(PackSkuShelvedEvent eventSource) { DecorationPack currentPack = this._unitOfWork.Resolve <DecorationPack>(eventSource.PackId); //下架 if (!eventSource.Shelved) { currentPack.SetHasOffShelvedSku(true); this._unitOfWork.RegisterSave(currentPack); } //上架 else { IEnumerable <DecorationPackItem> packItems = this._repMediator.DecorationPackItemRep.FindByPack(eventSource.PackId, null); //所有工艺和商品是否都上架 if (packItems.All(x => x.AllSkuShelved && x.AllCraftShelved)) { currentPack.SetHasOffShelvedSku(false); this._unitOfWork.RegisterSave(currentPack); } } this._unitOfWork.Commit(); }
/// <summary> /// 套餐模板映射 /// </summary> /// <param name="pack">套餐模板领域模型</param> /// <param name="packSchemes">套餐默认方案集</param> /// <returns>套餐模板数据传输对象</returns> public static App_DecorationPackInfo ToAppDTO(this DecorationPack pack, List <DecorationPackScheme> packSchemes) { DecorationPackScheme packScheme = packSchemes.SingleOrDefault(x => x.PackId == pack.Id); App_DecorationPackInfo packInfo = new App_DecorationPackInfo { Sort = (int)pack.Sort, Name = pack.Name, AddedTime = pack.AddedTime, BuildingSquare = pack.BuildingSquare, BuildingTotalPrice = pack.BuildingTotalPrice, BuildingUnitPrice = pack.BuildingUnitPrice, UnitPrice = pack.UnitPrice, Id = pack.Id, PackSeries = pack.PackSeries.Select(s => s.Name), PackSerieInfos = pack.PackSeries.ToDictionary(x => x.Name, x => x.Describe), Layouts = pack.Layouts, Color = pack.Color, //默认方案信息 Cover = packScheme != null ? packScheme.Cover : null, CoverDescription = packScheme != null ? packScheme.Description : null, SchemeImages = packScheme != null ? packScheme.Images : new List <string>(), SchemeDescriptions = packScheme != null?packScheme.SchemeDescriptions.ToList() : null, SchemeVideoAudioLink = packScheme != null ? packScheme.VideoAudioLink : null, SchemeVideoAudioLinkFileId = packScheme != null ? packScheme.VideoAudioFileId : null, CriterionSquare = pack.CriterionSquare, Instructions = pack.Instructions, InstructionsName = pack.InstructionsName, IsActual = pack.IsActual, IsBuilding = pack.IsBuilding, IsUnitActual = pack.IsUnitActual, IsUnitBuilding = pack.IsUnitBuilding, IsWhole = pack.IsWhole, MaxApplicableSquare = pack.MaxApplicableSquare, MinApplicableSquare = pack.MinApplicableSquare, NewHouse = pack.NewHouse, Number = pack.Number, PackKind = pack.PackKind, PackMode = pack.PackMode, PackType = pack.PackType, Premium = pack.Premium, Priced = pack.Priced, PricingType = pack.PricingType, Sales = pack.Sales, SecondHandHouse = pack.SecondHandHouse, SpaceInfos = pack.SpaceInfos, Square = pack.Square, StyleNos = pack.StyleNos, TotalPrice = pack.TotalPrice, UnitBuildingSquare = pack.UnitBuildingSquare, UnitBuildingTotalPrice = pack.UnitBuildingTotalPrice, UnitSquare = pack.UnitSquare, UnitTotalPrice = pack.UnitTotalPrice, Views = pack.Views, Propertys = pack.Propertys, Status = pack.Status, IsManageFee = pack.IsManageFee, IsWaterElectricityFee = pack.IsWaterElectricityFee, ManageFee = pack.ManageFee, WaterElectricityFee = pack.WaterElectricityFee }; return(packInfo); }
/// <summary> /// 克隆套餐模板 /// </summary> /// <param name="sourcePackId">源套餐模板Id</param> /// <returns>新套餐模板Id</returns> private void CloneDecorationPack(Guid sourcePackId) { DecorationPack sourcePack = this._repMediator.DecorationPackRep.Single(sourcePackId); //套餐模板名称,版本号 string version = this._svcMediator.NumberSvc.GeneratePackVersionNo(sourcePack.Id, "Decoration"); //string packName = "备份套餐【" + sourcePack.Name + "】" + version; //验证 //Assert.IsFalse(this._repMediator.DecorationPackRep.ExistsName(packName), "套餐模板名称已存在!"); //注:此处代码是为了将导航属性加载出来 Trace.WriteLine(sourcePack.Spaces.Count); //注:此处代码是为了将导航属性加载出来 foreach (DecorationPackSpace space in sourcePack.Spaces) { //注:此处代码是为了将导航属性加载出来 Trace.WriteLine(space.SpaceDetails.Count); } //声明套餐模板副本Id Guid clonedPackId = Guid.NewGuid(); //声明套餐模板空间Id映射关系字典 IDictionary <Guid, Guid> spaceMaps = new Dictionary <Guid, Guid>(); #region # 克隆套餐模板、套餐模板空间;设置源套餐Id,版本号;修改套餐名称; DecorationPack clonedPack = sourcePack.Clone <DecorationPack>(); clonedPack.SetId(clonedPackId); //clonedPack.UpdateInfo(sourcePack.Name); clonedPack.SetSourcePackIdAndVersion(sourcePackId, version, true); var cloneArticles = new List <Article>(); var packArticles = this._repMediator.ArticleRepository.GetArticlesByPackId(sourcePackId).ToList(); foreach (var article in packArticles.Where(s => s.SpaceId == null)) { Article cloneArticle = article.Clone <Article>(); cloneArticle.SetId(Guid.NewGuid()); cloneArticle.SetPackId(clonedPackId); cloneArticles.Add(cloneArticle); } //套餐模板空间Id重新赋值 foreach (DecorationPackSpace space in clonedPack.Spaces) { Guid newPackSpaceId = Guid.NewGuid(); spaceMaps.Add(space.Id, newPackSpaceId); space.SetId(newPackSpaceId); foreach (DecorationPackSpaceDetail spaceDetail in space.SpaceDetails) { spaceDetail.SetId(Guid.NewGuid()); } var spaceArticles = packArticles.Where(s => s.SpaceId == space.Id); foreach (var spaceArticle in spaceArticles) { Article cloneArticle = spaceArticle.Clone <Article>(); cloneArticle.SetId(Guid.NewGuid()); cloneArticle.SetPackId(clonedPackId); cloneArticles.Add(cloneArticle); } } this._unitOfWork.RegisterAdd(clonedPack); if (cloneArticles.Any()) { this._unitOfWork.RegisterAddRange(cloneArticles); } #endregion #region # 克隆套餐模板项 //IEnumerable<DecorationPackItem> packItems = this._repMediator.DecorationPackItemRep.FindByPack(sourcePackId, null); IEnumerable <DecorationPackItem> packItems = this._unitOfWork.GetItemsByPackSku(sourcePackId); foreach (DecorationPackItem packItem in packItems) { //注:此处代码是为了将导航属性加载出来 //Trace.WriteLine(packItem.PackSkus.Count); //Trace.WriteLine(packItem.PackCraftEntities.Count); //克隆套餐模板项 DecorationPackItem clonedPackItem = packItem.Clone <DecorationPackItem>(); clonedPackItem.SetId(Guid.NewGuid()); clonedPackItem.SetPackId(clonedPackId); clonedPackItem.SetPackSpaceId(spaceMaps[clonedPackItem.PackSpaceId]); clonedPackItem.SetIsClone(); //重新为Id赋值 foreach (DecorationPackSku packSku in clonedPackItem.PackSkus) { packSku.SetId(Guid.NewGuid()); } foreach (DecorationPackCraft packCraft in clonedPackItem.PackCraftEntities) { packCraft.SetId(Guid.NewGuid()); } this._unitOfWork.RegisterAdd(clonedPackItem); } #endregion #region # 克隆套餐模板推荐项 //IEnumerable<DecorationPackItem> packItems = this._repMediator.DecorationPackItemRep.FindByPack(sourcePackId, null); IEnumerable <DecorationPackRecommendedItem> packRecommendedItems = this._unitOfWork.GetRecommendedItemsByPack(sourcePackId); foreach (DecorationPackRecommendedItem packRecommendedItem in packRecommendedItems) { //注:此处代码是为了将导航属性加载出来 //Trace.WriteLine(packItem.PackSkus.Count); //Trace.WriteLine(packItem.PackCraftEntities.Count); //克隆套餐模板项 DecorationPackRecommendedItem clonedPackRecommendedItem = packRecommendedItem.Clone <DecorationPackRecommendedItem>(); clonedPackRecommendedItem.SetId(Guid.NewGuid()); clonedPackRecommendedItem.SetPackId(clonedPackId); clonedPackRecommendedItem.SetPackSpaceId(spaceMaps[clonedPackRecommendedItem.PackSpaceId]); clonedPackRecommendedItem.SetIsClone(); //重新为Id赋值 foreach (DecorationPackRecommendedSku packSku in clonedPackRecommendedItem.PackRecommendedSkus) { packSku.SetId(Guid.NewGuid()); } this._unitOfWork.RegisterAdd(clonedPackRecommendedItem); } #endregion #region # 克隆套餐模板方案 IEnumerable <DecorationPackScheme> packSchemes = this._repMediator.DecorationPackSchemeRep.FindByPack(sourcePackId); foreach (DecorationPackScheme packScheme in packSchemes) { //注:此处代码是为了将导航属性加载出来 Trace.WriteLine(packScheme.SchemeSpaces.Count); //克隆套餐模板方案 DecorationPackScheme clonedPackScheme = packScheme.Clone <DecorationPackScheme>(); clonedPackScheme.SetId(Guid.NewGuid()); clonedPackScheme.SetPackId(clonedPackId); foreach (DecorationPackSchemeSpace schemeSpace in clonedPackScheme.SchemeSpaces) { schemeSpace.SetId(Guid.NewGuid()); schemeSpace.SetPackSpaceId(spaceMaps[schemeSpace.PackSpaceId]); } this._unitOfWork.RegisterAdd(clonedPackScheme); } #endregion #region # 克隆套餐关联大包/定制 IEnumerable <DecorationPack_BalePack> decorationPackBalePacks = this._repMediator.DecorationPack_BalePackRep.FindByDecorationPack(sourcePackId); foreach (DecorationPack_BalePack decorationPackBalePack in decorationPackBalePacks) { DecorationPack_BalePack clonedDecorationPackBalePack = decorationPackBalePack.Clone <DecorationPack_BalePack>(); clonedDecorationPackBalePack.SetId(Guid.NewGuid()); clonedDecorationPackBalePack.SetDecorationPackId(clonedPackId); this._unitOfWork.RegisterAdd(clonedDecorationPackBalePack); } #endregion this._unitOfWork.Commit(); }
/// <summary> /// 获取聚合根实体关键字 /// </summary> /// <param name="entity">聚合根实体对象</param> /// <returns>关键字</returns> public string GetKeywords(DecorationPack entity) { return(entity.Keywords); }