示例#1
0
 /// <summary>
 /// Category Tests
 /// </summary>
 public List <Category> GetCategories()
 {
     using (var db = new NorthwindContex())
     {
         return(db.Categories.ToList());
     }
 }
示例#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);
 }
示例#3
0
 public Category GetCategory(int index)
 {
     using (var db = new NorthwindContex())
     {
         return(db.Categories.Find(index));
     }
 }
示例#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());
     }
 }
示例#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());
            }
        }
示例#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);
     }
 }
示例#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());
     }
 }
示例#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));
     }
 }
示例#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());
     }
 }
示例#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);
     }
 }
示例#12
0
 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);
     }
 }
示例#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);
     }
 }
示例#14
0
        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);
            }
        }