private Item Create(ItemCriteria criteria)
        {
            var item = (Item)Activator.CreateInstance(typeof(Item), true);

            bool cancel = false;

            OnCreating(ref cancel);
            if (cancel)
            {
                return(item);
            }

            var resource = Fetch(criteria);

            using (BypassPropertyChecks(item))
            {
                item.ListPrice = resource.ListPrice;
                item.UnitCost  = resource.UnitCost;
                item.Status    = resource.Status;
                item.Name      = resource.Name;
                item.Image     = resource.Image;
            }

            CheckRules(item);
            MarkNew(item);

            OnCreated();

            return(item);
        }
        private Item Create(ItemCriteria criteria)
        {
            var item = (Item)Activator.CreateInstance(typeof(Item), true);

            bool cancel = false;
            OnCreating(ref cancel);
            if (cancel) return item;

            var resource = Fetch(criteria);
            using (BypassPropertyChecks(item))
            {
                item.ListPrice = resource.ListPrice;
                item.UnitCost = resource.UnitCost;
                item.Status = resource.Status;
                item.Name = resource.Name;
                item.Image = resource.Image;
            }

            CheckRules(item);
            MarkNew(item);

            OnCreated();

            return item;
        }
Example #3
0
            public IEnumerator GetItemByCriteria_byTags_Success()
            {
                Items items = AccelBytePlugin.GetItems();

                string[]     tags         = new string[] { "SDK", "GAME" };
                ItemCriteria itemCriteria = new ItemCriteria {
                    tags = tags
                };
                Result <ItemPagingSlicedResult> getItemByCriteriaResult = null;

                items.GetItemsByCriteria(
                    itemCriteria,
                    result => { getItemByCriteriaResult = result; });

                while (getItemByCriteriaResult == null)
                {
                    yield return(null);
                }

                TestHelper.Assert.IsTrue(!getItemByCriteriaResult.IsError, "Get item by item by tags failed.");
                if (getItemByCriteriaResult.Value.data.Length > 0)
                {
                    TestHelper.Assert.IsTrue(
                        getItemByCriteriaResult.Value.data[0].tags[0] == tags[0] ||
                        getItemByCriteriaResult.Value.data[0].tags[0] == tags[1],
                        "Get item by item by tags failed.");
                }
            }
        private void Child_Fetch(ItemCriteria criteria)
        {
            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return;

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [ItemId], [ProductId], [ListPrice], [UnitCost], [Supplier], [Status], [Name], [Image] FROM [dbo].[Item] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                        {
                            do
                            {
                                this.Add(PetShop.Business.Item.GetItem(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
        private void DataPortal_Fetch(ItemCriteria criteria)
        {
            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return;

            string commandText = String.Format("SELECT [ItemId], [ProductId], [ListPrice], [UnitCost], [Supplier], [Status], [Name], [Image] FROM [dbo].[Item] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                            Map(reader);
                        else
                            throw new Exception(String.Format("The record was not found in 'dbo.Item' using the following criteria: {0}.", criteria));
                    }
                }
            }

            OnFetched();
        }
        /// <summary>
        /// Fetch ItemList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public ItemList Fetch(ItemCriteria criteria)
        {
            ItemList item = (ItemList)Activator.CreateInstance(typeof(ItemList), true);

            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return item;

            // Fetch Child objects.
            string commandText = String.Format("SELECT [ItemId], [ProductId], [ListPrice], [UnitCost], [Supplier], [Status], [Name], [Image] FROM [dbo].[Item] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new ItemFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return item;
        }
        private void DataPortal_Fetch(ItemCriteria criteria)
        {
            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return;

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue);
                command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue);
                command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue);
                command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue);
                command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue);
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                            Map(reader);
                        else
                            throw new Exception(String.Format("The record was not found in 'dbo.Item' using the following criteria: {0}.", criteria));
                    }
                }
            }

            OnFetched();
        }
