コード例 #1
0
        public async Task <IActionResult> CheckoutCart()
        {
            /// <summary>
            /// Adds cart items to orderitems db then empties cart
            /// </summary>
            List <OrderItemViewModel> CurrentCart = (List <OrderItemViewModel>)_cache.Get("customerCart");

            foreach (OrderItemViewModel thisOIVM in CurrentCart)
            {
                //OrderItem(int CustomerIdIn, int LocationIdIn, int ProductIdIn, double TotalPriceWhenOrderedIn, int OrderCountIn)
                OrderItem thisOrderItem = new OrderItem(
                    thisOIVM.CustomerId,
                    thisOIVM.LocationId,
                    thisOIVM.ProductId,
                    thisOIVM.TotalPriceWhenOrdered,
                    thisOIVM.OrderCount
                    );
                _context.Add(thisOrderItem);
                _context = UtilMethods.DecrementStockItem(thisOrderItem, _context);
            }
            await _context.SaveChangesAsync();

            System.Diagnostics.Debug.WriteLine($"Orders updated");
            _cache.Set("customerCart", new List <OrderItemViewModel>());
            return(Redirect("/Home/History"));
        }
コード例 #2
0
        public async Task <EIGENAAR> VoegToe(EIGENAAR eigenaar)
        {
            _dbContextClass.Add(eigenaar);
            await _dbContextClass.SaveChangesAsync();

            return(eigenaar);
        }
コード例 #3
0
        public async Task <IActionResult> Register([Bind("CustomerId,UserName,FirstName,LastName,Password,DateAdded")] Customer customer)
        {
            /// <summary>
            /// Registers a new customer
            /// </summary>
            if (ModelState.IsValid)
            {
                Customer checkCust = UtilMethods.GetCustomerByUserName(customer.UserName, _context);
                if (checkCust.UserName != null)
                {
                    System.Diagnostics.Debug.WriteLine($"Customer with user name {customer.UserName} already exists");
                    return(Redirect("/Login/Register?warn=duplicate"));
                }
                else
                {
                    customer.DateAdded = DateTime.Now;
                    _context.Add(customer);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(customer));
        }