Esempio n. 1
0
        public async Task<IActionResult> DeleteProductPicture(string key, [FromBody] ODataActionParameters parameters)
        {
            if (parameters == null)
                return NotFound();

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

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

            var pictureId = parameters.FirstOrDefault(x => x.Key == "PictureId").Value;
            if (pictureId != null)
            {
                var pp = product.Pictures.Where(x => x.PictureId == pictureId.ToString()).FirstOrDefault();
                if (pp == null)
                    ModelState.AddModelError("", "No product picture mapping found with the specified id");

                if (ModelState.IsValid)
                {
                    await _productApiService.DeleteProductPicture(product, pictureId.ToString());
                    return Ok(true);
                }
                return BadRequest(ModelState);
            }
            return NotFound();
        }