// POST: Orders/Create // To protect from overposting attacks, please enable the specific properties you want to bind to, for // more details see http://go.microsoft.com/fwlink/?LinkId=317598. public async Task <IActionResult> PaypalCheckout(string name, string email, string surname) { Random r = new Random(); int num = r.Next(); var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); string sessionID = HttpContext.Session.Id; List <Product> cart = SessionHelper.GetObjectFromJson <List <Product> >(HttpContext.Session, sessionID); Order order = new Order(); int totalPrice = 0; for (int i = cart.Count() - 1; i >= 0; i--) { totalPrice = totalPrice + cart[i].ProductPrice; } if (userId == null) { order = new Order { OrderId = num, TotalPrice = totalPrice, FirstName = name, SurName = surname, Email = email, Username = null, }; } else { order = new Order { OrderId = num, TotalPrice = totalPrice, FirstName = name, SurName = surname, Email = email, Username = userId, }; } EmailService m = new EmailService(); m.sendEmailAsync(order.Email); if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction("CreateOrder", "OrderItems", new { id = num })); } return(RedirectToAction("CreateOrder", "OrderItems", new { id = num })); }
public async Task <IActionResult> CreateOrder(int id) { string sessionID = HttpContext.Session.Id; var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); List <Product> cart = SessionHelper.GetObjectFromJson <List <Product> >(HttpContext.Session, sessionID); if (ModelState.IsValid) { for (int i = cart.Count() - 1; i >= 0; i--) { OrderItem order = new OrderItem { OrderItemName = cart[i].ProductName, OrderItemPrice = cart[i].ProductPrice, OrderId = id, }; _context.Add(order); } await _context.SaveChangesAsync(); SessionHelper.SetObjectAsJson(HttpContext.Session, sessionID, null); return(RedirectToAction("Thanksfororder", "Orders")); } // ViewData["OrderId"] = new SelectList(_context.Order, "OrderId", "OrderId", orderItem2.OrderId); return(RedirectToAction("Thanksfororder", "Orders")); }
public async Task <IActionResult> Create([Bind("ProductId,ProductName,ProductPrice,ProductCategory,ProductSubCategory")] Product product, IList <IFormFile> fil) { if (ModelState.IsValid) { var files = HttpContext.Request.Form.Files; foreach (var Image in files) { if (Image != null && Image.Length > 0) { var file = Image; //There is an error here var uploads = Path.Combine(he.WebRootPath, "wwwroot\\images\\", file.FileName); if (file.Length > 0) { var fileName = Guid.NewGuid().ToString().Replace("-", "") + Path.GetExtension(file.FileName); using (var stream = new FileStream(uploads, FileMode.Create)) { await file.CopyToAsync(stream); } } } } _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }