/// <summary> /// get the same product made by different companies /// the resulted products will have the same category /// </summary> /// <param name="product"></param> /// <returns></returns> public static IEnumerable <Product> _SimilarProductsByCompany(this Product product) { var _context = ServiceHelper.GetDbContext(); return(_context.Products .Where( p => p.id != product.id && p.name == product.name && p.categoryId == product.categoryId)); }
/// <summary> /// get all products of category and products of it's child /// </summary> /// <param name="category"></param> /// <returns></returns> public static IEnumerable <Product> _allProductsOfChilds(this Category category) { var products = new List <Product>(); if (category.SubCategories.Count() == 0) { return(ServiceHelper.GetDbContext().Products.Where(p => p.categoryId == category.id)); } foreach (var c in category.SubCategories) { products.AddRange(c._allProductsOfChilds()); } return(products); }
/// <summary> /// check if any of parents of specified category match specified id /// </summary> /// <param name="category"></param> /// <param name="id"></param> /// <returns></returns> public static bool AnyParentCategoryHasId(this Category category, Guid id) { if (category.superId == null) { return(false); } if (category.superId == id) { return(true); } if (category.SuperCategory != null) { return(category.SuperCategory.AnyParentCategoryHasId(id)); } else { return(ServiceHelper.GetDbContext() .Categories.FirstOrDefault(c => c.id == category.superId) .AnyParentCategoryHasId(id)); } }
public static IApplicationBuilder UseDefaultSeededData(this IApplicationBuilder app) { ServiceHelper.GetDbContext().Database.Migrate(); MainConfigHelper.SeedDefaultedData(); return(app); }
public static void SeedDefaultedData() { DBHelper.ResetData(ServiceHelper.GetDbContext()).Wait(); InitialSeeds.SeedRequireds().Wait(); Seeder.SeedToAllTables(); }