/// <summary>
        /// Validates the product scope.
        /// </summary>
        /// <param name="productBasedObject">The product based object.</param>
        /// <returns>Return true if validation passed.</returns>
        public static bool ValidateProductScope(this IProductIdentifier productBasedObject)
        {
            if (productBasedObject != null)
            {
                var adminUser = ContextHelper.CurrentUserInfo as AdminUserInfo;
                adminUser.CheckNullObject(nameof(adminUser));

                if (!adminUser.ProductKey.HasValue || adminUser.ProductKey.Value == productBasedObject.ProductKey)
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Ensures the product scope.
        /// </summary>
        /// <param name="productBasedObject">The product based object.</param>
        /// <exception cref="UnauthorizedOperationException">ProductOwnership</exception>
        public static void EnsureProductScope(this IProductIdentifier productBasedObject)
        {
            if (productBasedObject != null)
            {
                var adminUser = ContextHelper.CurrentUserInfo as AdminUserInfo;
                adminUser.CheckNullObject(nameof(adminUser));

                if (_parameterProductKey.HasValue)
                {
                    if (!adminUser.ProductKey.HasValue || adminUser.ProductKey.Value == _parameterProductKey.Value)
                    {
                        productBasedObject.ProductKey = _parameterProductKey;
                    }
                    else
                    {
                        throw new UnauthorizedOperationException("ProductOwnership", new { ProductKey = productBasedObject?.ProductKey });
                    }
                }
                else
                {
                    productBasedObject.ProductKey = adminUser.ProductKey ?? productBasedObject.ProductKey;
                }
            }
        }
예제 #3
0
 static ProductInfo()
 {
     product = typeof(ProductInfo).Assembly.GetAttribute <ApexProductAttribute>(false);
 }
예제 #4
0
 public void DecrementProductInventory(IProductIdentifier product, IStoreIdentifier store, int quantity)
 {
     CreateDbContext().Database.ExecuteSqlInterpolated($"Update dbo.Inventory Set Quantity = Quantity - {quantity} Where (ProductId = {product.ProductId}) And (StoreId = {store.StoreId})");
 }