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

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