Ejemplo n.º 1
0
 public static void InsertCustomer(Customer customer)
 {
     using (var dbContext = new NorthwindEntities())
     {
         dbContext.Customers.Add(customer);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 2
0
        public static void InsertCustomer(string customerID, string companyName)
        {
            using (NorthwindEntities northwindDBContext = new NorthwindEntities())
            {
                Customer customer = new Customer
                {
                    CustomerID = customerID,
                    CompanyName = companyName,
                };

                northwindDBContext.Customers.Add(customer);
                northwindDBContext.SaveChanges();

                Console.WriteLine("Customer is inserted");
            }
        }
Ejemplo n.º 3
0
        public static void ModifyCustomer(Customer customer)
        {
            using (var dbContext = new NorthwindEntities())
            {
                var obsoleteCustomer = dbContext
                    .Customers
                    .Where(x => x.CustomerID == customer.CustomerID)
                    .FirstOrDefault();

                if (obsoleteCustomer == null)
                {
                    throw new ArgumentNullException("No such user in database!");
                }

                dbContext.Customers.Remove(obsoleteCustomer);
                dbContext.Customers.Add(customer);
                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        public static void Main()
        {
            using (var dbContext = new NorthwindEntities())
            {
                var customer = new Customer()
                {
                    CustomerID = "ZAZA",
                    CompanyName = "Mad House LTD",
                    ContactName = "Mad Man",
                    ContactTitle = "Owner",
                };

                DataAccessUtils.InsertCustomer(customer);

                customer.Country = "Bulgaria";
                DataAccessUtils.ModifyCustomer(customer);

                DataAccessUtils.DeleteCustomer(customer.CustomerID);
            }
        }
        static void Main()
        {
            DAO.InsertCustomer("BUBLA", "SamsaraBeach");
            Customer customer = new Customer
            {
                CustomerID = "BUBLA",
                CompanyName = "SamsaraBeach",
                ContactName = "Samuel",
                ContactTitle = "God",
                Address = "Everywhere",
                City = "CityOfGod",
                Region = "Earth",
                PostalCode = "123",
                Country = "Atlantice",
                Phone = "555 Banana Drive",
                Fax = "nah"
            };

            DAO.UpdateCustomer("BUBLA", customer);
            DAO.DeleteCustomer("BUBLA");
        }
Ejemplo n.º 6
0
        public static void UpdateCustomer(string customerID, Customer newCustomer)
        {
            using (NorthwindEntities northwindDBContext = new NorthwindEntities())
            {
                Customer customer = northwindDBContext.Customers.First(x => x.CustomerID == customerID);

                customer.CompanyName = newCustomer.CompanyName;
                customer.ContactName = newCustomer.ContactName;
                customer.ContactTitle = newCustomer.ContactTitle;
                customer.Address = newCustomer.Address;
                customer.City = newCustomer.City;
                customer.Region = newCustomer.Region;
                customer.PostalCode = newCustomer.PostalCode;
                customer.Country = newCustomer.Country;
                customer.Phone = newCustomer.Phone;
                customer.Fax = newCustomer.Fax;

                northwindDBContext.SaveChanges();

                Console.WriteLine("Customer is updated.");
            }
        }