public async System.Threading.Tasks.Task <ActionResult> Edit([Bind(Include = "OrderId,PublicOrderNum,OrderStatus,StatusList,Buyer,Total,ProductId,CustomerOrderId,Quantity,TrackingId,OrderTime,StatusId,CustomerId")] Order order) { if (ModelState.IsValid) { order.OrderStatus = db.Status.Where(s => s.StatusId == order.StatusId).First(); db.Entry(order).State = EntityState.Modified; db.SaveChanges(); if (order.StatusId == 2) { string subject = "Order processed"; string to = "*****@*****.**"; // normally would use order.buyer.email, but for testing/demo purposes we are hardcoding string body = "Thank you for choosing Painted Plunders!"; APIFucnction.SendSimpleMessage(subject, to, body); } return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customer, "CustomerId", "FirstName", order.CustomerId); ViewBag.StatusId = new SelectList(db.Status, "StatusId", "Name", order.StatusId); return(View(order)); }
public ActionResult Charge(string stripeEmail, string stripeToken) { try { var order = ProcessToDatabase(this.HttpContext); var cart = ShoppingCart.GetCart(this.HttpContext); var cartProduct = cart.GetCartItems(); foreach (var item in cartProduct) { Products product = db.Products.Where(p => p.ProductId == item.ProductId).First(); if (product.InStock == false) { return(RedirectToAction("Index", "Checkout", 1)); } } db.Order.Add(order); db.SaveChanges(); APIFucnction.SendSimpleMessage("Your order has been placed", "*****@*****.**", "Thank you for choosing PaintedPlunders"); foreach (var item in cartProduct) { OrderItem oi = new OrderItem(); oi.OrderId = order.OrderId; oi.Order = order; oi.ProductId = item.ProductId; oi.Product = item.Product; db.OrderItems.Add(oi); db.SaveChanges(); } order.PublicOrderNum = GetRandomizedString(order.OrderId); db.SaveChanges(); var orderList = db.OrderItems.Where(o => o.OrderId == order.OrderId).ToList(); foreach (var item in orderList) { Products product = db.Products.Where(p => p.ProductId == item.ProductId).First(); product.InStock = false; db.SaveChanges(); } cart.EmptyCart(); } catch { return(RedirectToAction("Index", "Checkout", 2)); } var customers = new StripeCustomerService(); var charges = new StripeChargeService(); var customer = customers.Create(new StripeCustomerCreateOptions { Email = stripeEmail, SourceToken = stripeToken }); // Need to not hard code total as amount var charge = charges.Create(new StripeChargeCreateOptions { Amount = 4900,//charge in cents Description = "Sample Charge", Currency = "usd", CustomerId = customer.Id }); return(RedirectToAction("Index", "Home")); }