Пример #1
0
        /// <summary>
        /// Creates a new Customer record in the Customer database table
        /// </summary>
        /// <param name="customer"></param>
        public void InsertCustomer(ClassLibrary.StoreApplication.Design.Customer customer)
        {
            using var context = new Project0DBContext(_contextOptions);

            var dbCustomer = new Customer()
            {
                FirstName = customer.FirstName,
                LastName  = customer.LastName,
                Email     = customer.Email
            };

            context.Customers.Add(dbCustomer);

            context.SaveChanges();
        }
Пример #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);
        }