public async Task <ActionResult> Create([Bind(Include = "Id,Name,Price,Size")] Product product) { if (ModelState.IsValid) { db.Products.Add(product); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(product)); }
public async Task <ActionResult> Create([Bind(Include = "PlanId,Category")] Plan plan) { if (ModelState.IsValid) { db.Plans.Add(plan); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(plan)); }
public async Task <ActionResult> Create([Bind(Include = "PartnerId,Name,Address,Country,Description,ImageUrl,Longitude,Latitude")] Partner partner) { if (ModelState.IsValid) { db.Partners.Add(partner); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(partner)); }
public async Task <ActionResult> Create([Bind(Include = "Id,Title,Description,PlanId,PartnerId")] Subscription subscription) { if (ModelState.IsValid) { db.Subscriptions.Add(subscription); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.PartnerId = new SelectList(db.Partners, "PartnerId", "Name", subscription.PartnerId); ViewBag.PlanId = new SelectList(db.Plans, "PlanId", "Category", subscription.PlanId); return(View(subscription)); }
// GET: Signature public async Task <ActionResult> UploadSignature(string imageData) { var signature = new Signature() { ImageData = imageData }; db.Signatures.Add(signature); await db.SaveChangesAsync(); string fileNameWitPath = DateTime.Now.ToString().Replace("/", "").Replace(" ", " ").Replace(":", "") + ".png"; string path = Path.Combine(Server.MapPath("~/SignatureImages/"), fileNameWitPath); using (FileStream fs = new FileStream(path, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(imageData); bw.Write(data); bw.Close(); } } return(RedirectToAction("About", "Home")); }
public async Task SaveAsync() { await _context.SaveChangesAsync(); }
public async Task <ActionResult> Checkout() { var cart = CreateOrGetCart(); if (cart.CartItems.Any()) { // Flat rate shipping int shipping = 0; // Flat rate tax 10% var taxRate = 0; var subtotal = cart.CartItems.Sum(x => x.Price * x.Quantity); var tax = Convert.ToInt32((subtotal + shipping) * taxRate); var total = subtotal + shipping + tax; // Create an Order object to store info about the shopping cart var order = new Entities.EshopEntities.Order() { OrderDate = DateTime.UtcNow, Subtotal = subtotal, Shipping = shipping, Tax = tax, Total = total, OrderItems = cart.CartItems.Select(x => new OrderItem() { Name = x.Name, Price = x.Price, Quantity = x.Quantity }).ToList() }; _dbContext.Orders.Add(order); await _dbContext.SaveChangesAsync(); // Get PayPal API Context using configuration from web.config var apiContext = GetApiContext(); // Create a new payment object var payment = new Payment { intent = "sale", payer = new Payer { payment_method = "paypal" }, transactions = new List <Transaction> { new Transaction { description = $"AKK Charity Shopping Cart Purchase", amount = new Amount { currency = "EUR", total = (order.Total / 1M).ToString(), // PayPal expects string amounts, eg. "20.00", details = new Details() { subtotal = (order.Subtotal / 1M).ToString(), shipping = (order.Shipping / 1M).ToString(), tax = (order.Tax / 1M).ToString() } }, item_list = new ItemList() { items = order.OrderItems.Select(x => new Item() { description = x.Name, currency = "EUR", quantity = x.Quantity.ToString(), price = (x.Price / 1M).ToString(), // PayPal expects string amounts, eg. "20.00" }).ToList() } } }, redirect_urls = new RedirectUrls { return_url = Url.Action("Return", "Eshop", null, Request.Url.Scheme), cancel_url = Url.Action("Cancel", "Eshop", null, Request.Url.Scheme) } }; // Send the payment to PayPal var createdPayment = payment.Create(apiContext); // Save a reference to the paypal payment order.PayPalReference = createdPayment.id; await _dbContext.SaveChangesAsync(); // Find the Approval URL to send our user to var approvalUrl = createdPayment.links.FirstOrDefault( x => x.rel.Equals("approval_url", StringComparison.OrdinalIgnoreCase)); // Send the user to PayPal to approve the payment return(Redirect(approvalUrl.href)); } return(RedirectToAction("Cart")); }