コード例 #1
0
        public async Task <IActionResult> DeleteProductsByIdsAsync([FromBody] List <int> idsList)
        {
            if (idsList == null)
            {
                return(Error("Invalid Payload"));
            }
            if (!idsList.Any())
            {
                return(Error("Empty Products Ids List"));
            }
            var userId = GetUserIdFromClaim();

            _logger.LogInformation($"Deleting Productss: {string.Join(",", idsList)}, Requested By:{userId}");

            ProductsContract products = new ProductsContract();

            products.StatementType = "Delete";

            var command = new AddOrUpdateProductsCommand
            {
                Products = products,
                UserId   = GetUserIdFromClaim()
            };
            var result = await _messages.Dispatch(command).ConfigureAwait(false);

            return(Ok(result));
        }
コード例 #2
0
        public async Task <IActionResult> UpdateProductsAsync([FromBody] ProductsContract products)
        {
            if (products == null)
            {
                return(Error("Invalid Payload"));
            }
            else if (products.Id < 1)
            {
                return(Error("Invalid products id"));
            }

            _logger.LogInformation($"Updating products: ${products.Id}");
            products.StatementType = "Update";
            var command = new AddOrUpdateProductsCommand
            {
                Products = products,
                UserId   = GetUserIdFromClaim()
            };
            var result = await _messages.Dispatch(command).ConfigureAwait(false);

            return(Ok(result));
        }
コード例 #3
0
        public async Task <IActionResult> DeleteProductsAsync(int productsId)
        {
            if (productsId < 1)
            {
                return(Error("Invalid Products Id"));
            }
            var userId = GetUserIdFromClaim();

            _logger.LogInformation($"Deleting Products: ${productsId}, Requested By:${userId}");

            ProductsContract products = new ProductsContract();

            products.StatementType = "Delete";
            products.Id            = productsId;

            var command = new AddOrUpdateProductsCommand
            {
                Products = products,
                UserId   = GetUserIdFromClaim()
            };
            var result = await _messages.Dispatch(command).ConfigureAwait(false);

            return(Ok(result));
        }
コード例 #4
0
        public async Task <int> AddOrUpdateProductsAsync(ProductsContract products, int userId)
        {
            using var connection = _connectionFactory.GetDbConnection();
            var procName = StoredProcedureConstants.spProductsInsertUpdateDelete;
            var result   = await connection.QueryAsync <int>(procName, new
            {
                Product_id     = products.Id,
                Company_id     = products.Companyid,
                Product_name   = products.ProductName,
                Techname       = products.Techname,
                Searchname     = products.Searchname,
                Description    = products.Description,
                PrimeImage     = products.PrimeImage,
                Price          = products.Price,
                Sold_By        = products.SoldBy,
                Specifications = products.Specifications,
                ProductURL     = products.ProductURL,
                AvgCustReview  = products.AvgCustReview,
                YrofLaunch     = products.YrofLaunch,
                StatementType  = products.StatementType
            }, null, null, CommandType.StoredProcedure).ConfigureAwait(false);

            return(result.FirstOrDefault());
        }