Example #8
0
            public IEnumerator GetItemByCriteria_CategoryPathInvalid_SuccessButEmpty()
            {
                Items        items = AccelBytePlugin.GetItems();
                const string invalidCategoryPath = "/invalidPath";
                Result <ItemPagingSlicedResult> getItemByCriteriaResult = null;
                ItemCriteria itemCriteria = new ItemCriteria {
                    categoryPath = invalidCategoryPath
                };

                items.GetItemsByCriteria(
                    itemCriteria,
                    result => { getItemByCriteriaResult = result; });

                while (getItemByCriteriaResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                TestHelper.Assert.IsTrue(!getItemByCriteriaResult.IsError, "Get item by invalid category path failed.");
                TestHelper.Assert.IsTrue(
                    getItemByCriteriaResult.Value.data.Length == 0,
                    "Get item by invalid category path failed.");
            }
Example #9
0
            public IEnumerator GetItemByCriteria_LanguageInvalid_Success()
            {
                Items        items = AccelBytePlugin.GetItems();
                const string invalidCategoryLanguage = "id";
                ItemCriteria itemCriteria            = new ItemCriteria {
                    categoryPath = TestVariables.expectedChildCategoryPath,
                    language     = invalidCategoryLanguage
                };
                Result <ItemPagingSlicedResult> getItemByCriteriaResult = null;

                items.GetItemsByCriteria(
                    itemCriteria,
                    result => { getItemByCriteriaResult = result; });

                while (getItemByCriteriaResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                TestHelper.Assert.IsTrue(!getItemByCriteriaResult.IsError, "Get item by invalid language failed.");
                TestHelper.Assert.IsTrue(
                    getItemByCriteriaResult.Value.data[0].categoryPath.Contains(TestVariables.expectedChildCategoryPath),
                    "Get item by invalid language failed.");
            }
        /// <summary>
        /// This call to delete is for immediate deletion and doesn't keep track of any entity state.
        /// </summary>
        /// <param name="criteria">The Criteria.</param>
        private void DoDelete(ItemCriteria criteria)
        {
            bool cancel = false;

            OnDeleting(criteria, ref cancel);
            if (cancel)
            {
                return;
            }

            string commandText = String.Format("DELETE FROM [dbo].[Item] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                    int result = command.ExecuteNonQuery();
                    if (result == 0)
                    {
                        throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                    }
                }
            }

            OnDeleted();
        }
Example #11
0
            public IEnumerator GetUserOrder_OrderExists_Success()
            {
                Items        items        = AccelBytePlugin.GetItems();
                ItemCriteria itemCriteria = new ItemCriteria
                {
                    categoryPath = TestVariables.expectedChildCategoryPath,
                    sortBy       = "createdAt:desc"
                };
                Result <ItemPagingSlicedResult> getItemsByCriteria = null;

                items.GetItemsByCriteria(
                    itemCriteria,
                    result =>
                {
                    getItemsByCriteria = result;
                });

                while (getItemsByCriteria == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                int          quantity     = 1;
                Orders       orders       = AccelBytePlugin.GetOrders();
                OrderRequest orderRequest = new OrderRequest
                {
                    currencyCode    = getItemsByCriteria.Value.data[0].regionData[0].currencyCode,
                    discountedPrice = getItemsByCriteria.Value.data[0].regionData[0].discountedPrice * quantity,
                    itemId          = getItemsByCriteria.Value.data[0].itemId,
                    price           = getItemsByCriteria.Value.data[0].regionData[0].price * quantity,
                    quantity        = quantity,
                    returnUrl       = "https://www.example.com"
                };
                Result <OrderInfo> createOrderResult = null;

                orders.CreateOrder(orderRequest, result => { createOrderResult = result; });

                while (createOrderResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                Result <OrderInfo> getUserOrderResult = null;

                orders.GetUserOrder(createOrderResult.Value.orderNo, result => { getUserOrderResult = result; });

                while (getUserOrderResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                TestHelper.Assert.IsTrue(!getUserOrderResult.IsError, "Get user order failed.");
            }
        public IEnumerator <ITask> GetItemsByCriteria(string @namespace, string accessToken, string region,
                                                      string language, ItemCriteria criteria, ResultCallback <PagedItems> callback)
        {
            Assert.IsNotNull(@namespace, "Can't get items by criteria! Namespace parameter is null!");
            Assert.IsNotNull(accessToken, "Can't get items by criteria! AccessToken parameter is null!");
            Assert.IsNotNull(language, "Can't get items by criteria! Language parameter is null!");
            Assert.IsNotNull(criteria, "Can't get items by criteria! Criteria parameter is null!");
            Assert.IsNotNull(language, "Can't get items by criteria! Language parameter is null!");

            var queries = new Dictionary <string, string>();

            if (criteria != null)
            {
                if (criteria.CategoryPath != null)
                {
                    queries.Add("categoryPath", criteria.CategoryPath);
                }

                if (criteria.ItemType != null)
                {
                    queries.Add("itemType", criteria.ItemType.ToString());
                }

                if (criteria.ItemStatus != null)
                {
                    queries.Add("status", criteria.ItemStatus.ToString());
                }

                if (criteria.Page != null)
                {
                    queries.Add("page", Convert.ToString(criteria.Page));
                }

                if (criteria.Size != null)
                {
                    queries.Add("size", Convert.ToString(criteria.Size));
                }
            }

            var request = HttpRequestBuilder
                          .CreateGet(this.baseUrl + "/platform/public/namespaces/{namespace}/items/byCriteria")
                          .WithPathParam("namespace", @namespace)
                          .WithQueryParam("region", region)
                          .WithQueryParam("language", language)
                          .WithQueries(queries)
                          .WithBearerAuth(accessToken)
                          .Accepts(MediaType.ApplicationJson)
                          .ToRequest();

            HttpWebResponse response = null;

            yield return(Task.Await(request, rsp => response = rsp));

            var result = response.TryParseJsonBody <PagedItems>();

            callback.Try(result);
        }
Example #13
0
        public async Task <IActionResult> GetItems([FromRoute] string projectKey, [FromQuery] ItemCriteria criteria)
        {
            if (!await _permissionService.HasProjectPermissionAsync(projectKey, Permission.Read))
            {
                return(StatusCode(403, "You have no permission to view items."));
            }

            criteria.ProjectKey = projectKey;
            return(Ok(await _itemService.GetItemsAsync(criteria)));
        }
Example #14
0
        async Task <MatchResponse> IOrderingEngine.MatchAsync(ItemCriteria critera)
        {
            var customerProxy = Proxy.ForComponent <ICustomerAccess>(this);
            await customerProxy.FilterAsync(new CustomerCriteria());

            var menuProxy = Proxy.ForComponent <IMenuAccess>(this);
            await menuProxy.FilterAsync(new FilterCriteria());

            return(new MatchResponse());
        }
Example #15
0
        /// <summary>
        /// Fetch ItemList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public ItemList Fetch(ItemCriteria criteria)
        {
            ItemList item = (ItemList)Activator.CreateInstance(typeof(ItemList), true);

            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(item);
            }

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue);
                    command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue);
                    command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue);
                    command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue);
                    command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                    command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue);
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new ItemFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return(item);
        }
