Exemplo n.º 1
0
 /// <summary>
 /// Category Tests
 /// </summary>
 public List <Category> GetCategories()
 {
     using (var db = new NorthwindContex())
     {
         return(db.Categories.ToList());
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 3
0
 public Category GetCategory(int index)
 {
     using (var db = new NorthwindContex())
     {
         return(db.Categories.Find(index));
     }
 }
Exemplo n.º 4
0
 public List <Order> GetOrders()
 {
     using (var db = new NorthwindContex())
     {
         return(db.Orders.ToList());
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Product Tests
 /// </summary>
 ///
 public List <Product> GetProduct()
 {
     using (var db = new NorthwindContex())
     {
         return(db.Products.ToList());
     }
 }
Exemplo n.º 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());
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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());
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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);
            }
        }