public static void Main()
        {
            using (var northwind = new NorthwindEntities())
            {
                Customer customer = new Customer();
                customer.Address = "155, Madison Avenue";
                customer.City = "New York";
                customer.CompanyName = "Company";
                customer.Country = "United States";
                customer.CustomerID = "US123";
                customer.ContactName = "James Peterson";

                Console.WriteLine(InsertModifyDeleteCustomers.AddCustomer(northwind, customer));

                Customer anotherCustomer = new Customer();
                anotherCustomer.CustomerID = "US123";
                anotherCustomer.Address = "253, Madison Avenue";
                anotherCustomer.City = "New York";
                anotherCustomer.CompanyName = "Another company";
                anotherCustomer.Country = "United States";
                anotherCustomer.ContactName = "Peter Jameson";
                Console.WriteLine(InsertModifyDeleteCustomers.ModifyCustomerById(northwind, "COMPA", anotherCustomer));

                Console.WriteLine(InsertModifyDeleteCustomers.DeleteCustomer(northwind, anotherCustomer));
            }
        }
        public static string AddCustomer(NorthwindEntities northwind, Customer customer)
        {
            northwind.Customers.Add(customer);
            northwind.SaveChanges();

            return "Customer added";
        }
        public static string DeleteCustomer(NorthwindEntities northwind, Customer newCustomer)
        {
            var selectedCustomer = northwind.Customers.Where(c => c.CustomerID == newCustomer.CustomerID).FirstOrDefault();
            northwind.Customers.Remove(selectedCustomer);
            northwind.SaveChanges();

            return "Customer deleted";
        }
Example #4
0
        public static int InsertCustomer(string contactName, string companyName)
        {
            using (NorthwindEntities db = new NorthwindEntities())
            {

                Customer customer = new Customer()
                {
                    ContactName = contactName,
                    CompanyName = companyName,
                    CustomerID = GetCustomerId(companyName),
                };

                if (IsCustomerExists(db, GetCustomerId(companyName)))
                {
                    throw new ArgumentException("Customer already exist!!!");
                }

                db.Customers.Add(customer);
                return db.SaveChanges();
            }
        }
        public static string ModifyCustomerById(NorthwindEntities northwind, string customerId, Customer newCustomer)
        {
            var selectedCustomer = northwind.Customers.Where(c => c.CustomerID == customerId).FirstOrDefault();

            selectedCustomer.Address = newCustomer.Address;
            selectedCustomer.City = newCustomer.City;
            selectedCustomer.CompanyName = newCustomer.CompanyName;
            selectedCustomer.ContactName = newCustomer.ContactName;
            selectedCustomer.ContactTitle = newCustomer.ContactTitle;
            selectedCustomer.Country = newCustomer.Country;
            selectedCustomer.CustomerDemographics = newCustomer.CustomerDemographics;
            selectedCustomer.Fax = newCustomer.Fax;
            selectedCustomer.Orders = newCustomer.Orders;
            selectedCustomer.Phone = newCustomer.Phone;
            selectedCustomer.PostalCode = newCustomer.PostalCode;
            selectedCustomer.Region = newCustomer.Region;

            northwind.SaveChanges();

            return "Customer modified";
        }
Example #6
0
        public static void AddCustomer(string id, string companyName)
        {
            var customer = new Customer
            {
                CustomerID = id,
                CompanyName = companyName
            };

            NorthwindEntities db = new NorthwindEntities();

            if (!CustomerExistsInDb(db, id))
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                Console.WriteLine("Company added -> {0}", companyName);
            }
            else
            {
                throw new ArgumentException("There is already a person with the same id in the databse!");
            }
        }
 private bool FilterCustomer(Customer entity)
 {
     return (entity.CustomerID == this.CustomerID);
 }
Example #8
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomers(Customer customer)
 {
     base.AddObject("Customers", customer);
 }
Example #9
0
 /// <summary>
 /// Create a new Customer object.
 /// </summary>
 /// <param name="customerID">Initial value of the CustomerID property.</param>
 /// <param name="companyName">Initial value of the CompanyName property.</param>
 public static Customer CreateCustomer(global::System.String customerID, global::System.String companyName)
 {
     Customer customer = new Customer();
     customer.CustomerID = customerID;
     customer.CompanyName = companyName;
     return customer;
 }