Пример #1
0
        public async Task <IActionResult> Create([Bind("CustomerId,FirstName,LastName,Email,Password,CreatedAt,DisplayDate")] Customer customer, String ConfirmPassword)
        {
            if (customer.Password != ConfirmPassword)
            {
                System.Console.WriteLine("DAMN HOMIE your passwords dont match **************************");
                ViewBag.PasswordError = $"Password doesn't match";
                return(View("Create"));
            }

            if (ModelState.IsValid)
            {
                PasswordHasher <Customer> Hasher = new PasswordHasher <Customer>();
                customer.Password = Hasher.HashPassword(customer, customer.Password);
                Customer ExistingUser = _context.Customer.SingleOrDefault(u => u.Email == customer.Email);
                if (ExistingUser != null)
                {
                    System.Console.WriteLine(" *************EMAIL ALREADY IN USE**********************");
                    ViewBag.AlreadyInUseEmail = true;
                    //ViewBag.AlreadyInUseEmail = $"{customer.Email} is already in the Data base";
                    return(View("Create"));
                }
                else
                {
                    _context.Add(customer);
                    await _context.SaveChangesAsync();

                    HttpContext.Session.SetString("user", customer.Email);
                    // grabs all reviews from database
                    return(RedirectToAction(nameof(Index)));
                }
            }
            return(View(customer));
        }
Пример #2
0
        public async Task <IActionResult> Delete(int id)
        {
            var currItem = await _shoppingAppContext.CartItems.FindAsync(id);

            _shoppingAppContext.CartItems.Remove(currItem);
            await _shoppingAppContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("ProductId,Name,ImageUrl,Description,InitialQuantity")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(product));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("OrderId,CustomerId,AmountOrdered,ProductId,OrderedAt,DisplayDate")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "CustomerId", order.CustomerId);
            ViewData["ProductId"]  = new SelectList(_context.Product, "ProductId", "ProductId", order.ProductId);
            return(View(order));
        }
Пример #5
0
        public async Task <IActionResult> AddToCart(CartItem newCartItem)
        {
            //_logger.LogInformation($"cart item id: {cartItem.CartItemId}");
            //_logger.LogInformation($"Product ID: {cartItem.ProductId}");
            //_logger.LogInformation($"Quantity: {cartItem.Quantity}");
            //_logger.LogInformation($"Product Name: {cartItem.ProductName}");
            //_logger.LogInformation($"Product Cost: {cartItem.ProductCost}");
            //_logger.LogInformation($"Product Cost: {cartItem.ShoppingCartId}");

            var existingItem = _shoppingAppContext.CartItems.Where(cartItem => cartItem.ProductId == newCartItem.ProductId).FirstOrDefault();

            if (existingItem != null)
            {
                existingItem.Quantity += newCartItem.Quantity;
                _shoppingAppContext.Update(existingItem);
            }
            else
            {
                await _shoppingAppContext.CartItems.AddAsync(newCartItem);
            }

            await _shoppingAppContext.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(Product product)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    _shoppingAppContext.Products.Add(product);
                    await _shoppingAppContext.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    throw;
                }

                return(RedirectToAction("Index"));
            }

            var categoryList = _shoppingAppContext.Categories.ToList();

            ViewData["categoryList"] = categoryList;

            return(View(product));
        }
Пример #7
0
        //add new category
        public async Task <Category> Addcategory(string category_name)
        {
            Category newcategory = new Category
            {
                Category_name = category_name
            };

            using (var context = new ShoppingAppContext(ShoppingAppContext.ops.dbOptions))
            {
                await context.AddAsync(newcategory);

                await context.SaveChangesAsync();
            }

            return(newcategory);
        }
        // returns true if new cart was created for the user
        public async Task <bool> CreateShoppingCartIfNotExists()
        {
            var userId = _userManager.GetUserId(User);

            var cart = _shoppingAppContext.ShoppingCarts.Where(cart => cart.UserId == userId).FirstOrDefault();

            // cart for user does not exist already
            if (cart == null)
            {
                ShoppingCart newCart = new ShoppingCart
                {
                    UserId = userId
                };

                await _shoppingAppContext.ShoppingCarts.AddAsync(newCart);

                await _shoppingAppContext.SaveChangesAsync();

                return(true);
            }

            return(false);
        }
Пример #9
0
 public async Task <int> CommitAsync(CancellationToken cancellationToken = default)
 {
     return(await _shoppingAppContext.SaveChangesAsync(cancellationToken));
 }