Esempio n. 1
0
        public void PlaceOrder(project0Context context)
        {
            List <Orderlist> orderlists = new List <Orderlist>();
            int orderId = GetTheLastOrderId(context) + 1;

            Console.WriteLine("What is the customerId:");

            string cs = Console.ReadLine();
            int    custId;

            if (!int.TryParse(cs, out custId))
            {
                Console.WriteLine("We don't have you in our system");
            }
            else
            {
                char stop = 'A';
                do
                {
                    orderlists.Add(AddProductToOrder(context, custId, orderId));
                    Console.WriteLine("Contnue shopping enter and letter or enter E to stop:");
                    string str = Console.ReadLine();
                    if (str != "")
                    {
                        stop = str[0];
                    }
                } while (stop != 'E');
            }

            Orders order = new Orders()
            {
                UserId    = custId,
                Total     = sumTotal,
                OrderDate = DateTime.Now
            };

            context.Add(order);
            context.SaveChanges();
            context.Add(orderlists);
            context.SaveChanges();

            /*foreach(Orderlist ol in orderlists)
             * {
             *  context
             * }*/
        }
        public async Task <IActionResult> Create([Bind("CustomerId,FirstName,LastName,Date")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(customer));
        }
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,Price,Date")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
        public async Task <IActionResult> Create([Bind("InventoryId,StoreId,ProductId,Stock")] Inventory inventory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(inventory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "ProductName", inventory.ProductId);
            ViewData["StoreId"]   = new SelectList(_context.Stores, "StoreId", "StoreName", inventory.StoreId);
            return(View(inventory));
        }
Esempio n. 5
0
        public void AddProduct(Library.Product product)
        {
            using var context = new project0Context(_dbContext);

            var dbProduct = new Product()
            {
                Name  = product.Name,
                Price = product.Price
            };

            context.Add(dbProduct);
            context.SaveChanges();
        }
Esempio n. 6
0
        /// <summary>
        /// Adds order to a particular customer
        /// </summary>
        /// <param name="order">Order Added</param>
        public void AddOrderByCustomerId(int customerId, int productId, int locationId, int quantity)
        {
            using var context = new project0Context(_dbContext);
            var dbOrders = new DataModel.Order()
            {
                CustomerId    = customerId,
                ProductId     = productId,
                LocationId    = locationId,
                OrderQuantity = quantity,
            };

            context.Add(dbOrders);
            context.SaveChanges();
        }
Esempio n. 7
0
        /// <summary>
        /// Adds a customer
        /// </summary>
        /// <param name="customer">Added customer</param>
        public void AddCustomer(Library.Customer customer)
        {
            using var context = new project0Context(_dbContext);

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

            context.Add(dbCustomer);
            context.SaveChanges();
        }
Esempio n. 8
0
        public void AddOrderItem(Library.OrderDetail orderItem)
        {
            using var context = new project0Context(_dbContext);

            var dbItem = new OrderDetail()
            {
                OrderId   = orderItem.OrderId,
                ProductId = orderItem.ProductId,
                Quantity  = orderItem.Quantity
            };

            context.Add(dbItem);
            context.SaveChanges();
        }
        public void AddCustomer(string FirstName, string LastName)
        {
            /*using*/ var context = new project0Context(_dbContext);

            if (FirstName.Length > 0 && LastName.Length > 0)
            {
                Customer customer = new Customer()
                {
                    FirstName = FirstName,
                    LastName  = LastName
                };

                context.Add(customer);
                context.SaveChanges();
            }
        }
Esempio n. 10
0
        public void AddLocation(string name)
        {
            // get the context of the db
            using var context = new project0Context(_dbContext);

            if (name.Length > 0)
            {
                // create the db model to add
                Location location = new Location()
                {
                    Name = name
                };

                //add location to context and save
                context.Add(location);
                context.SaveChanges();
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Adds order to a particular customer
        /// </summary>
        /// <param name="order">Order Added</param>
        public void AddOrderByCustomerId(int customerId, int locationId)
        {
            using var context = new project0Context(_dbContext);
            var appOrders = new Library.Order()
            {
                CustomerId = customerId,
                LocationId = locationId,
            };
            var dbOrders = new DataModel.Order()
            {
                CustomerId = appOrders.CustomerId,
                LocationId = appOrders.LocationId,
                // OrderDetails.Quantity = quantity,
            };

            context.Add(dbOrders);
            context.SaveChanges();
        }
Esempio n. 12
0
        /// <summary>
        /// Adding new customer to the database
        /// input: customer object
        /// output: void
        /// </summary>
        /// <param name="ncustomer"></param>

        public void AddCustomer(project0Context context)
        {
            //using project0Context context = new project0Context();
            Customers customer = new Customers();

            //get the first name of the customer
            Console.WriteLine("Enter the customers first name:");
            customer.FirstName = Console.ReadLine();
            //get the customer last name
            Console.WriteLine("Enter the customers Last name:");
            customer.LastName = Console.ReadLine();
            //get the street address
            Console.WriteLine("Enter the customers Street address:");
            customer.StreetAddress = Console.ReadLine();

            //get the city address
            Console.WriteLine("Enter the customers City Address:");
            customer.CityAddress = Console.ReadLine();

            //get the state address
            Console.WriteLine("Enter the customers Sate Address:");
            customer.StateAddress = Console.ReadLine();

            //get the country address
            Console.WriteLine("Enter the customers Country Address:");
            customer.CountryAddress = Console.ReadLine();

            //get the username
            Console.WriteLine("Enter the customers username:"******"Enter the customers password:");
            customer.PassWord = Console.ReadLine();

            customer.RegDate = DateTime.Now;

            context.Add(customer);
            context.SaveChanges()
            ;
        }
Esempio n. 13
0
        public Order AddOrder(Library.Order order)
        {
            using var context = new project0Context(_dbContext);

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

            //var appOrder = new Library.Order()
            //{
            //    CustomerId = dbOrder.CustomerId,
            //    LocationId = dbOrder.LocationId,
            //    Date = dbOrder.Date
            //};

            context.Add(dbOrder);
            context.SaveChanges();

            return(GetOrderById(dbOrder.OrderId));
        }