Example #16
0
        /// <summary>
        /// Fetch Item.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public Item Fetch(ItemCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(null);
            }

            Item item;

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue);
                    command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue);
                    command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue);
                    command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue);
                    command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                    command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue);
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            item = Map(reader);
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.Item' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            MarkOld(item);
            OnFetched();
            return(item);
        }
Example #17
0
        /// <summary>
        /// Get Items by criteria. Set ItemCriteria fields as null if you don't want to specify the criteria. The result
        /// callback will returns a PagedItems that contains Items within it.
        /// </summary>
        /// <param name="criteria">Criteria to search items</param>
        /// <param name="region">Region of items</param>
        /// <param name="language">Display language</param>
        /// <param name="callback">Returns a Result that contains PagedItems via callback when completed.</param>
        public void GetItemsByCriteria(ItemCriteria criteria, string region, string language,
                                       ResultCallback <PagedItems> callback)
        {
            Assert.IsNotNull(criteria, "Can't get items by criteria; Criteria parameter is null!");
            Assert.IsNotNull(language, "Can't get items by criteria; Language parameter is null!");

            if (!this.user.IsLoggedIn)
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);
                return;
            }

            this.taskDispatcher.Start(
                Task.Retry(
                    cb => this.api.GetItemsByCriteria(this.user.Namespace,
                                                      this.user.AccessToken, region, language, criteria, result => cb(result)),
                    result => this.coroutineRunner.Run(() => callback((Result <PagedItems>)result)),
                    this.user));
        }
