public static void InsertCustomer(Customer customer)
 {
     using (var db = new NorthwindEntities())
     {
         if (customer==null)
         {
             throw new ArgumentNullException("Customer cannot be null");
         }
         db.Customers.Add(customer);
         db.SaveChanges();
     }
     Console.WriteLine("Customer added");
 }
Example #2
0
        static void Main()
        {
            //2.Create a DAO class with static methods which provide functionality for inserting, modifying and deleting customers. Write a testing class.

            Customer pesho = new Customer()
            {
                CustomerID = "test",
                ContactName = "Pesho",
                Country = "BG",
                CompanyName = "Pesho OOD"
            };

            CustomersOperations.InsertCustomer(pesho);
            CustomersOperations.ModifyCustomer("test", "Gosho");
            CustomersOperations.DeleteCustomer("test");
        }
Example #3
0
        // TASK 2
        // Create a DAO class with static methods which provide functionality for inserting, modifying and deleting customers.
        // Write a testing class.
        static void Add(string name, string id)
        {
            Customer newCustomer = new Customer()
            {
                CompanyName = name,
                CustomerID = id
            };

            using (NorthwindEntities db = new NorthwindEntities())
            {
                bool isInDB = IsInDataBase(db, id);

                if (!isInDB)
                {
                    db.Customers.Add(newCustomer);
                    db.SaveChanges();
                    Console.WriteLine("Added Successful.");
                }
                else
                {
                    throw new ArgumentException("Such customer already exists");
                }
            }
        }