Exemple #1
0
 /// <summary>
 /// Category Tests
 /// </summary>
 public List <Category> GetCategories()
 {
     using (var db = new NorthwindContex())
     {
         return(db.Categories.ToList());
     }
 }
Exemple #2
0
 public bool DeleteCategory(int id)
 {
     try
     {
         using (var db = new NorthwindContex())
         {
             var delCat = new Category()
             {
                 Id = id
             };
             db.Categories.Attach(delCat);
             db.Categories.Remove(delCat);
             db.SaveChanges();
             if (delCat != null)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception) { } return(false);
 }
Exemple #3
0
 public Category GetCategory(int index)
 {
     using (var db = new NorthwindContex())
     {
         return(db.Categories.Find(index));
     }
 }
Exemple #4
0
 public List <Order> GetOrders()
 {
     using (var db = new NorthwindContex())
     {
         return(db.Orders.ToList());
     }
 }
 /// <summary>
 /// Product Tests
 /// </summary>
 ///
 public List <Product> GetProduct()
 {
     using (var db = new NorthwindContex())
     {
         return(db.Products.ToList());
     }
 }
Exemple #6
0
        public List <Product> GetProductByName(String productName)
        {
            using (var db = new NorthwindContex())
            {
                var product = db.Products.Where(x => x.Name.ToLower().Contains(productName.ToLower()));

                return(product.ToList());
            }
        }
Exemple #7
0
 /// <summary>
 /// Product Tests
 /// </summary>
 public Product GetProduct(int productId)
 {
     using (var db = new NorthwindContex())
     {
         var product = db.Products
                       .Include(x => x.Category)
                       .FirstOrDefault(x => x.Id == productId);
         return(product);
     }
 }
Exemple #8
0
 public List <OrderDetails> GetOrderDetailsByOrderId(int orderid)
 {
     using (var db = new NorthwindContex())
     {
         return(db.OrderDetails
                .Include(x => x.Product)
                .Where(x => x.OrderId == orderid)
                .ToList());
     }
 }
Exemple #9
0
 //not done
 public Order GetOrder(int id)
 {
     using (var db = new NorthwindContex())
     {
         return(db.Orders.Include(x => x.OrderDetails).
                ThenInclude(x => x.Product).
                ThenInclude(x => x.Category)
                .FirstOrDefault(x => x.Id == id));
     }
 }
Exemple #10
0
 public List <OrderDetails> GetOrderDetailsByProductId(int id)
 {
     using (var db = new NorthwindContex())
     {
         return(db.OrderDetails
                .Include(x => x.Order)
                .Where(x => x.ProductId == id)
                .OrderBy(x => x.Order.Date)
                .ToList());
     }
 }
Exemple #11
0
 public List <Product> GetProductByCategory(int categoryId)
 {
     using (var db = new NorthwindContex())
     {
         var products = db.Products
                        .Include(x => x.Category)
                        .Where(x => x.Category.Id == categoryId)
                        .ToList();
         return(products);
     }
 }
 public bool UpdateCategory(int categoryId, String name, String description)
 {
     using (var db = new NorthwindContex())
     {
         var category = db.Categories.FirstOrDefault(x => x.Id == categoryId);
         if (category != null)
         {
             category.Name        = name;
             category.Description = description;
             db.SaveChanges();
             return(true);
         }
         return(false);
     }
 }
Exemple #13
0
 public Category CreateCategory(string name, string description)
 {
     using (var db = new NorthwindContex())
     {
         var count  = GetCategories();
         var newCat = new Category()
         {
             Id          = count.Count() + 1,
             Name        = name,
             Description = description
         };
         db.Categories.Add(newCat);
         db.SaveChanges();
         return(newCat);
     }
 }
        public bool DeleteCategory(int id)
        {
            using (var db = new NorthwindContex())
            {
                var category = db.Categories.FirstOrDefault(x => x.Id == id);

                if (category != null)
                {
                    db.Categories.Remove(category);

                    db.SaveChanges();

                    return(true);
                }
                return(false);
            }
        }