Example #18
0
            public IEnumerator SetUp_ExpectedEcommerceStuff()
            {
                Items      items      = AccelBytePlugin.GetItems();
                Categories categories = AccelBytePlugin.GetCategories();
                Result <ItemPagingSlicedResult> getItemResult          = null;
                Result <CategoryInfo[]>         getChildCategoryResult = null;
                ItemCriteria itemCriteria = new ItemCriteria
                {
                    categoryPath = TestVariables.expectedChildCategoryPath,
                    region       = TestVariables.region,
                    language     = TestVariables.language
                };

                items.GetItemsByCriteria(
                    itemCriteria,
                    result =>
                {
                    getItemResult       = result;
                    this.expectedItemId = result.Value.data[0].itemId;
                });

                while (getItemResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                categories.GetChildCategories(
                    TestVariables.expectedChildCategoryPath,
                    TestVariables.language,
                    result => { getChildCategoryResult = result; });

                while (getChildCategoryResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                Assert.That(!getItemResult.IsError);
                Assert.That(!getChildCategoryResult.IsError);
            }
Example #19
0
        /// <summary>
        /// Get Items by criteria. Set ItemCriteria fields as null if you don't want to specify the criteria. The result
        /// callback will returns a ItemPagingSlicedResult that contains Items within it.
        /// </summary>
        /// <param name="criteria">Criteria to search items</param>
        /// <param name="region">Region of items</param>
        /// <param name="language">Display language</param>
        /// <param name="callback">Returns a Result that contains ItemPagingSlicedResult via callback when completed.</param>
        public void GetItemsByCriteria(ItemCriteria criteria,
                                       ResultCallback <ItemPagingSlicedResult> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(criteria, "Can't get items by criteria; Criteria parameter is null!");

            if (!this.session.IsValid())
            {
                callback.TryError(ErrorCode.IsNotLoggedIn);

                return;
            }

            this.coroutineRunner.Run(
                this.api.GetItemsByCriteria(
                    this.@namespace,
                    this.session.AuthorizationToken,
                    criteria,
                    callback));
        }
Example #20
0
            public IEnumerator GetItemByCriteria_ItemTypeBUNDLE_Success()
            {
                Items        items        = AccelBytePlugin.GetItems();
                ItemCriteria itemCriteria = new ItemCriteria {
                    itemType = ItemType.BUNDLE
                };
                Result <ItemPagingSlicedResult> getItemByCriteriaResult = null;

                items.GetItemsByCriteria(
                    itemCriteria,
                    result => { getItemByCriteriaResult = result; });

                while (getItemByCriteriaResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                TestHelper.Assert.IsTrue(!getItemByCriteriaResult.IsError, "Get item by item type BUNDLE failed.");
            }
        /// <summary>
        /// Fetch ItemList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public ItemList Fetch(ItemCriteria criteria)
        {
            ItemList item = (ItemList)Activator.CreateInstance(typeof(ItemList), true);

            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return item;

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue);
                command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue);
                command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue);
                command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue);
                command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue);
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                        {
                            do
                            {
                                item.Add(new ItemFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return item;
        }
        private void Child_Fetch(ItemCriteria criteria)
        {
            bool cancel = false;
            OnFetching(criteria, ref cancel);
            if (cancel) return;

            RaiseListChangedEvents = false;

            // Fetch Child objects.
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Select]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    command.Parameters.AddWithValue("@p_ListPriceHasValue", criteria.ListPriceHasValue);
                command.Parameters.AddWithValue("@p_UnitCostHasValue", criteria.UnitCostHasValue);
                command.Parameters.AddWithValue("@p_SupplierHasValue", criteria.SupplierHasValue);
                command.Parameters.AddWithValue("@p_StatusHasValue", criteria.StatusHasValue);
                command.Parameters.AddWithValue("@p_NameHasValue", criteria.NameHasValue);
                command.Parameters.AddWithValue("@p_ImageHasValue", criteria.ImageHasValue);
                    using(var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if(reader.Read())
                        {
                            do
                            {
                                this.Add(PetShop.Tests.StoredProcedures.Item.GetItem(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            RaiseListChangedEvents = true;

            OnFetched();
        }
Example #23
0
            public IEnumerator GetItemByCriteria_CategoryPathUnspecified_Success()
            {
                Items        items        = AccelBytePlugin.GetItems();
                ItemCriteria itemCriteria = new ItemCriteria();
                Result <ItemPagingSlicedResult> getItemByCriteriaResult = null;

                items.GetItemsByCriteria(
                    itemCriteria,
                    result => { getItemByCriteriaResult = result; });

                while (getItemByCriteriaResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                TestHelper.Assert.IsTrue(!getItemByCriteriaResult.IsError, "Get item by valid criteria failed.");
                TestHelper.Assert.IsTrue(
                    getItemByCriteriaResult.Value.data.Length > 0,
                    "Get item by valid criteria failed.");
            }
Example #24
0
            public IEnumerator GetItemByCriteria_LanguageEmpty_Success()
            {
                Items        items        = AccelBytePlugin.GetItems();
                ItemCriteria itemCriteria = new ItemCriteria {
                    categoryPath = TestVariables.expectedChildCategoryPath,
                    language     = ""
                };
                Result <ItemPagingSlicedResult> getItemByCriteriaResult = null;

                items.GetItemsByCriteria(
                    itemCriteria,
                    result => { getItemByCriteriaResult = result; });

                while (getItemByCriteriaResult == null)
                {
                    Thread.Sleep(100);

                    yield return(null);
                }

                TestHelper.Assert.IsTrue(getItemByCriteriaResult.IsError, "Get item by empty language not failed.");
            }
Example #25
0
        /// <summary>
        /// Fetch ItemList.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public ItemList Fetch(ItemCriteria criteria)
        {
            ItemList item = (ItemList)Activator.CreateInstance(typeof(ItemList), true);

            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(item);
            }

            // Fetch Child objects.
            string commandText = String.Format("SELECT [ItemId], [ProductId], [ListPrice], [UnitCost], [Supplier], [Status], [Name], [Image] FROM [dbo].[Item] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            do
                            {
                                item.Add(new ItemFactory().Map(reader));
                            } while(reader.Read());
                        }
                    }
                }
            }

            MarkOld(item);
            MarkAsChild(item);
            OnFetched();
            return(item);
        }
        protected void DoDelete(ref Item item)
        {
            // If we're not dirty then don't update the database.
            if (!item.IsDirty)
            {
                return;
            }

            // If we're new then don't call delete.
            if (item.IsNew)
            {
                return;
            }

            var criteria = new ItemCriteria {
                ItemId = item.ItemId
            };

            DoDelete(criteria);

            MarkNew(item);
        }
Example #27
0
            public IEnumerator GetItemByCriteria_AppTypeGAME_Success()
            {
                Items        items        = AccelBytePlugin.GetItems();
                ItemCriteria itemCriteria = new ItemCriteria {
                    appType = EntitlementAppType.GAME
                };
                Result <ItemPagingSlicedResult> getItemByCriteriaResult = null;

                items.GetItemsByCriteria(
                    itemCriteria,
                    result => { getItemByCriteriaResult = result; });

                while (getItemByCriteriaResult == null)
                {
                    yield return(null);
                }

                TestHelper.Assert.IsTrue(!getItemByCriteriaResult.IsError, "Get item by item appType GAME failed.");
                if (getItemByCriteriaResult.Value.data.Length > 0)
                {
                    TestHelper.Assert.IsTrue(getItemByCriteriaResult.Value.data[0].appType == EntitlementAppType.GAME, "Get item by item appType GAME failed.");
                }
            }
        /// <summary>
        /// Fetch Item.
        /// </summary>
        /// <param name="criteria">The criteria.</param>
        /// <returns></returns>
        public Item Fetch(ItemCriteria criteria)
        {
            bool cancel = false;

            OnFetching(criteria, ref cancel);
            if (cancel)
            {
                return(null);
            }

            Item   item;
            string commandText = String.Format("SELECT [ItemId], [ProductId], [ListPrice], [UnitCost], [Supplier], [Status], [Name], [Image] FROM [dbo].[Item] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));
                    using (var reader = new SafeDataReader(command.ExecuteReader()))
                    {
                        if (reader.Read())
                        {
                            item = Map(reader);
                        }
                        else
                        {
                            throw new Exception(String.Format("The record was not found in 'dbo.Item' using the following criteria: {0}.", criteria));
                        }
                    }
                }
            }

            MarkOld(item);
            OnFetched();
            return(item);
        }
        private void DoUpdate(ref Item item, bool stopProccessingChildren)
        {
            bool cancel = false;

            OnUpdating(ref cancel);
            if (cancel)
            {
                return;
            }

            // Don't update if the item isn't dirty.
            if (item.IsDirty)
            {
                if (item.OriginalItemId != item.ItemId)
                {
                    // Insert new child.
                    var temp = (Item)Activator.CreateInstance(typeof(Item), true);
                    temp.ItemId    = item.ItemId;
                    temp.ProductId = item.ProductId;
                    temp.ListPrice = item.ListPrice;
                    temp.UnitCost  = item.UnitCost;
                    temp.Supplier  = item.Supplier;
                    temp.Status    = item.Status;
                    temp.Name      = item.Name;
                    temp.Image     = item.Image;
                    temp           = temp.Save();

                    // Mark child lists as dirty. This code may need to be updated to one-to-one relationships.

                    // Update Children
                    Update_Product_Product_FK__Item__ProductId__117F9D94(ref item);
                    Update_SupplierMember_SupplierMember_FK__Item__Supplier__1273C1CD(ref item);

                    // Delete the old.
                    var criteria = new ItemCriteria {
                        ItemId = item.OriginalItemId
                    };

                    Delete(criteria);

                    // Mark the original as the new one.
                    item.OriginalItemId = item.ItemId;

                    MarkOld(item);
                    CheckRules(item);
                    OnUpdated();

                    return;
                }

                const string commandText = "UPDATE [dbo].[Item] SET [ItemId] = @p_ItemId, [ProductId] = @p_ProductId, [ListPrice] = @p_ListPrice, [UnitCost] = @p_UnitCost, [Supplier] = @p_Supplier, [Status] = @p_Status, [Name] = @p_Name, [Image] = @p_Image WHERE [ItemId] = @p_ItemId; SELECT [ItemId] FROM [dbo].[Item] WHERE [ItemId] = @p_OriginalItemId";
                using (var connection = new SqlConnection(ADOHelper.ConnectionString))
                {
                    connection.Open();
                    using (var command = new SqlCommand(commandText, connection))
                    {
                        command.Parameters.AddWithValue("@p_OriginalItemId", item.OriginalItemId);
                        command.Parameters.AddWithValue("@p_ItemId", item.ItemId);
                        command.Parameters.AddWithValue("@p_ProductId", item.ProductId);
                        command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(item.ListPrice));
                        command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(item.UnitCost));
                        command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(item.Supplier));
                        command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(item.Status));
                        command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(item.Name));
                        command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(item.Image));

                        //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed.
                        int result = command.ExecuteNonQuery();
                        if (result == 0)
                        {
                            throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                        }
                    }
                }
            }

            item.OriginalItemId = item.ItemId;

            MarkOld(item);
            CheckRules(item);

            if (!stopProccessingChildren)
            {
                // Update Child Items.
                Update_Product_Product_FK__Item__ProductId__117F9D94(ref item);
                Update_SupplierMember_SupplierMember_FK__Item__Supplier__1273C1CD(ref item);
            }

            OnUpdated();
        }
        //[Transactional(TransactionalTypes.TransactionScope)]
        protected void DataPortal_Delete(ItemCriteria criteria, SqlConnection connection)
        {
            bool cancel = false;
            OnDeleting(criteria, ref cancel);
            if (cancel) return;

            string commandText = String.Format("DELETE FROM [dbo].[Item] {0}", ADOHelper.BuildWhereStatement(criteria.StateBag));
            using (var command = new SqlCommand(commandText, connection))
            {
                command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. 
                int result = command.ExecuteNonQuery();
                if (result == 0)
                    throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
            }

            OnDeleted();
        }
        protected override void DataPortal_Update()
        {
            bool cancel = false;
            OnUpdating(ref cancel);
            if (cancel) return;

            if(OriginalItemId != ItemId)
            {
                // Insert new child.
                Item item = new Item {ItemId = ItemId, ProductId = ProductId, Status = Status, Name = Name, Image = Image};
                                if(ListPrice.HasValue) item.ListPrice = ListPrice.Value;
                if(UnitCost.HasValue) item.UnitCost = UnitCost.Value;
                if(Supplier.HasValue) item.Supplier = Supplier.Value;
                item = item.Save();

                // Mark editable child lists as dirty. This code may need to be updated to one-to-one relationships.

                // Create a new connection.
                using (var connection = new SqlConnection(ADOHelper.ConnectionString))
                {
                    connection.Open();
                    FieldManager.UpdateChildren(this, connection);
                }

                // Delete the old.
                var criteria = new ItemCriteria {ItemId = OriginalItemId};
                
                DataPortal_Delete(criteria);

                // Mark the original as the new one.
                OriginalItemId = ItemId;

                OnUpdated();

                return;
            }

            const string commandText = "UPDATE [dbo].[Item] SET [ItemId] = @p_ItemId, [ProductId] = @p_ProductId, [ListPrice] = @p_ListPrice, [UnitCost] = @p_UnitCost, [Supplier] = @p_Supplier, [Status] = @p_Status, [Name] = @p_Name, [Image] = @p_Image WHERE [ItemId] = @p_OriginalItemId; SELECT [ItemId] FROM [dbo].[Item] WHERE [ItemId] = @p_OriginalItemId";
            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using(var command = new SqlCommand(commandText, connection))
                {
                    command.Parameters.AddWithValue("@p_OriginalItemId", this.OriginalItemId);
                command.Parameters.AddWithValue("@p_ItemId", this.ItemId);
                command.Parameters.AddWithValue("@p_ProductId", this.ProductId);
                command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(this.ListPrice));
                command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(this.UnitCost));
                command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(this.Supplier));
                command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(this.Status));
                command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(this.Name));
                command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(this.Image));

                    //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. 
                    int result = command.ExecuteNonQuery();
                    if (result == 0)
                        throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");

                    LoadProperty(_originalItemIdProperty, this.ItemId);
                }

                FieldManager.UpdateChildren(this, connection);
            }

            OnUpdated();
        }
 public void Delete(ItemCriteria criteria)
 {
     // Note: this call to delete is for immediate deletion and doesn't keep track of any entity state.
     DoDelete(criteria);
 }
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Item"/> object. 
 /// </summary>
 /// <param name="criteria"><see cref="ItemCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(ItemCriteria criteria, ref bool cancel);
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the <see cref="Item"/> object. 
 /// </summary>
 /// <param name="criteria"><see cref="ItemCriteria"/> object containing the criteria of the object to fetch.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param>
 partial void OnFetching(ItemCriteria criteria, ref bool cancel);
        protected void DoDelete(ref Item item)
        {
            // If we're not dirty then don't update the database.
            if (!item.IsDirty) return;

            // If we're new then don't call delete.
            if (item.IsNew) return;
            
            var criteria = new ItemCriteria{ItemId = item.ItemId};
            
            DoDelete(criteria);

            MarkNew(item);
        }
