コード例 #1
0
        public async Task <ActionResult> Put(string authorization, int id, ProductUpdateParameters parameters)
        {
            var product = await _productService.Update(id, parameters);

            if (product == null)
            {
                return(Ok(new ProductUpdateResult()));
            }
            return(Ok(product));
        }
コード例 #2
0
        public async Task <bool> UpdateValidation(int id, ProductUpdateParameters parameters)
        {
            bool findProductName = await _dbContext.Products.AnyAsync(p => (p.Id != id) && p.Name.ToLower().Equals(parameters.Name.ToLower()));

            if (findProductName)
            {
                return(false);
            }
            return(true);
        }
コード例 #3
0
        /// <inheritdoc />
        public void UpdateProduct(int productId, ProductUpdateParameters productUpdateParameters)
        {
            var product = this.GetProducts().FirstOrDefault(x => x.Id == productId);

            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            if (!productUpdateParameters.ReplaceDescription)
            {
                return;
            }

            product.Description = productUpdateParameters.Description;
        }
コード例 #4
0
        /// <inheritdoc />
        public void UpdateProduct(int productId, ProductUpdateParameters productUpdateParameters)
        {
            if (!productUpdateParameters.ReplaceDescription)
            {
                return;
            }

            var product = this.ShopDbContext.Products.Find(productId);

            if (product == null)
            {
                throw new ArgumentNullException(nameof(product));
            }

            product.Description = productUpdateParameters.Description;

            this.SaveChanges();
            this.logger.LogInformation($"Updated product with Id = {productId}.");
        }
コード例 #5
0
        public async Task <ProductUpdateResult> Update(int id, ProductUpdateParameters parameters)
        {
            var product = await _dbContext.Products.FirstOrDefaultAsync(p => p.Id == id);

            if (!(await _productValidation.UpdateValidation(id, parameters)) || product == null)
            {
                return(null);
            }


            product.Name           = parameters.Name;
            product.TicketPriority = parameters.TicketPriority;

            await _dbContext.SaveChangesAsync();

            return(new ProductUpdateResult
            {
                Name = product.Name,
                Id = product.Id,
                TicketPriority = product.TicketPriority
            });
        }
