/// <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="choiceArea"></param> /// <param name="repMediator"></param> /// <returns></returns> public static BalePackChoiceAreaInfo ToDTO(this BalePackChoiceArea choiceArea, RepositoryMediator repMediator) { BalePackChoiceAreaInfo choiceAreaInfo = Transform <BalePackChoiceArea, BalePackChoiceAreaInfo> .Map(choiceArea); choiceAreaInfo.BalePackInfo = choiceArea.BalePack.ToDTO(); if (choiceArea.BalePack.BalePackType == BalePackType.Customized) { choiceAreaInfo.ExistsSku = repMediator.BalePackGroupRep.IsCustomizedPackShelfed(new List <Guid> { choiceArea.Id }); } if (choiceArea.BalePack.BalePackType == BalePackType.Bale) { choiceAreaInfo.ExistsSku = repMediator.BalePackGroupRep.IsBalePackShelfed(new List <Guid> { choiceArea.Id }); } return(choiceAreaInfo); }