예제 #1
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="arg">
        /// The AddReviewArgument argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="Review"/>.
        /// </returns>
        public override async Task <Review> Run(AddReviewArgument arg, CommercePipelineExecutionContext context)
        {
            AddReviewBlock addReviewBlock = this;

            Condition.Requires(arg).IsNotNull($"{addReviewBlock.Name}: The block argument cannot be null.");

            string reviewId = Guid.NewGuid().ToString();

            Review review = new Review
            {
                Id     = $"{CommerceEntity.IdPrefix<Review>()}{reviewId}",
                Text   = arg.ReviewsText,
                Author = arg.Author,
                Score  = arg.Score
            };

            DateTimeOffset?dateCreated = DateTimeOffset.UtcNow;

            review.DateCreated = dateCreated;
            DateTimeOffset?dateUpdated = DateTimeOffset.UtcNow;

            review.DateUpdated = dateUpdated;

            CommerceContext commerceContextRef = context.CommerceContext;

            string name = review.Name;

            review.ProductReference = new EntityReference()
            {
                EntityTarget = arg.Product.Id,
                Name         = arg.Product.Name
            };

            Review reviewRef = review;

            reviewRef.SetComponent(new ListMembershipsComponent()
            {
                Memberships = new List <string>()
                {
                    CommerceEntity.ListName <Review>()
                }
            });

            ReviewAddedModel reviewAdded = new ReviewAddedModel(review.FriendlyId)
            {
                Name = name
            };

            commerceContextRef.AddModel(reviewAdded);

            context.CommerceContext.AddUniqueObjectByType(arg);

            await context.CommerceContext.AddMessage(context.GetPolicy <KnownResultCodes>().Information, null, null, "Generated unallocated review");

            return(review);
        }
        public override async Task <CommerceEnvironment> Run(CommerceEnvironment arg, CommercePipelineExecutionContext context)
        {
            CustomPersistEnvironmentBlock environmentBlock = this;

            Condition.Requires(arg).IsNotNull(environmentBlock.Name + ": The argument cannot be null.");
            arg = (await environmentBlock._persistEntityPipeline.Run(new PersistEntityArgument(arg), context).ConfigureAwait(false)).Entity as CommerceEnvironment;
            if (arg != null)
            {
                CommerceContext          commerceContext  = context.CommerceContext;
                ImportedEnvironmentModel environmentModel = new ImportedEnvironmentModel(arg.Id);
                environmentModel.Name = arg.Name;
                commerceContext.AddModel(environmentModel);
                int num = await environmentBlock._resetNodeContext.Process(context.CommerceContext, arg.Id).ConfigureAwait(false) ? 1 : 0;
            }

            return(arg);
        }