コード例 #6
0
        /// <inheritdoc />
        public UpdateResult <Product> UpdateProduct(int productId, ProductUpdateParameters productUpdateParameters)
        {
            try
            {
                this.productRepository.UpdateProduct(productId, productUpdateParameters);
                Product product = this.productRepository.GetProduct(productId);

                return(new UpdateResult <Product>()
                {
                    Result = product,
                    Success = true
                });
            }
            catch (Exception ex)
            {
                return(new UpdateResult <Product>()
                {
                    ExceptionMessage = ex.Message,
                    Success = false
                });
            }
        }
 /// <summary>
 /// Update product.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IProductsOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='pid'>
 /// Required. Identifier of the product.
 /// </param>
 /// <param name='parameters'>
 /// Required. Update parameters.
 /// </param>
 /// <param name='etag'>
 /// Required. ETag.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static Task <AzureOperationResponse> UpdateAsync(this IProductsOperations operations, string resourceGroupName, string serviceName, string pid, ProductUpdateParameters parameters, string etag)
 {
     return(operations.UpdateAsync(resourceGroupName, serviceName, pid, parameters, etag, CancellationToken.None));
 }
 /// <summary>
 /// Update product.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.ApiManagement.IProductsOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// Required. The name of the Api Management service.
 /// </param>
 /// <param name='pid'>
 /// Required. Identifier of the product.
 /// </param>
 /// <param name='parameters'>
 /// Required. Update parameters.
 /// </param>
 /// <param name='etag'>
 /// Required. ETag.
 /// </param>
 /// <returns>
 /// A standard service response including an HTTP status code and
 /// request ID.
 /// </returns>
 public static AzureOperationResponse Update(this IProductsOperations operations, string resourceGroupName, string serviceName, string pid, ProductUpdateParameters parameters, string etag)
 {
     return(Task.Factory.StartNew((object s) =>
     {
         return ((IProductsOperations)s).UpdateAsync(resourceGroupName, serviceName, pid, parameters, etag);
     }
                                  , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
コード例 #9
0
        public async Task CreateListUpdateDelete()
        {
            Environment.SetEnvironmentVariable("AZURE_TEST_MODE", "Playback");
            using (MockContext context = MockContext.Start(this.GetType()))
            {
                var testBase = new ApiManagementTestBase(context);
                testBase.TryCreateApiManagementService();

                var listResponse = testBase.client.Product.ListByService(
                    testBase.rgName,
                    testBase.serviceName,
                    null);

                Assert.NotNull(listResponse);
                Assert.Equal(2, listResponse.Count());// there are 2 product Starter and Unlimited created by default
                Assert.Null(listResponse.NextPageLink);

                string productId = TestUtilities.GenerateName("newproduct");

                try
                {
                    string       productName                 = TestUtilities.GenerateName("productName");
                    bool?        productApprovalRequired     = true;
                    string       productDescription          = TestUtilities.GenerateName("productDescription");
                    ProductState productState                = ProductState.NotPublished;
                    bool?        productSubscriptionRequired = true;
                    int?         productSubscriptionsLimit   = 10;
                    string       productTerms                = TestUtilities.GenerateName("productTerms");

                    var createParameters = new ProductContract(productName)
                    {
                        ApprovalRequired     = productApprovalRequired,
                        Description          = productDescription,
                        State                = productState,
                        SubscriptionRequired = productSubscriptionRequired,
                        SubscriptionsLimit   = productSubscriptionsLimit,
                        Terms                = productTerms
                    };

                    var createResponse = testBase.client.Product.CreateOrUpdate(
                        testBase.rgName,
                        testBase.serviceName,
                        productId,
                        createParameters);

                    Assert.NotNull(createResponse);
                    Assert.Equal(productName, createResponse.DisplayName);
                    Assert.Equal(productApprovalRequired, createResponse.ApprovalRequired);
                    Assert.Equal(productDescription, createResponse.Description);
                    Assert.Equal(productState, createResponse.State);
                    Assert.Equal(productSubscriptionRequired, createResponse.SubscriptionRequired);
                    Assert.Equal(productSubscriptionsLimit, createResponse.SubscriptionsLimit);
                    Assert.Equal(productTerms, createResponse.Terms);

                    //get async
                    var productTag = await testBase.client.Product.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        productId);

                    Assert.NotNull(productTag);

                    // update product
                    string patchedName        = TestUtilities.GenerateName("productName");
                    string patchedDescription = TestUtilities.GenerateName("productDescription");
                    string patchedTerms       = TestUtilities.GenerateName("productTerms");
                    var    updateParameters   = new ProductUpdateParameters
                    {
                        DisplayName = patchedName,
                        Description = patchedDescription,
                        Terms       = patchedTerms
                    };
                    testBase.client.Product.Update(
                        testBase.rgName,
                        testBase.serviceName,
                        productId,
                        updateParameters,
                        productTag.ETag);

                    // get to check it was updated
                    var getUpdatedResponse = testBase.client.Product.Get(
                        testBase.rgName,
                        testBase.serviceName,
                        productId);

                    Assert.NotNull(getUpdatedResponse);

                    Assert.Equal(patchedName, getUpdatedResponse.DisplayName);
                    Assert.Equal(productApprovalRequired, getUpdatedResponse.ApprovalRequired);
                    Assert.Equal(patchedDescription, getUpdatedResponse.Description);
                    Assert.Equal(productState, getUpdatedResponse.State);
                    Assert.Equal(productSubscriptionRequired, getUpdatedResponse.SubscriptionRequired);
                    Assert.Equal(productSubscriptionsLimit, getUpdatedResponse.SubscriptionsLimit);
                    Assert.Equal(patchedTerms, getUpdatedResponse.Terms);

                    // check product listing works
                    // list paged
                    var productList = await testBase.client.Product.ListByServiceAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        new Microsoft.Rest.Azure.OData.ODataQuery <ProductContract> {
                        Top = 1
                    });

                    Assert.NotNull(productList);
                    Assert.Single(productList);
                    // first is the product in Test due to alphabetical order of name
                    Assert.Equal(patchedName, productList.First().DisplayName);
                    Assert.NotEmpty(productList.NextPageLink);

                    // check the next link returned from above query works
                    var pagedProducts = await testBase.client.Product.ListByServiceNextAsync(productList.NextPageLink);

                    Assert.NotNull(pagedProducts);
                    Assert.Single(pagedProducts);
                    // next is the Starter product due to alphabetical order of name
                    Assert.Equal("Starter", pagedProducts.First().DisplayName);

                    // check the nextlink to the next page link query works
                    pagedProducts = await testBase.client.Product.ListByServiceNextAsync(pagedProducts.NextPageLink);

                    Assert.NotNull(pagedProducts);
                    Assert.Single(pagedProducts);
                    // finally the Unlimited product due to alphabetical order of name
                    Assert.Equal("Unlimited", pagedProducts.First().DisplayName);
                    Assert.Null(pagedProducts.NextPageLink); // it should be empty now.

                    // get the entity tag
                    productTag = await testBase.client.Product.GetEntityTagAsync(
                        testBase.rgName,
                        testBase.serviceName,
                        productId);

                    Assert.NotNull(productTag);

                    // delete the product
                    testBase.client.Product.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        productId,
                        productTag.ETag,
                        deleteSubscriptions: true);

                    // get the deleted product to make sure it was deleted
                    Assert.Throws <ErrorResponseException>(()
                                                           => testBase.client.Product.Get(
                                                               testBase.rgName,
                                                               testBase.serviceName,
                                                               productId));
                }
                finally
                {
                    testBase.client.Product.Delete(
                        testBase.rgName,
                        testBase.serviceName,
                        productId,
                        "*",
                        true);
                }
            }
        }
        public void ProductsCreateListUpdateDelete()
        {
            TestUtilities.StartTest("SmapiFunctionalTests", "ProductsCreateListUpdateDelete");

            try
            {
                // list all products: there should be two products: Starter and Unlimited
                var listResponse = ApiManagementClient.Products.List(ResourceGroupName, ApiManagementServiceName, null);

                Assert.NotNull(listResponse);
                Assert.NotNull(listResponse.Result);
                Assert.Equal(2, listResponse.Result.TotalCount);
                Assert.Equal(2, listResponse.Result.Values.Count);

                // list paged
                listResponse = ApiManagementClient.Products.List(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    new QueryParameters {
                    Top = 1
                });

                Assert.NotNull(listResponse);
                Assert.NotNull(listResponse.Result);
                Assert.Equal(2, listResponse.Result.TotalCount);
                Assert.Equal(1, listResponse.Result.Values.Count);

                // create new product
                string productId                   = TestUtilities.GenerateName("productId");
                string productName                 = TestUtilities.GenerateName("productName");
                bool?  productApprovalRequired     = true;
                string productDescription          = TestUtilities.GenerateName("productDescription");
                ProductStateContract productState  = ProductStateContract.NotPublished;
                bool?  productSubscriptionRequired = true;
                int?   productSubscriptionsLimit   = 10;
                string productTerms                = TestUtilities.GenerateName("productTerms");

                ProductContract productContract = new ProductContract(productName)
                {
                    ApprovalRequired = productApprovalRequired,
                    Description      = productDescription,
                    //Groups =
                    State = productState,
                    SubscriptionRequired = productSubscriptionRequired,
                    SubscriptionsLimit   = productSubscriptionsLimit,
                    Terms = productTerms
                };

                var createResponse = ApiManagementClient.Products.Create(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    productId,
                    new ProductCreateParameters(productContract));

                Assert.NotNull(createResponse);
                Assert.Equal(HttpStatusCode.Created, createResponse.StatusCode);

                // get to check it was created
                var getResponse = ApiManagementClient.Products.Get(ResourceGroupName, ApiManagementServiceName, productId);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse.Value);

                Assert.Equal(productId, getResponse.Value.Id);
                Assert.Equal(productName, getResponse.Value.Name);
                Assert.Equal(productApprovalRequired, getResponse.Value.ApprovalRequired);
                Assert.Equal(productDescription, getResponse.Value.Description);
                Assert.Equal(productState, getResponse.Value.State);
                Assert.Equal(productSubscriptionRequired, getResponse.Value.SubscriptionRequired);
                Assert.Equal(productSubscriptionsLimit, getResponse.Value.SubscriptionsLimit);
                Assert.Equal(productTerms, getResponse.Value.Terms);

                // update product
                string patchedName        = TestUtilities.GenerateName("productName");
                string patchedDescription = TestUtilities.GenerateName("productDescription");
                string patchedTerms       = TestUtilities.GenerateName("productTerms");
                var    updateParameters   = new ProductUpdateParameters
                {
                    Name        = patchedName,
                    Description = patchedDescription,
                    Terms       = patchedTerms
                };
                ApiManagementClient.Products.Update(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    productId,
                    updateParameters,
                    getResponse.ETag);

                // get to check it was updated
                getResponse = ApiManagementClient.Products.Get(ResourceGroupName, ApiManagementServiceName, productId);

                Assert.NotNull(getResponse);
                Assert.NotNull(getResponse.Value);

                Assert.Equal(productId, getResponse.Value.Id);
                Assert.Equal(patchedName, getResponse.Value.Name);
                Assert.Equal(productApprovalRequired, getResponse.Value.ApprovalRequired);
                Assert.Equal(patchedDescription, getResponse.Value.Description);
                Assert.Equal(productState, getResponse.Value.State);
                Assert.Equal(productSubscriptionRequired, getResponse.Value.SubscriptionRequired);
                Assert.Equal(productSubscriptionsLimit, getResponse.Value.SubscriptionsLimit);
                Assert.Equal(patchedTerms, getResponse.Value.Terms);

                // delete the product
                var deleteResponse = ApiManagementClient.Products.Delete(
                    ResourceGroupName,
                    ApiManagementServiceName,
                    productId,
                    getResponse.ETag,
                    true);

                Assert.NotNull(deleteResponse);
                Assert.Equal(HttpStatusCode.NoContent, deleteResponse.StatusCode);

                // get the deleted api to make sure it was deleted
                try
                {
                    ApiManagementClient.Products.Get(ResourceGroupName, ApiManagementServiceName, productId);
                    throw new Exception("This code should not have been executed.");
                }
                catch (CloudException ex)
                {
                    Assert.Equal(HttpStatusCode.NotFound, ex.Response.StatusCode);
                }
            }
            finally
            {
                TestUtilities.EndTest();
            }
        }
