예제 #1
0
        public ProductCategory Create(ProductCategory productCategory)
        {
            if (productCategory == null)
            {
                throw new ArgumentNullException("productCategory");
            }

            if (productCategory.Id == Guid.Empty)
            {
                productCategory.Id = Guid.NewGuid();
            }

            if (productCategory.ProductId == Guid.Empty)
            {
                throw new ArgumentNullException("ProductId");
            }

            if (productCategory.CategoryId == Guid.Empty)
            {
                throw new ArgumentNullException("CategoryId");
            }

            using (var connection = context.CreateConnection())
            {
                connection.Execute(ProductCategoryQuery.Insert(productCategory));
                return(productCategory);
            }
        }
예제 #2
0
 public ProductCategory GetById(Guid id)
 {
     using (var connection = context.CreateConnection())
     {
         return(connection.Query <ProductCategory>(ProductCategoryQuery.ById(id)).SingleOrDefault());
     }
 }
예제 #3
0
 public IEnumerable <Category> GetCategoriesByProductId(Guid id)
 {
     using (var connection = context.CreateConnection())
     {
         return(connection.Query <Category>(ProductCategoryQuery.CategoriesByProductId(id)));
     }
 }
예제 #4
0
 public IEnumerable <Product> GetProductsByCategoryId(Guid id)
 {
     using (var connection = context.CreateConnection())
     {
         return(connection.Query <Product>(ProductCategoryQuery.ProductsByCategoryId(id)));
     }
 }
예제 #5
0
 public void Delete(Guid id)
 {
     using (var connection = context.CreateConnection())
     {
         connection.Execute(ProductCategoryQuery.Delete(id));
     }
 }
예제 #6
0
 public ProductCategory Update(ProductCategory productCategory)
 {
     using (var connection = context.CreateConnection())
     {
         connection.Execute(ProductCategoryQuery.Update(productCategory));
         return(productCategory);
     }
 }
예제 #7
0
        /// <summary>
        /// Test Find using the Query class
        /// </summary>
        private void Step_30_TestFindByQuery_Generated()
        {
            using (TransactionManager tm = CreateTransaction())
            {
                //Insert Mock Instance
                ProductCategory mock   = CreateMockInstance(tm);
                bool            result = DataRepository.ProductCategoryProvider.Insert(tm, mock);

                Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed");

                ProductCategoryQuery query = new ProductCategoryQuery();

                query.AppendEquals(ProductCategoryColumn.ProductCategoryId, mock.ProductCategoryId.ToString());
                query.AppendEquals(ProductCategoryColumn.Name, mock.Name.ToString());
                query.AppendEquals(ProductCategoryColumn.Rowguid, mock.Rowguid.ToString());
                query.AppendEquals(ProductCategoryColumn.ModifiedDate, mock.ModifiedDate.ToString());

                TList <ProductCategory> results = DataRepository.ProductCategoryProvider.Find(tm, query);

                Assert.IsTrue(results.Count == 1, "Find is not working correctly.  Failed to find the mock instance");
            }
        }
예제 #8
0
        public async Task <IHttpActionResult> Get([FromUri] ProductCategoryQuery query)
        {
            var serviceRes = await _productCatService.Get(new ProductCategoryListRequest()
            {
                RequestOwner = User,
                Query        = query ?? new ProductCategoryQuery()
            });

            IHttpActionResult res = BadRequest();

            if (serviceRes.Access == ResponseAccess.Granted)
            {
                res = Ok(serviceRes.Categories);
            }

            if (serviceRes.Access == ResponseAccess.Deny)
            {
                res = Unauthorized(serviceRes.Message);
            }

            return(res);
        }
 private static IQueryable <ProductCategory> FilterByCategoryType(this IQueryable <ProductCategory> categories,
                                                                  ProductCategoryQuery query)
 {
     return(query.CheckByType ? categories.Where(x => x.CategoryType == query.CategoryType || x.CategoryType == CategoryType.Mixed) : categories);
 }
 public static IQueryable <ProductCategory> FilterByQuery(this IQueryable <ProductCategory> categories,
                                                          ProductCategoryQuery query)
 {
     return(categories.FilterByCategoryType(query).FilterByMapTreeView(query.MapForTreeView));
 }