public IEnumerable <Product> GetRandomProducts(int count) { using (var context = new TBStockDBContext()) { return(context.Products.OrderBy(x => Guid.NewGuid()).Take(count).ToList()); } }
public Product GetProductByProductId(int productId) { using (var context = new TBStockDBContext()) { return(context.Products.FirstOrDefault(x => x.Id == productId)); } }
public Product GetProductByCode(string code) { using (var context = new TBStockDBContext()) { return(context.Products.FirstOrDefault(x => x.Code == code)); } }
public int GetTopProductId() { using (var context = new TBStockDBContext()) { return(context.Products.OrderByDescending(x => x.Id).FirstOrDefault().Id); } }
public IEnumerable <ProductDetail> GetProductDetailsByProductId(int productId) { using (var context = new TBStockDBContext()) { return(context.ProductDetails.Where(x => x.ProductId == productId).ToList()); } }
public int GetProductsCount() { using (var context = new TBStockDBContext()) { return(context.Products.Count()); } }
public void DeleteAllProductsDetails() { using (var context = new TBStockDBContext()) { context.Database.ExecuteSqlCommand("TRUNCATE TABLE [walidaly_TB_Stock].[walid].[ProductDetails]"); } }
public IEnumerable <Product> GetProductsByDepartmentId(int departmentId) { using (var context = new TBStockDBContext()) { return(context.Products.Where(x => x.DepartmentId == departmentId).ToList()); } }
public void DeleteAllProducts() { using (var context = new TBStockDBContext()) { context.Database.ExecuteSqlCommand("DELETE FROM [walidaly_TB_Stock].[walid].[Products]"); } }
public IEnumerable <Product> GetProductsByCategory(string category, ProductDepartment department, int skip, int take) { using (var context = new TBStockDBContext()) { return(context.Products.Where(x => x.Category == category && x.DepartmentId == (int)department).OrderByDescending(x => x.Id).Skip(skip).Take(take).ToList()); } }
public void AddProductsDetails(IEnumerable <ProductDetail> productsDetails) { using (var context = new TBStockDBContext()) { context.ProductDetails.AddRange(productsDetails); context.SaveChanges(); } }
public IEnumerable <DepartmentCategory> GetUniqueCategories() { using (var context = new TBStockDBContext()) { return(context.Products.GroupBy(x => new DepartmentCategory() { DepartmentId = x.DepartmentId, Category = x.Category }).Select(x => new DepartmentCategory() { DepartmentId = x.Key.DepartmentId, Category = x.Key.Category }).ToList()); } }