Beispiel #1
0
        private static Customer GetCustomerByID(NorthwindEntities northwindEntities, string customerID)
        {
            Customer customer = northwindEntities.Customers.FirstOrDefault(
                p => p.CustomerID == customerID);

            return customer;
        }
Beispiel #2
0
 public static void UpdateCustomerRecord(string customerID, string companyName)
 {
     NorthwindEntities northwindEntities = new NorthwindEntities();
     Customer customer = GetCustomerByID(northwindEntities, customerID);
     customer.CompanyName = companyName;
     northwindEntities.SaveChanges();
 }
Beispiel #3
0
 public static void DeleteCustomerRecored(string customerID)
 {
     NorthwindEntities northwindEntities = new NorthwindEntities();
     Customer customer = GetCustomerByID(northwindEntities, customerID);
     northwindEntities.Customers.Remove(customer);
     northwindEntities.SaveChanges();
 }
        public static void Main()
        {
            NorthwindEntities northwindEntities = new NorthwindEntities();

            //DAO.AddCustomerRecord("ddddd","TEsterrrr");

            //DAO.UpdateCustomerRecord("AROUT", "UPDATETEST");

            //DAO.DeleteCustomerRecored("ddddd");
        }
        public static void Main(string[] args)
        {
            NorthwindEntities dbContent = new NorthwindEntities();

            /* 
             * Steps to reproduse the DB:
             * 1. Open SorceModel.edmx
             * 2. Right button click on the empty space between the tables
             * 3. Click Generate Database from model - it will generate a SQL script
             * 4. Edit the USE [Northwind]; to the name of the database you want to clone the current DB to.
             * 5. Run the script;
             */
        }
        public static void Main(string[] args)
        {
            Employee extended = new Employee();

            NorthwindEntities dbContext = new NorthwindEntities();

            extended = dbContext.Employees.Find(1);

            foreach (var item in extended.Territories)
            {
                Console.WriteLine("Teritory description - {0}", item.TerritoryDescription);
            }
        }
Beispiel #7
0
        public static int AddCustomerRecord(string comapnyID, string companyName)
        {
            NorthwindEntities northwindEntities = new NorthwindEntities();
            Customer newCustomer = new Customer
            {
                CustomerID = comapnyID,
                CompanyName = companyName
            };

            northwindEntities.Customers.Add(newCustomer);
            northwindEntities.SaveChanges();
            return int.Parse(newCustomer.CustomerID);
        }
        public static void FindAllClients(int orderDate, string shipDestination)
        {
            using (NorthwindEntities northwindEntities = new NorthwindEntities())
            {
                var searchResult = from order in northwindEntities.Orders
                              where order.OrderDate.Value.Year == orderDate && order.ShipCountry == shipDestination
                              select order;

                foreach (var customer in searchResult)
                {
                    Console.WriteLine("Customer: {0}", customer.Customer.ContactName);
                }
            }
        }
 public static void Main()
 {
     using (NorthwindEntities ent = new NorthwindEntities())
     {
         using (NorthwindEntities entitty = new NorthwindEntities())
         {
             ent.Customers.Add(new Customer() { CustomerID = "xswde", CompanyName = "CONFLICTTEST" });
             entitty.Customers.Add(new Customer() { CustomerID = "xldde", CompanyName = "CONFLICTTEST2" }); 
             entitty.SaveChanges();
             ent.SaveChanges();
             entitty.SaveChanges();
         }
     }
 }
        public static void Main(string[] args)
        {
            using (NorthwindEntities dbContext = new NorthwindEntities())
            {
                var result = dbContext.usp_FindIncome("Exotic Liquids", DateTime.Parse("02/02/1995"), DateTime.Parse("02/02/2000"));

                Console.WriteLine(dbContext.usp_FindIncome("Exotic Liquids", DateTime.Parse("02/02/1995"), DateTime.Parse("02/02/2000")));

                foreach (var item in result)
                {
                    Console.WriteLine("Company Name: {0}, Total Income: {1}", item.CompanyName, item.TotalIncome);
                }
            }
        }
        public static void FindAllClients(int orderDate, string shipDestination)
        {
            using (NorthwindEntities northwindEntities = new NorthwindEntities())
            {
                string searchQuery = @"SELECT c.ContactName from Customers
                                    c INNER JOIN Orders o ON o.CustomerID = c.CustomerID 
                                    WHERE (YEAR(o.OrderDate) = {0} AND o.ShipCountry = {1});";

                object[] queryParams = { orderDate, shipDestination };

                var searchResult = northwindEntities.Database.SqlQuery<string>(searchQuery, queryParams);

                foreach (var customer in searchResult)
                {
                    Console.WriteLine("Customer: {0}", customer);
                }
            }
        }
        public static void AddOrder(string shipName, short amount, int productID, decimal unitPrice, float discount)
        {
            using (NorthwindEntities dbContent = new NorthwindEntities())
            {
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        Order newOrder = new Order { ShipName = shipName };

                        dbContent.Orders.Add(newOrder);
                        dbContent.SaveChanges();

                        var result = dbContent.Orders.Where(x => x.ShipName == shipName);

                        using (NorthwindEntities dbContext = new NorthwindEntities())
                        {
                            foreach (var item in result)
                            {
                                Order_Detail newDetail = new Order_Detail
                                {
                                    OrderID = item.OrderID,
                                    ProductID = productID,
                                    UnitPrice = unitPrice,
                                    Discount = discount,
                                    Quantity = amount,
                                };

                                dbContext.Order_Details.Add(newDetail);
                                dbContext.SaveChanges();
                            }
                        }

                        scope.Complete();
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }
        }
        public static void FindAllSales(int startDate, int endDate, string region)
        {
            using (NorthwindEntities northwindEntities = new NorthwindEntities())
            {
                var searchResult = from order in northwindEntities.Orders
                                   join ordeDetails in northwindEntities.Order_Details
                                   on order.OrderID equals ordeDetails.OrderID
                                   where order.ShipRegion == region
                                   && order.OrderDate.Value.Year == startDate
                                   && order.ShippedDate.Value.Year == endDate
                                   select new 
                                   { 
                                        Amount = ordeDetails.Quantity,
                                        Region = order.ShipRegion,
                                   };

                foreach (var customer in searchResult)
                {
                    Console.WriteLine("Amount: {0}, Region: {1}", customer.Amount, customer.Region);
                }
            }
        }