Exemplo n.º 1
0
        public async Task <bool> Process(CommerceContext commerceContext, Promotion promotion, List <Policy> policies = null)
        {
            using (CommandActivity.Start(commerceContext, this))
            {
                var createdPromotion = promotion;

                commerceContext.GetMessages().Add(new CommandMessage {
                    Code = "Information", CommerceTermKey = "PromotionBeingApproved", Text = "Promotion Being Approved!"
                });

                var requestApprovalResponse = await this._commerceCommander.Command <SetApprovalStatusCommand>()
                                              .Process(commerceContext.GetPipelineContextOptions().CommerceContext, createdPromotion,
                                                       commerceContext.GetPolicy <ApprovalStatusPolicy>().ReadyForApproval, "Generated");

                if (!requestApprovalResponse)
                {
                    commerceContext.Logger.LogWarning($"DoActionGeneratePromotionBook.ApprovalRequestDenied: PromotionId={createdPromotion.Id}");
                }

                createdPromotion = await this._commerceCommander.GetEntity <Promotion>(commerceContext, $"{createdPromotion.Id}");

                var approvalResponse = await this._commerceCommander.Command <SetApprovalStatusCommand>()
                                       .Process(commerceContext.GetPipelineContextOptions().CommerceContext, createdPromotion, commerceContext.GetPolicy <ApprovalStatusPolicy>().Approved, "Generated");

                if (!approvalResponse)
                {
                    commerceContext.Logger.LogWarning($"DoActionGeneratePromotionBook.ApprovalRequestDenied: PromotionId={createdPromotion.Id}");
                }
                else
                {
                    commerceContext.GetMessages().Add(new CommandMessage {
                        Code = "Information", CommerceTermKey = "PromotionApproved", Text = "Promotion Approved!"
                    });
                }

                createdPromotion = await this._commerceCommander.GetEntity <Promotion>(commerceContext, $"{createdPromotion.Id}");

                await this._commerceCommander.PersistEntity(commerceContext, createdPromotion);

                return(true);
            }
        }
 /// <summary>
 /// Copies messages from one context into another.
 /// </summary>
 /// <param name="targetContext">The context that will recieve the messages.</param>
 /// <param name="sourceContext">The context that is the source of the messages.</param>
 protected void MergeMessages(CommerceContext targetContext, CommerceContext sourceContext)
 {
     Condition.Requires(targetContext, nameof(targetContext)).IsNotNull();
     if (sourceContext != null)
     {
         foreach (var message in sourceContext.GetMessages())
         {
             targetContext.AddMessage(message);
         }
     }
 }