Beispiel #1
0
        /// <summary>
        /// Creates a new Order record in the Order database table
        /// </summary>
        /// <param name="order"></param>
        public void InsertOrder(ClassLibrary.StoreApplication.Design.Order order)
        {
            using var context = new Project0DBContext(_contextOptions);

            var dbOrder = new Order()
            {
                LocationId = order.LocationId,
                CustomerId = order.CustomerId,
                ProductId  = order.ProductId,
                Quantity   = order.Quantity
            };

            context.Orders.Add(dbOrder);

            context.SaveChanges();
        }
Beispiel #2
0
        /// <summary>
        /// Gets an Order based off of a specific OrderId
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ClassLibrary.StoreApplication.Design.Order GetOrderById(int id)
        {
            using var context = new Project0DBContext(_contextOptions);

            var dbOrders = context.Orders
                           .Include(o => o.Location)
                           .Include(o => o.Customer)
                           .Include(o => o.Product)
                           .First(o => o.OrderId == id);

            var location = new ClassLibrary.StoreApplication.Design.Location(dbOrders.LocationId, dbOrders.Location.Name)
            {
                LocationId = dbOrders.LocationId,
                Name       = dbOrders.Location.Name,
            };

            var customer = new ClassLibrary.StoreApplication.Design.Customer()
            {
                CustomerId = dbOrders.CustomerId,
                FirstName  = dbOrders.Customer.FirstName,
                LastName   = dbOrders.Customer.LastName,
                Email      = dbOrders.Customer.Email
            };

            var product = new ClassLibrary.StoreApplication.Design.Product()
            {
                ProductId = dbOrders.ProductId,
                Title     = dbOrders.Product.Name,
                Price     = dbOrders.Product.Price,
            };

            ClassLibrary.StoreApplication.Design.Order testorder = new ClassLibrary.StoreApplication.Design.Order()
            {
                OrderId    = dbOrders.OrderId,
                CustomerId = customer.CustomerId,
                LocationId = location.LocationId,
                ProductId  = product.ProductId,
                OrderTime  = dbOrders.OrderTime,
                Quantity   = dbOrders.Quantity
            };


            return(testorder);
        }