コード例 #1
0
 public static OrderModel Create(Order order)
 {
     return new OrderModel
     {
         CustomerID = order.CustomerID,
         IsShipped = order.ShippedDate.HasValue,
         OrderID = order.OrderID,
         ShipCity = order.ShipCity
     };
 }
コード例 #2
0
        /* 09. Create a method that places a new order in the Northwind database. The order should contain several order items. Use transaction to ensure the data consistency.*/
        /// <summary>
        /// Mains this instance.
        /// </summary>
        public static void Main()
        {
            var order = new Order
            {
                CustomerID = "TOMSP",
                EmployeeID = 1,
                Freight = 5M,
                OrderDate = new DateTime(1995, 12, 11),
                RequiredDate = new DateTime(1995, 12, 30),
                ShipAddress = "Ship Address",
                ShipCity = "Ship City",
                ShipCountry = "Ship Country",
                ShipName = "Ship Name"
            };

            AddOrderMultipleTimes(order);
            Console.WriteLine("DONE!");
        }
コード例 #3
0
        /// <summary>
        /// Adds an order multiple times to the db. Transaction demo.
        /// </summary>
        /// <param name="order">The order.</param>
        private static void AddOrderMultipleTimes(Order order)
        {
            using (var northwindDbContext = new NorthwindEntities())
            {
                northwindDbContext.Orders.Add(order);
                northwindDbContext.Orders.Add(order);
                northwindDbContext.Orders.Add(order);

                //// Uncomment to see transaction power!
                // order.CustomerID = "PESHO_ZLIA";
                northwindDbContext.Orders.Add(order);
                northwindDbContext.Orders.Add(order);

                try
                {
                    northwindDbContext.SaveChanges();
                }
                catch (Exception)
                {
                    Console.WriteLine("Error! Orders not confirmed!");
                }
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: bahtev/TelerikAcademy
        private static void PlaceNewOrder(
            int orderId, string customerId = null,
            int? employeeId = null, DateTime? orderDate = null,
            DateTime? requireDate = null, DateTime? shippedDate = null,
            int? shipVia = null, decimal? freight = null,
            string shipName = null, string shipAddress = null,
            string shipCity = null, string shipRegion = null,
            string shipPostalCode = null, string shipCountry = null)
        {
            //9. Create a method that places a new order in the Northwind database. The order 
            //should contain several order items. Use transaction to ensure the data consistency.

            using (NorthwindEntities dbContext = new NorthwindEntities())
            {
                Order newOrder = new Order()
                {
                    CustomerID = customerId,
                    EmployeeID = employeeId,
                    Freight = freight,
                    OrderDate = orderDate,
                    OrderID = orderId,
                    RequiredDate = requireDate,
                    ShipAddress = shipAddress,
                    ShipCity = shipCity,
                    ShipCountry = shipCountry,
                    ShipName = shipName,
                    ShippedDate = shippedDate,
                    ShipPostalCode = shipPostalCode,
                    ShipRegion = shipRegion,
                    ShipVia = shipVia,
                };

                dbContext.Orders.Add(newOrder);

                dbContext.SaveChanges();
            }
        }