Exemple #1
0
 public IEnumerable <Product> GetRandomProducts(int count)
 {
     using (var context = new TBStockDBContext())
     {
         return(context.Products.OrderBy(x => Guid.NewGuid()).Take(count).ToList());
     }
 }
Exemple #2
0
 public Product GetProductByProductId(int productId)
 {
     using (var context = new TBStockDBContext())
     {
         return(context.Products.FirstOrDefault(x => x.Id == productId));
     }
 }
Exemple #3
0
 public Product GetProductByCode(string code)
 {
     using (var context = new TBStockDBContext())
     {
         return(context.Products.FirstOrDefault(x => x.Code == code));
     }
 }
Exemple #4
0
 public int GetTopProductId()
 {
     using (var context = new TBStockDBContext())
     {
         return(context.Products.OrderByDescending(x => x.Id).FirstOrDefault().Id);
     }
 }
Exemple #5
0
 public IEnumerable <ProductDetail> GetProductDetailsByProductId(int productId)
 {
     using (var context = new TBStockDBContext())
     {
         return(context.ProductDetails.Where(x => x.ProductId == productId).ToList());
     }
 }
Exemple #6
0
 public int GetProductsCount()
 {
     using (var context = new TBStockDBContext())
     {
         return(context.Products.Count());
     }
 }
Exemple #7
0
 public void DeleteAllProductsDetails()
 {
     using (var context = new TBStockDBContext())
     {
         context.Database.ExecuteSqlCommand("TRUNCATE TABLE [walidaly_TB_Stock].[walid].[ProductDetails]");
     }
 }
Exemple #8
0
 public IEnumerable <Product> GetProductsByDepartmentId(int departmentId)
 {
     using (var context = new TBStockDBContext())
     {
         return(context.Products.Where(x => x.DepartmentId == departmentId).ToList());
     }
 }
Exemple #9
0
 public void DeleteAllProducts()
 {
     using (var context = new TBStockDBContext())
     {
         context.Database.ExecuteSqlCommand("DELETE FROM [walidaly_TB_Stock].[walid].[Products]");
     }
 }
Exemple #10
0
 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());
     }
 }
Exemple #11
0
        public void AddProductsDetails(IEnumerable <ProductDetail> productsDetails)
        {
            using (var context = new TBStockDBContext())
            {
                context.ProductDetails.AddRange(productsDetails);

                context.SaveChanges();
            }
        }
Exemple #12
0
 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());
     }
 }