예제 #1
0
        public Customer Select(Guid customerId)
        {
            var db = new Models.OrdersEntities();

            Models.Customer customer = (from d in db.Customers where d.Id == customerId select d).Single();

            db.Dispose();

            return(new Customer(customer));
        }
예제 #2
0
        public void Delete(Guid orderId)
        {
            var db = new Models.OrdersEntities();

            var del = (from d in db.Orders where d.Id == orderId select d).Single();

            db.Orders.Remove(del);
            db.SaveChanges();

            db.Dispose();
        }
예제 #3
0
        public void Update()
        {
            var db = new Models.OrdersEntities();

            Models.Customer customer = (from d in db.Customers where d.Id == this.Model.Id select d).Single();

            customer.FirstName = this.Model.FirstName;
            customer.LastName  = this.Model.LastName;

            db.SaveChanges();

            db.Dispose();
        }
예제 #4
0
        public SortedDictionary <System.Guid, Models.Customer> SelectAll()
        {
            var dict = new SortedDictionary <System.Guid, Models.Customer>();
            var db   = new Models.OrdersEntities();

            db.Configuration.LazyLoadingEnabled = false;

            IOrderedQueryable query = from C in db.Customers orderby C.LastName select C;

            foreach (Models.Customer item in query)
            {
                dict.Add(item.Id, item);
            }

            db.Dispose();

            return(dict);
        }
예제 #5
0
        public Guid Insert(Guid customerId, string referenceNumber, decimal orderValue)
        {
            var db = new Models.OrdersEntities();

            var order = new Models.Order {
                Id              = Guid.NewGuid(),
                CustomerId      = customerId,
                ReferenceNumber = referenceNumber,
                OrderValue      = orderValue,
                OrderDate       = DateTime.Now
            };

            db.Orders.Add(order);
            db.SaveChanges();

            db.Dispose();

            return(order.Id);
        }
예제 #6
0
        public SortedDictionary <System.Guid, GenesisBusiness.Order> SelectAll()
        {
            var dict = new SortedDictionary <System.Guid, GenesisBusiness.Order>();
            var db   = new Models.OrdersEntities();

            db.Configuration.LazyLoadingEnabled = false;

            //KF: There are several ways that the Orders can be combined with the Customer data to return the Customer names.

            //The orders Entity Framework could load the data using lazy-loading.  However in a display grid every orders customer would be loaded
            //one at a time.  For a large grid the performance hit would be quite large.  If several tables data were used in the grid the performance hit
            //would be even larger.

            //The customer data could be selected separately and then knitted into the grid using the customer id and CustomUnboundColumnData.  This method is most suitable
            //for static data that can be cached in memory.  For instance Customer or Order type.  This method reduces the amount of data returned from the database and so
            //improves performance.

            //I have chosen to write a stored procedure that returns the data that the grid needs.  As not every customer is needed and the data is not static it is the
            //most suitable method.


            var orders = db.SelectAllOrdersWithCustomers();

            foreach (Models.spr_SelectAllOrdersWithCustomers_Result item in orders)
            {
                Order order = new Order(item);
                order.Parent = this;

                dict.Add(item.OrderId, order);
            }

            db.Dispose();

            this.Dictionary = dict;

            return(dict);
        }