Example #36
0
        public IEnumerator GetItemsByCriteria(string @namespace, string accessToken,
                                              ItemCriteria criteria, ResultCallback <ItemPagingSlicedResult> callback)
        {
            Report.GetFunctionLog(this.GetType().Name);
            Assert.IsNotNull(@namespace, "Can't get items by criteria! Namespace parameter is null!");
            Assert.IsNotNull(accessToken, "Can't get items by criteria! AccessToken parameter is null!");
            Assert.IsNotNull(criteria, "Can't get items by criteria! Criteria parameter is null!");

            var queries = new Dictionary <string, string>();

            if (criteria != null)
            {
                if (criteria.categoryPath != null)
                {
                    queries.Add("categoryPath", criteria.categoryPath);
                }

                if (criteria.itemType != ItemType.NONE)
                {
                    queries.Add("itemType", criteria.itemType.ToString());
                }

                if (criteria.appType != EntitlementAppType.NONE)
                {
                    queries.Add("appType", criteria.appType.ToString());
                }

                if (criteria.region != null)
                {
                    queries.Add("region", criteria.region);
                }

                if (criteria.language != null)
                {
                    queries.Add("language", criteria.language);
                }

                if (criteria.tags != null)
                {
                    string tags = "";
                    for (int i = 0; i < criteria.tags.Length; i++)
                    {
                        tags += (i < criteria.tags.Length - 1 ? criteria.tags[i] + "," : criteria.tags[i]);
                    }
                    queries.Add("tags", tags);
                }

                if (criteria.features != null)
                {
                    string feats = "";
                    for (int i = 0; i < criteria.features.Length; i++)
                    {
                        feats += (i < criteria.features.Length - 1 ? criteria.features[i] + "," : criteria.features[i]);
                    }
                    queries.Add("features", feats);
                }

                if (criteria.offset != null)
                {
                    queries.Add("offset", Convert.ToString(criteria.offset));
                }

                if (criteria.limit != null)
                {
                    queries.Add("limit", Convert.ToString(criteria.limit));
                }
                if (criteria.sortBy != null)
                {
                    queries.Add("sortBy", criteria.sortBy);
                }
            }

            var request = HttpRequestBuilder.CreateGet(this.baseUrl + "/public/namespaces/{namespace}/items/byCriteria")
                          .WithPathParam("namespace", @namespace)
                          .WithQueries(queries)
                          .WithBearerAuth(accessToken)
                          .Accepts(MediaType.ApplicationJson)
                          .GetResult();

            IHttpResponse response = null;

            yield return(this.httpClient.SendRequest(request, rsp => response = rsp));

            var result = response.TryParseJson <ItemPagingSlicedResult>();

            callback.Try(result);
        }
        private void DoUpdate(ref Item item, bool stopProccessingChildren)
        {
            bool cancel = false;
            OnUpdating(ref cancel);
            if (cancel) return;

            // Don't update if the item isn't dirty.
            if (item.IsDirty)
            {
                if(item.OriginalItemId != item.ItemId)
                {
                    // Insert new child.
                    var temp = (Item)Activator.CreateInstance(typeof(Item), true);
                    temp.ItemId = item.ItemId;
                    temp.ProductId = item.ProductId;
                    temp.ListPrice = item.ListPrice;
                    temp.UnitCost = item.UnitCost;
                    temp.Supplier = item.Supplier;
                    temp.Status = item.Status;
                    temp.Name = item.Name;
                    temp.Image = item.Image;
                    temp = temp.Save();
    
                    // Mark child lists as dirty. This code may need to be updated to one-to-one relationships.

                    // Update Children
                    Update_Product_Product_FK__Item__ProductId__117F9D94(ref item);
                    Update_SupplierMember_SupplierMember_FK__Item__Supplier__1273C1CD(ref item);
    
                    // Delete the old.
                    var criteria = new ItemCriteria {ItemId = item.OriginalItemId};
                    
                    Delete(criteria);
    
                    // Mark the original as the new one.
                    item.OriginalItemId = item.ItemId;

                    MarkOld(item);
                    CheckRules(item);
                    OnUpdated();

                    return;
                }

                using (var connection = new SqlConnection(ADOHelper.ConnectionString))
                {
                    connection.Open();
                    using(var command = new SqlCommand("[dbo].[CSLA_Item_Update]", connection))
                    {
                        command.CommandType = CommandType.StoredProcedure;
                        command.Parameters.AddWithValue("@p_OriginalItemId", item.OriginalItemId);
                command.Parameters.AddWithValue("@p_ItemId", item.ItemId);
                command.Parameters.AddWithValue("@p_ProductId", item.ProductId);
                command.Parameters.AddWithValue("@p_ListPrice", ADOHelper.NullCheck(item.ListPrice));
                command.Parameters.AddWithValue("@p_UnitCost", ADOHelper.NullCheck(item.UnitCost));
                command.Parameters.AddWithValue("@p_Supplier", ADOHelper.NullCheck(item.Supplier));
                command.Parameters.AddWithValue("@p_Status", ADOHelper.NullCheck(item.Status));
                command.Parameters.AddWithValue("@p_Name", ADOHelper.NullCheck(item.Name));
                command.Parameters.AddWithValue("@p_Image", ADOHelper.NullCheck(item.Image));

                        //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. 
                        int result = command.ExecuteNonQuery();
                        if (result == 0)
                            throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");

                    }
                }
            }

            item.OriginalItemId = item.ItemId;

            MarkOld(item);
            CheckRules(item);

            if(!stopProccessingChildren)
            {
            // Update Child Items.
                Update_Product_Product_FK__Item__ProductId__117F9D94(ref item);
                Update_SupplierMember_SupplierMember_FK__Item__Supplier__1273C1CD(ref item);
            }

            OnUpdated();
        }
