コード例 #1
0
        public static void InsertCustomer(Customer customer)
        {
            ExecuteCommandSafely(
                databaseContext =>
                    {
                        if (CustomerExists(databaseContext, customer.CustomerID))
                        {
                            throw new ArgumentException(
                                "Unable to add the customer with this ID because there's already a customer with this ID.");
                        }

                        databaseContext.Customers.Add(customer);
                    });
        }
コード例 #2
0
        private static void Main()
        {
            const string CustumerId = "DIMPE";
            var customer = new Customer
                                  {
                                      CustomerID = CustumerId,
                                      CompanyName = "Telerik Academy",
                                      ContactName = "Dimo Petrov",
                                      ContactTitle = "sir",
                                      Address = "Stara Planina 12",
                                      City = "Yambol",
                                      Region = "Yambol",
                                      PostalCode = "8600",
                                      Country = "Bulgaria",
                                      Phone = "09821421",
                                      Fax = "09821421"
                                  };

            CustomerDao.InsertCustomer(customer);
            Console.WriteLine("Customer successfully added!");
            CustomerDao.DeleteCustumer(CustumerId);
            Console.WriteLine("Customer successfully deleted!");
        }