Exemple #1
0
 public IActionResult Register(Customers cust)
 {
     _context.Customers.Add(cust);
     _context.SaveChanges();
     HttpContext.Session.SetString("logout", cust.UserName);
     return(RedirectToAction("Login"));
 }
Exemple #2
0
        public ActionResult Feedback(Feedbacks fed)
        {
            _context.Feedbacks.Add(fed);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
        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    amount = (TempData["total"]);
            Orders orders = new Orders()
            {
                OrderPrice = Convert.ToSingle(amount),
                OrderDate  = DateTime.Now,
                CustomerId = c.CustomerId
            };

            _context.Orders.Add(orders);
            _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   = orders.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("Invoice"));
            //}
            //return View();
        }
Exemple #4
0
        public IActionResult Checkout(Customers customer1, string stripeEmail, string stripeToken)
        {
            var c = _context.Customers.Where(x => x.UserName == customer1.UserName).SingleOrDefault();

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

            _context.Orders.Add(orders);

            _context.SaveChanges();
            TempData["orderId"] = orders.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   = orders.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 order     = TempData["orderId"];
            var custt     = TempData["cust"];
            var customer  = customers.Create(new CustomerCreateOptions
            {
                Email       = stripeEmail,
                SourceToken = stripeToken
            });

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

            Payments payment = new Payments();

            {
                payment.PaymentStripeId = charge.PaymentMethodId;
                payment.Amount          = Convert.ToInt32(amount);
                payment.Paymentdate     = System.DateTime.Now;
                payment.CardNo          = Convert.ToInt32(charge.PaymentMethodDetails.Card.Last4);
                payment.OrderId         = Convert.ToInt32(order);
                payment.CustomerId      = Convert.ToInt32(custt);
            }
            //var customerService = new CustomerService();
            //ViewBag.details = charge.PaymentMethodDetails.Card.Last4;
            _context.Add <Payments>(payment);
            _context.Payments.Add(payment);
            _context.SaveChanges();
            TempData["pay"] = payment.PaymentId;

            return(RedirectToAction("Invoice"));
        }