public async Task <IActionResult> Create([Bind("PaymentId,CartId,CustomerId,NameOnCard,CardNumber,Expiration,Cvv")] Payment payment)
        {
            var cartContext = _context.Cart.Include(p => p.Customer).Where(p => p.CustomerId == Convert.ToInt32(HttpContext.Session.GetString("CustomerID"))).FirstOrDefault();;

            payment.CustomerId = Convert.ToInt32(HttpContext.Session.GetString("CustomerID"));
            payment.CartId     = cartContext.Id;
            var paymentContext = _context.Payment;

            if (paymentContext == null)
            {
                payment.PaymentId = 1;
            }
            else
            {
                payment.PaymentId = paymentContext.Max(p => p.PaymentId) + 1;
            }

            if (ModelState.IsValid)
            {
                _context.Add(payment);

                HttpContext.Session.SetString("TotalItem", "0");

                var _cart = _context.Cart.Where(p => p.CustomerId == Convert.ToInt32(HttpContext.Session.GetString("CustomerID"))).FirstOrDefault();

                // _context.Cart.Remove(_cart);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartId"]     = new SelectList(_context.Cart, "Id", "Id", payment.CartId);
            ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "Password", payment.CustomerId);
            return(View(payment));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("AdminId,Name,Password")] Admin admin)
        {
            if (ModelState.IsValid)
            {
                _context.Add(admin);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(admin));
        }
        public async Task <IActionResult> Create([Bind("DepartmentName")] Departments departments)
        {
            if (ModelState.IsValid)
            {
                _context.Add(departments);
                await _context.SaveChangesAsync();

                TempData["Message"] = "Category created succesfully! ";
                return(RedirectToAction("ProductCategories", "Admins"));
            }
            return(View(departments));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("TransactionId,ProductId,Quantity,CustomerId,PurchaseDate,Total")] Purchases purchases)
        {
            if (ModelState.IsValid)
            {
                _context.Add(purchases);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "Password", purchases.CustomerId);
            ViewData["ProductId"]  = new SelectList(_context.Products, "ProductId", "CostUnit", purchases.ProductId);
            return(View(purchases));
        }
        public async Task <IActionResult> Create([Bind("CustomerName,CustomerEmail,Password")] Customers customers)
        {
            var cust_contex = _context.Customers;
            int id          = cust_contex.Max(p => p.CustomerId);

            customers.CustomerId = id + 1;
            if (ModelState.IsValid)
            {
                _context.Add(customers);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Index", "Home"));
        }
        public async Task <IActionResult> Create([Bind("CustomerFirstName,CustomerLastName,Address,City,PostalCode,PhoneNumber,CustomerEmail,Password")] Customers customers)
        {
            var cust_contex = _context.Customers;
            int id          = cust_contex.Max(p => p.CustomerId);

            customers.CustomerId = id + 1;
            if (ModelState.IsValid)
            {
                _context.Add(customers);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Register", "Home"));
        }
        public async Task <IActionResult> Create([Bind("ProductId,ProductName,PricePerCostUnit,CostUnit,DepartmentName,QuantityInStock,Brand,ProductionDate,BestBeforeDate,Plu,Upc,Organic,Cut,Animal")] Products products)
        {
            var prodContext = _context.Products;
            int id          = prodContext.Max(p => p.ProductId);

            products.ProductId = id + 1;
            if (ModelState.IsValid)
            {
                _context.Add(products);
                await _context.SaveChangesAsync();

                TempData["Message"] = products.ProductName + " has been created succesfully!";
                return(RedirectToAction("Products", "Admins"));
            }
            ViewData["DepartmentName"] = new SelectList(_context.Departments, "DepartmentName", "DepartmentName", products.DepartmentName);
            return(View(products));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("productId, CustomerID")] Cart _cart)
        {
            if (Request.Query["PID"].Any() && Request.Query["CustID"].Any())
            {
                _cart.ProductId  = Convert.ToInt32(Request.Query["PID"]);
                _cart.CustomerId = Convert.ToInt32(Request.Query["CustID"]);
            }


            if (ModelState.IsValid)
            {
                _context.Add(_cart);
                await _context.SaveChangesAsync();

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

            /*ViewData["CustomerId"] = new SelectList(_context.Customers, "CustomerId", "Password", cart.CustomerId);
             * ViewData["ProductId"] = new SelectList(_context.Products, "ProductId", "CostUnit", cart.ProductId);*/
            return(View(_cart));
        }