public async Task <IActionResult> DeleteProductTierPrice(string key, [FromBody] ODataActionParameters parameters)
        {
            if (parameters == null)
            {
                return(BadRequest());
            }

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

            var product = await _mediator.Send(new GetQuery <ProductDto>() { Id = key });

            if (!product.Any())
            {
                return(NotFound());
            }

            var tierPriceId = parameters.FirstOrDefault(x => x.Key == "Id").Value;

            if (tierPriceId != null)
            {
                var pt = product.FirstOrDefault().TierPrices.Where(x => x.Id == tierPriceId.ToString()).FirstOrDefault();
                if (pt == null)
                {
                    ModelState.AddModelError("", "No product tier price mapping found with the specified id");
                }

                if (ModelState.IsValid)
                {
                    var result = await _mediator.Send(new DeleteProductTierPriceCommand()
                    {
                        Product = product.FirstOrDefault(), Id = tierPriceId.ToString()
                    });

                    return(Ok(result));
                }
                return(BadRequest(ModelState));
            }
            return(NotFound());
        }
        public async Task <IActionResult> DeleteProductSpecification(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 specificationId = parameters.FirstOrDefault(x => x.Key == "Id").Value;

            if (specificationId != null)
            {
                var psa = product.SpecificationAttribute.Where(x => x.Id == specificationId.ToString()).FirstOrDefault();
                if (psa == null)
                {
                    ModelState.AddModelError("", "No product picture specification found with the specified id");
                }

                if (ModelState.IsValid)
                {
                    await _productApiService.DeleteProductSpecification(product, specificationId.ToString());

                    return(Ok(true));
                }
                return(BadRequest(ModelState));
            }
            return(NotFound());
        }
        public async Task <IActionResult> DeleteAddress(string key, [FromBody] ODataActionParameters parameters)
        {
            if (!await _permissionService.Authorize(PermissionSystemName.Customers))
            {
                return(Forbid());
            }

            var addressId = parameters.FirstOrDefault(x => x.Key == "addressId").Value;

            if (addressId == null)
            {
                return(NotFound());
            }

            var customer = await _mediator.Send(new GetCustomerQuery()
            {
                Email = key
            });

            if (customer == null)
            {
                return(NotFound());
            }

            var address = customer.Addresses.FirstOrDefault(x => x.Id == addressId.ToString());

            if (address == null)
            {
                return(NotFound());
            }

            await _mediator.Send(new DeleteCustomerAddressCommand()
            {
                Customer = customer, Address = address
            });

            return(Ok(true));
        }
        public IActionResult DeleteProductPicture(string key, [FromBody] ODataActionParameters parameters)
        {
            if (parameters == null)
            {
                return(NotFound());
            }

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

            var product = _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)
                {
                    _productApiService.DeleteProductPicture(product, pictureId.ToString());
                    return(Ok(true));
                }
                return(BadRequest(ModelState));
            }
            return(NotFound());
        }
        public IActionResult SetPassword(string key, [FromBody] ODataActionParameters parameters)
        {
            if (!_permissionService.Authorize(PermissionSystemName.Customers))
            {
                return(Forbid());
            }

            var password = parameters.FirstOrDefault(x => x.Key == "password").Value;

            if (password == null)
            {
                return(NotFound());
            }

            var changePassRequest = new ChangePasswordRequest(key, false, _customerSettings.DefaultPasswordFormat, password.ToString());
            var changePassResult  = _customerRegistrationService.ChangePassword(changePassRequest);

            if (!changePassResult.Success)
            {
                return(BadRequest(string.Join(',', changePassResult.Errors)));
            }
            return(Ok(true));
        }