Exemplo n.º 1
0
 public void CreatedCategory(Category category)
 {
     using (var db = new NorthwindConnect())
     {
         db.Categories.Add(category);
         db.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public Category CreateCategory(string v1, string v2)
 {
     using (var db = new NorthwindConnect())
     {
         var category = new Category(v1, v2);
         db.Categories.Add(category);
         db.SaveChanges();
         return(db.Categories.Last());
     }
 }
Exemplo n.º 3
0
 static void Main(string[] args)
 {
     Console.WriteLine("check ");
     using (var db = new NorthwindConnect())
     {
         var service = new DataService();
         // var category = service.CreateCategory("Test", "CreateCategory_ValidData_CreteCategoryAndRetunsNewObject");
         service.CreatedCategory(new Category("we", "sfs"));
         Console.WriteLine("check ");
     }
 }
Exemplo n.º 4
0
 /*Product methods*/
 public Product GetProduct(int productId)
 {
     using (var db = new NorthwindConnect())
     {
         var product = db.Products.Find(productId);
         if (product == null)
         {
             return(null);
         }
         return(product);
     }
 }
Exemplo n.º 5
0
        /*category methods*/

        /*
         * @int v id-number of categary
         * @return Category with the id number given.
         */
        public Category GetCategory(int categoryId)
        {
            using (var db = new NorthwindConnect())
            {
                var category = db.Categories.Find(categoryId);
                if (category == null)
                {
                    return(null);
                }
                return(category);
            }
        }
Exemplo n.º 6
0
 public List <Product> GetProductByCategory(int categoryId)
 {
     using (var db = new NorthwindConnect())
     {
         IEnumerable <Product> products = db.Products.Where(s => s.CategoryId == categoryId)
                                          .Select(s => new Product
         {
             Name = s.Name
         });
         return(products.ToList());
     }
 }
Exemplo n.º 7
0
 public List <Product> GetProductByName(string productName)
 {
     using (var db = new NorthwindConnect())
     {
         IEnumerable <Product> products = db.Products.Where(s => s.Name.Contains(productName))
                                          .Select(s => new Product
         {
             Name = s.Name
         });
         return(products.ToList());
     }
 }
Exemplo n.º 8
0
        /*public void DeleteCategory(object id)
         * {
         *  using (var db = new NorthwindConnect())
         *  {
         *      db.Categories.Remove(db.Categories.Find(id));
         *      db.SaveChanges();
         *  }
         * }*/

        public bool DeleteCategory(int id)
        {
            using (var db = new NorthwindConnect())
            {
                var category = db.Categories.Find(id);
                if (category == null)
                {
                    return(false);
                }
                db.Categories.Remove(db.Categories.Find(id));
                db.SaveChanges();
                return(true);
            }
        }
Exemplo n.º 9
0
 public bool UpdateCategory(int id, string name, string description)
 {
     using (var db = new NorthwindConnect())
     {
         var category = db.Categories.Find(id);
         if (category == null)
         {
             return(false);
         }
         category.Id          = id;
         category.Name        = name;
         category.Description = description;
         db.SaveChanges();
         return(true);
     }
 }
Exemplo n.º 10
0
        public List <Category> GetCategories()
        {
            var db = new NorthwindConnect();

            return(db.Categories.ToList());
        }