/// <summary> /// 事件处理方法 /// </summary> /// <param name="eventSource">事件源</param> public void Handle(BalePackProductShelvedEvent eventSource) { BalePackChoiceArea area = this._repMediator.BalePackChoiceAreaRep.Single(eventSource.ChoiceAreaId); BalePack balePack = this._unitOfWork.Resolve <BalePack>(area.BalePack.Id); //下架 if (!eventSource.Shelved) { balePack.SetHasOffShelvedSku(true); this._unitOfWork.RegisterSave(balePack); } //上架 else { //查询套餐下所有商品均上架 IEnumerable <Guid> choiceAreaIds = balePack.ChoiceAreas.Select(s => s.Id); IEnumerable <BalePackProduct> products = this._repMediator.BalePackProductRep.GetProductsByAreaIds(choiceAreaIds); if (products.All(s => s.Shelved)) { balePack.SetHasOffShelvedSku(false); this._unitOfWork.RegisterSave(balePack); } } this._unitOfWork.Commit(); }
/// <summary> /// 大包/定制套餐映射 /// </summary> /// <param name="balePack"></param> /// <returns></returns> public static BalePackInfo ToDTO(this BalePack balePack) { BalePackInfo balePackInfo = Transform <BalePack, BalePackInfo> .Map(balePack); return(balePackInfo); }
/// <summary> /// 克隆套餐模板 /// </summary> /// <param name="sourcePackId">源套餐模板Id</param> /// <returns>新套餐模板Id</returns> private void CloneBalePack(Guid sourcePackId) { BalePack sourcePack = this._repMediator.BalePackRep.Single(sourcePackId); //套餐模板名称,版本号 string version = this._svcMediator.NumberSvc.GeneratePackVersionNo(sourcePack.Id, sourcePack.BalePackType.ToString()); //string packName = "备份套餐【" + sourcePack.Name + "】" + version; //验证 //Assert.IsFalse(this._repMediator.DecorationPackRep.ExistsName(packName), "套餐模板名称已存在!"); //注:此处代码是为了将导航属性加载出来 Trace.WriteLine(sourcePack.ChoiceAreas.Count); //声明套餐副本Id Guid clonedPackId = Guid.NewGuid(); //声明套餐选区Id映射关系字典 IDictionary <Guid, Guid> choiceAreaMaps = new Dictionary <Guid, Guid>(); #region # 克隆套餐、套餐选区;设置源套餐Id,版本号;修改套餐名称; BalePack clonedPack = sourcePack.Clone <BalePack>(); clonedPack.SetId(clonedPackId); clonedPack.ModifyPackNameAndRatio(sourcePack.Name, sourcePack.DiscountRatio); clonedPack.SetSourcePackIdAndVersion(sourcePackId, version); //套餐模板空间Id重新赋值 foreach (BalePackChoiceArea choiceArea in clonedPack.ChoiceAreas) { Guid newPackSpaceId = Guid.NewGuid(); choiceAreaMaps.Add(choiceArea.Id, newPackSpaceId); choiceArea.SetId(newPackSpaceId); } this._unitOfWork.RegisterAdd(clonedPack); #endregion #region # 克隆套餐组、品类、商品;设置是否克隆; IEnumerable <Guid> choiceAreaIds = this._repMediator.BalePackRep.GetChoiceAreaIdsByPackId(sourcePackId); IEnumerable <BalePackGroup> groups = this._repMediator.BalePackGroupRep.GetGroupByChoiceAreaIds(choiceAreaIds); foreach (BalePackGroup group in groups) { //注:此处代码是为了将导航属性加载出来 Trace.WriteLine(group.BalePackCategorys.Count); foreach (BalePackCategory category in group.BalePackCategorys) { //注:此处代码是为了将导航属性加载出来 Trace.WriteLine(category.BalePackProducts.Count); } //克隆套餐组 BalePackGroup clonedGroup = group.Clone <BalePackGroup>(); clonedGroup.SetId(Guid.NewGuid()); clonedGroup.SetChoiceAreaId(choiceAreaMaps[clonedGroup.ChoiceAreaId]); clonedGroup.SetIsClone(); //重新为Id赋值 foreach (BalePackCategory clonedCategory in clonedGroup.BalePackCategorys) { clonedCategory.SetId(Guid.NewGuid()); foreach (BalePackProduct clonedProduct in clonedCategory.BalePackProducts) { clonedProduct.SetId(Guid.NewGuid()); } } this._unitOfWork.RegisterAdd(clonedGroup); } #endregion this._unitOfWork.Commit(); }