コード例 #11
0
 /// <summary>
 /// Update product.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='productId'>
 /// Product identifier. Must be unique in the current API Management service
 /// instance.
 /// </param>
 /// <param name='parameters'>
 /// Update parameters.
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Entity. ETag should match the current entity state from the
 /// header response of the GET request or it should be * for unconditional
 /// update.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task UpdateAsync(this IProductOperations operations, string resourceGroupName, string serviceName, string productId, ProductUpdateParameters parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken))
 {
     (await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, productId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)).Dispose();
 }
コード例 #12
0
 /// <summary>
 /// Update product.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='productId'>
 /// Product identifier. Must be unique in the current API Management service
 /// instance.
 /// </param>
 /// <param name='parameters'>
 /// Update parameters.
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Entity. ETag should match the current entity state from the
 /// header response of the GET request or it should be * for unconditional
 /// update.
 /// </param>
 public static void Update(this IProductOperations operations, string resourceGroupName, string serviceName, string productId, ProductUpdateParameters parameters, string ifMatch)
 {
     operations.UpdateAsync(resourceGroupName, serviceName, productId, parameters, ifMatch).GetAwaiter().GetResult();
 }
コード例 #13
0
 /// <summary>
 /// Update existing product details.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='serviceName'>
 /// The name of the API Management service.
 /// </param>
 /// <param name='productId'>
 /// Product identifier. Must be unique in the current API Management service
 /// instance.
 /// </param>
 /// <param name='parameters'>
 /// Update parameters.
 /// </param>
 /// <param name='ifMatch'>
 /// ETag of the Entity. ETag should match the current entity state from the
 /// header response of the GET request or it should be * for unconditional
 /// update.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <ProductContract> UpdateAsync(this IProductOperations operations, string resourceGroupName, string serviceName, string productId, ProductUpdateParameters parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, productId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }