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"); }
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"); }
// 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"); } } }