public void Post([FromBody] ProductCreateParameters parameters) { Logger.Log.Info($"Creating product ..."); ProductService productService = new ProductService(); var id = productService.CreateProduct(parameters); Logger.Log.Info($"Created product with id {id}."); }
public async Task <ActionResult> Post(string authorization, ProductCreateParameters parameters) { var product = await _productService.Create(parameters); if (product == null) { return(Ok(new ProductCreateResult())); } return(Ok(product)); }
public async Task <bool> CreateValidation(ProductCreateParameters parameters) { var findProductName = await _dbContext.Products.AnyAsync(p => p.Name.ToLower().Equals(parameters.Name.ToLower())); if (!string.IsNullOrEmpty(parameters.Name) && !(findProductName)) { return(true); } return(false); }
/// <summary> /// Updates an existing product. /// </summary> /// <param name="id">Product ID.</param> /// <param name="parameters">Updated product information.</param> public void Put(int id, [FromBody] ProductCreateParameters parameters) { ILog log = LogManager.GetLogger(typeof(ProductsController)); try { var service = new ProductService(SecretValues.ConnectionString); service.UpdateProduct(id, parameters.Name); } catch (Exception ex) { log.Error(ex); throw; } }
/// <summary> /// Creates a new product. /// </summary> /// <param name="parameters">New product information.</param> /// <returns>Product information.</returns> public Product Post([FromBody] ProductCreateParameters parameters) { ILog log = LogManager.GetLogger(typeof(ProductsController)); try { var service = new ProductService(SecretValues.ConnectionString); var newProduct = service.CreateProduct(parameters.Name); return(newProduct); } catch (Exception ex) { log.Error(ex); throw; } }
public async Task <ProductCreateResult> Create(ProductCreateParameters parameters) { if (!await _productValidation.CreateValidation(parameters)) { return(null); } var product = await _dbContext.Products.AddAsync(new Product { Name = parameters.Name, TicketPriority = parameters.TicketPriority }); await _dbContext.SaveChangesAsync(); return(new ProductCreateResult() { Name = product.Entity.Name, Id = product.Entity.Id, TicketPriority = product.Entity.TicketPriority }); }
/// <summary> /// Create new 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. Create or update parameters. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> CreateAsync(this IProductsOperations operations, string resourceGroupName, string serviceName, string pid, ProductCreateParameters parameters) { return(operations.CreateAsync(resourceGroupName, serviceName, pid, parameters, CancellationToken.None)); }
/// <summary> /// Create new 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. Create or update parameters. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse Create(this IProductsOperations operations, string resourceGroupName, string serviceName, string pid, ProductCreateParameters parameters) { return(Task.Factory.StartNew((object s) => { return ((IProductsOperations)s).CreateAsync(resourceGroupName, serviceName, pid, parameters); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }