コード例 #1
0
        public async Task<IActionResult> UpdateProductManufacturer(string key, [FromBody] ProductManufacturerDto productManufacturer)
        {
            if (productManufacturer == null)
                return NotFound();

            if (!await _permissionService.Authorize(PermissionSystemName.Products))
                return Forbid();

            var product = await _productApiService.GetById(key);
            if (product == null)
            {
                return NotFound();
            }

            var pm = product.Manufacturers.Where(x => x.ManufacturerId == productManufacturer.ManufacturerId).FirstOrDefault();
            if (pm == null)
                ModelState.AddModelError("", "No product manufacturer mapping found with the specified id");

            if (ModelState.IsValid)
            {
                await _productApiService.UpdateProductManufacturer(product, productManufacturer);

                return Ok(true);
            }
            return BadRequest(ModelState);
        }