Ejemplo n.º 1
0
        static void DeleteEntry(string id)
        {
            var database = new NorthwindEntities();

            using (database)
            {
                if (EntryExists(database, id))
                {
                    var itemToDelete = database.Customers.Where(c => c.CustomerID == id).First();
                    database.Customers.Remove(itemToDelete);
                    database.SaveChanges();
                    Console.WriteLine("Entry successfully deleted.");
                }
                else
                {
                    Console.WriteLine("Item with the id \"{0}\" does not exist in the database.", id);
                }
            }
        }
Ejemplo n.º 2
0
        static void AddEntry(string id, string name)
        {
            var database = new NorthwindEntities();

            using (database)
            {
                if (EntryExists(database, id))
                {
                    Console.WriteLine("There is already an entry with the same ID");
                }
                else
                {
                    var newCustomer = new Customer()
                    {
                        CustomerID = id,
                        CompanyName = name
                    };

                    database.Customers.Add(newCustomer);
                    database.SaveChanges();
                    Console.WriteLine("Entry successfully added.");
                }
            }
        }
Ejemplo n.º 3
0
        static void ModifyEntry(string id, string newName)
        {
            var database = new NorthwindEntities();

            using (database)
            {
                if (EntryExists(database, id))
                {
                    var itemToDelete = database.Customers.Where(c => c.CustomerID == id).First();
                    itemToDelete.CompanyName = newName;
                    database.SaveChanges();
                    Console.WriteLine("Entry successfully modified.");
                }
                else
                {
                    Console.WriteLine("Item with the id \"{0}\" does not exist in the database.", id);
                }
            }
        }