public IActionResult Create(Customers customer)
 {
     _context.Customers.Add(customer);
     _context.SaveChanges();
     HttpContext.Session.SetString("Logout", customer.Username);
     return(RedirectToAction("Login"));
 }
        public IActionResult Feedback(Feedbacks fed)
        {
            Customers c = SessionHelper.GetObjectFromJson <Customers>(HttpContext.Session, "cust");

            fed.CustomerId = c.CustomerId;
            context.Feedbacks.Add(fed);
            context.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public IActionResult Checkout(Customers customer)
        {
            var c = _context.Customers.Where(x => x.Username == customer.Username).SingleOrDefault();

            c.FirstName = customer.FirstName;
            c.LastName  = customer.LastName;
            c.Username  = customer.Username;
            c.EmailId   = customer.EmailId;
            c.Address   = customer.Address;
            c.PhoneNo   = customer.PhoneNo;
            c.Country   = customer.Country;
            c.State     = customer.State;
            c.Zip       = customer.Zip;
            _context.SaveChanges();
            var    price = TempData["total"];
            Orders order = new Orders()
            {
                OrderPrice = Convert.ToSingle(price),
                OrderDate  = DateTime.Now,
                CustomerId = c.CustomerId
            };

            _context.Orders.Add(order);
            _context.SaveChanges();
            var cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");
            List <OrderProducts> OrderProducts = new List <OrderProducts>();

            for (int i = 0; i < cart.Count; i++)
            {
                OrderProducts orderProducts = new OrderProducts()
                {
                    OrderId   = order.OrderId,
                    ProductId = cart[i].products.ProductId,
                    Quantity  = cart[i].Quantity
                };
                OrderProducts.Add(orderProducts);
            }
            OrderProducts.ForEach(n => _context.OrderProducts.Add(n));
            _context.SaveChanges();
            TempData["cust"] = c.CustomerId;
            return(RedirectToAction("Index", "payment"));
        }
        public IActionResult Charge(string stripeEmail, string stripeToken)
        {
            var customers = new CustomerService();
            var charges   = new ChargeService();
            var checkout  = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");

            ViewBag.checkout = checkout;
            ViewBag.total    = checkout.Sum(item => item.products.ProductPrice * item.Quantity);
            var customer = customers.Create(new CustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount      = 500,
                Description = "Sample Charge",
                Currency    = "usd",
                CustomerId  = customer.Id
            });
            Payments payment = new Payments();

            {
                payment.PaymentStripeId = charge.PaymentMethodId;
                payment.Amount          = ViewBag.total;
                payment.Date            = System.DateTime.Now;
                payment.CardNo          = Convert.ToInt32(charge.PaymentMethodDetails.Card.Last4);
                payment.OrderId         = 5;
                payment.CustomerId      = 1;
            }

            _context.Add <Payments>(payment);
            _context.Payments.Add(payment);
            _context.SaveChanges();


            //var customerservice = new CustomerService();
            //ViewBag.details = charge.PaymentMethodDetails.Card.Last4;

            return(RedirectToAction("Invoice", "Cart"));
        }
Exemple #5
0
        public IActionResult Checkout(Customers customer, string stripeEmail, string stripeToken)
        {
            //int custId = int.Parse(TempData["cust"].ToString());
            //Customers customers = context.Customers.Where(x => x.CustomerId == custId).SingleOrDefault();
            //ViewBag.Customers = customers;
            //if (ModelState.IsValid)
            //{
            var c = _context.Customers.Where(x => x.Username == customer.Username).SingleOrDefault();

            c.FirstName = customer.FirstName;
            c.LastName  = customer.LastName;
            c.Username  = customer.Username;
            c.EmailId   = customer.EmailId;
            c.Address   = customer.Address;
            c.PhoneNo   = customer.PhoneNo;
            c.Country   = customer.Country;
            c.State     = customer.State;
            c.Zip       = customer.Zip;
            _context.SaveChanges();
            var    price = TempData["total"];
            Orders order = new Orders()
            {
                OrderPrice = Convert.ToSingle(price),
                OrderDate  = DateTime.Now,
                CustomerId = c.CustomerId
            };

            _context.Orders.Add(order);
            _context.SaveChanges();
            TempData["orderId"] = order.OrderId;
            var cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");
            List <OrderProducts> OrderProducts = new List <OrderProducts>();

            for (int i = 0; i < cart.Count; i++)
            {
                OrderProducts orderProducts = new OrderProducts()
                {
                    OrderId   = order.OrderId,
                    ProductId = cart[i].products.ProductId,
                    Quantity  = cart[i].Quantity
                };
                OrderProducts.Add(orderProducts);
            }
            OrderProducts.ForEach(n => _context.OrderProducts.Add(n));
            _context.SaveChanges();
            TempData["cust"] = c.CustomerId;
            var customers = new CustomerService();
            var charges   = new ChargeService();
            var Amount    = TempData["total"];
            var orders    = TempData["orderId"];
            var custt     = TempData["cust"];
            var customer1 = customers.Create(new CustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

            var charge = charges.Create(new ChargeCreateOptions
            {
                Amount      = 500,
                Description = "Sample Charge",
                Currency    = "usd",
                CustomerId  = customer1.Id
            });

            Payments payment = new Payments();

            {
                payment.PaymentStripeId = charge.PaymentMethodId;
                payment.Amount          = Convert.ToInt32(Amount);
                payment.Date            = System.DateTime.Now;
                payment.CardNo          = Convert.ToInt32(charge.PaymentMethodDetails.Card.Last4);
                payment.OrderId         = Convert.ToInt32(orders);
                payment.CustomerId      = Convert.ToInt32(custt);
            }

            _context.Add <Payments>(payment);
            _context.Payments.Add(payment);
            _context.SaveChanges();
            TempData["pay"] = payment.PaymentId;
            return(RedirectToAction("Invoice"));
        }