コード例 #1
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Contract.Requires(entityView != null);
            Contract.Requires(context != null);
            Condition.Requires(entityView).IsNotNull($"{this.Name}: The argument cannot be null");

            if (entityView == null || !entityView.Action.Equals("VatTaxDashboard-AddDashboardEntity", StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            if (entityView != null && entityView.Action.Equals("VatTaxDashboard-AddDashboardEntity", StringComparison.OrdinalIgnoreCase))
            {
                var taxTag      = entityView.Properties.First(p => p.Name == "TaxTag").Value ?? "";
                var countryCode = entityView.Properties.First(p => p.Name == "CountryCode").Value ?? "";
                var taxPct      = Convert.ToDecimal(entityView.Properties.First(p => p.Name == "TaxPct").Value ?? "0");

                using (var sampleDashboardEntity = new VatTaxEntity())
                {
                    try
                    {
                        sampleDashboardEntity.Id          = CommerceEntity.IdPrefix <VatTaxEntity>() + Guid.NewGuid().ToString("N");
                        sampleDashboardEntity.Name        = string.Empty;
                        sampleDashboardEntity.TaxTag      = taxTag;
                        sampleDashboardEntity.CountryCode = countryCode;
                        sampleDashboardEntity.TaxPct      = taxPct;
                        sampleDashboardEntity.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <VatTaxEntity>());
                        await _commerceCommander.Pipeline <IPersistEntityPipeline>().Run(new PersistEntityArgument(sampleDashboardEntity), context).ConfigureAwait(false);
                    }
                    catch (ArgumentNullException ex)
                    {
                        context.Logger.LogError($"Catalog.DoActionAddDashboardEntity.Exception: Message={ex.Message}");
                    }
                }
            }
            else
            {
                System.Diagnostics.Debug.Write($"Error creating the View is", entityView.Name);
            }

            return(entityView);
        }
コード例 #2
0
        public override async Task <EntityView> Run(EntityView entityView, CommercePipelineExecutionContext context)
        {
            Contract.Requires(context != null);

            /* Adding the code to save a new Vat Tax configuration item */
            if (entityView == null ||
                !entityView.Action.Equals("VatTaxDashboard-AddDashboardEntity", StringComparison.OrdinalIgnoreCase))
            {
                return(entityView);
            }

            try
            {
                var taxTag      = entityView.Properties.First(p => p.Name == "TaxTag").Value ?? "";
                var countryCode = entityView.Properties.First(p => p.Name == "CountryCode").Value ?? "";
                var taxPct      = System.Convert.ToDecimal(entityView.Properties.First(p => p.Name == "TaxPct").Value ?? "0");

                var sampleDashboardEntity = new VatTaxEntity
                {
                    Id          = CommerceEntity.IdPrefix <VatTaxEntity>() + Guid.NewGuid().ToString("N"),
                    Name        = string.Empty,
                    TaxTag      = taxTag,
                    CountryCode = countryCode,
                    TaxPct      = taxPct
                };

                sampleDashboardEntity.GetComponent <ListMembershipsComponent>().Memberships.Add(CommerceEntity.ListName <VatTaxEntity>());

                await this._commerceCommander.PersistEntity(context.CommerceContext, sampleDashboardEntity);
            }
            catch (Exception ex)
            {
                context.Logger.LogError($"Catalog.DoActionAddDashboardEntity.Exception: Message={ex.Message}");
            }


            return(entityView);
        }