public void GetProductCategoryById_IncludeParent_Success() { // Arrange CreateTestData(); // Act ProductCategory result; using (var context = new TinyShoppingCartDbContext(_options)) { context.Database.UseTransaction(_transaction); var repository = new ProductCategoryRepository(context); IQueryInclude queryObj = new QueryInclude { IncludeProperties = "Parent" }; result = repository.GetById(3, queryObj); } // Assert Assert.NotNull(result); Assert.Equal <int>(3, result.Id); Assert.True(result.Name == "Clothes"); Assert.NotNull(result.Parent); Assert.Equal <string>("Men", result.Parent.Name); }
public override IListResult <TEntity> Execute(IContext dataContext) { var query = dataContext.AsQueryable <TEntity>(); if (QueryInclude != null) { query = QueryInclude.Include(query); } foreach (var queryFilter in QueryFilters) { query = queryFilter.Filter(query); } if (Filter != null) { query = query.Where(Filter); } var total = query.Count(); var data = query.SortAndPage(SortDictionary, Request); return(new ListResult <TEntity>(data.ToList(), Request) { Total = total }); }
public void GetProductCategoryById_HaveTracking_Success() { // Arrange CreateTestData(); // Act ProductCategory result; using (var context = new TinyShoppingCartDbContext(_options)) { context.Database.UseTransaction(_transaction); var repository = new ProductCategoryRepository(context); IQueryInclude queryObj = new QueryInclude { IsTracking = true }; result = repository.GetById(3, queryObj); result.Name = "Test"; context.SaveChanges(); result = repository.GetById(3, queryObj); } // Assert Assert.NotNull(result); Assert.Equal <int>(3, result.Id); Assert.True(result.Name == "Test"); Assert.Null(result.Parent); }
public EditProductCategoryDTO GetDataForEdit(int productCategoryId) { // Get product category without tracking by EF IQueryInclude queryObj = new QueryInclude { IsTracking = false }; var entity = _unitOfWork.ProductCategoryRepository.GetById(productCategoryId, queryObj); if (entity == null) { return(null); } EditProductCategoryDTO dto = _mapper.Map <ProductCategory, EditProductCategoryDTO>(entity); if (dto == null) { return(null); } // Get all parent categories that does not contain the editing product catetory dto.ParentCategories = GetFullTree(productCategoryId); return(dto); }
public virtual Response <string> GetJSON(IdPartialRequest request, IQueryInclude <TEntity> includeQuery = null) { var response = new Response <string>(); var queryInclude = new QueryInclude <TEntity>(request); var result = Get(request, queryInclude.IsValid ? queryInclude : includeQuery ?? _queryInclude); response.Merge(result); return(response); }
public override IResult <bool> Execute(IContext dataContext) { var query = dataContext.AsQueryable <T>(); if (QueryInclude != null) { query = QueryInclude.Include(query); } return(_invertPredicate ? new Result <bool>(!query.Any(Predicate)) : new Result <bool>(query.Any(Predicate))); }
public bool Delete(int productCategoryId) { IQueryInclude queryObj = new QueryInclude { IsTracking = false }; var fullData = _unitOfWork.ProductCategoryRepository.GetAll(queryObj).ToList(); var productCategory = fullData.SingleOrDefault(c => c.Id == productCategoryId); if (productCategory == null) { return(false); } DeleteChildCategories(fullData, productCategory.Id); _unitOfWork.ProductCategoryRepository.Delete(productCategory); _unitOfWork.Commit(); return(true); }