Example #38
0
 /// <summary>
 /// CodeSmith generated stub method that is called when fetching the child <see cref="Item"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="ItemCriteria"/> object containing the criteria of the object to fetch.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object fetching should proceed.</param>
 partial void OnFetching(ItemCriteria criteria, ref bool cancel);
        /// <summary>
        /// This call to delete is for immediate deletion and doesn't keep track of any entity state.
        /// </summary>
        /// <param name="criteria">The Criteria.</param>
        private void DoDelete(ItemCriteria criteria)
        {
            bool cancel = false;
            OnDeleting(criteria, ref cancel);
            if (cancel) return;

            using (var connection = new SqlConnection(ADOHelper.ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand("[dbo].[CSLA_Item_Delete]", connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.AddRange(ADOHelper.SqlParameters(criteria.StateBag));

                    //result: The number of rows changed, inserted, or deleted. -1 for select statements; 0 if no rows were affected, or the statement failed. 
                    int result = command.ExecuteNonQuery();
                    if (result == 0)
                        throw new DBConcurrencyException("The entity is out of date on the client. Please update the entity and try again. This could also be thrown if the sql statement failed to execute.");
                }
            }

            OnDeleted();
        }
 public void Delete(ItemCriteria criteria)
 {
     //Note: this call to delete is for immediate deletion and doesn't keep track of any entity state.
     DoDelete(criteria);
 }
 /// <summary>
 /// CodeSmith generated stub method that is called when deleting the <see cref="Item"/> object.
 /// </summary>
 /// <param name="criteria"><see cref="ItemCriteria"/> object containing the criteria of the object to delete.</param>
 /// <param name="cancel">Value returned from the method indicating whether the object deletion should proceed.</param>
 partial void OnDeleting(ItemCriteria criteria, ref bool cancel);