Exemple #1
0
        public string Insert(Customer customer)
        {
            using (var dbContext = new NorthwindEntities())
            {
                dbContext.Customers.Add(customer);
                dbContext.SaveChanges();

                return customer.CustomerID;
            }
        }
Exemple #2
0
 public void Delete(string id)
 {
     using (var dbContext = new NorthwindEntities())
     {
         var customer = dbContext.Customers.FirstOrDefault(c => c.CustomerID == id);
         if (customer != null)
         {
             dbContext.Customers.Remove(customer);
             dbContext.SaveChanges();
         }
     }
 }
Exemple #3
0
 public void Update(string id, string newCompanyName)
 {
     using (var dbContext = new NorthwindEntities())
     {
         var customer = dbContext.Customers.FirstOrDefault(c => c.CustomerID == id);
         if (customer != null)
         {
             customer.CompanyName = newCompanyName;
             dbContext.SaveChanges();
         }
     }
 }
Exemple #4
0
        public string Insert(string customerID, string companyName)
        {
            using(var dbContext = new NorthwindEntities())
            {
                var customer = new Customer()
                {
                    CustomerID = customerID,
                    CompanyName = companyName,
                };

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

                return customer.CustomerID;
            }
        }