public async Task <IActionResult> PayBill() { List <string> data = new List <string>(); List <int> dataq = new List <int>(); List <int> dataid = new List <int>(); float total = 0; string dataAs = HttpContext.Session.GetString("QUALITYPRODUCT"); data.AddRange(dataAs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); for (int i = 0; i < data.Count; i++) { dataq.Add(Convert.ToInt32(data[i].Split(new char[] { '/' }).Last())); dataid.Add(Convert.ToInt32(data[i].Split(new char[] { '/' }).First())); //calculate total price total += dataq[i] * _context.Souvenirs.Where(so => so.SouvenirID == dataid[i]).Select(p => p.SouPrice).First(); } var s = _context.Souvenirs.Where(so => dataid.Contains(so.SouvenirID)); string id = HttpContext.Session.GetString("QUALITYIDSTRING"); var order = new Order(); order.UserID = Convert.ToInt32(id); order.OrdDate = DateTime.Now; order.OrdStatus = "Waiting"; order.OrdCost = total; _context.Add(order); await _context.SaveChangesAsync(); for (int i = 0; i < dataq.Count; i++) { var souvenir = _context.Souvenirs.Where(so => so.SouvenirID == dataid[i]).First(); souvenir.SouQuantity = souvenir.SouQuantity - dataq[i]; var orderitem = new OrderItem(); orderitem.OrderID = order.OrderID; orderitem.SouvenirID = dataid[i]; orderitem.OrdItemQ = dataq[i]; _context.Add(orderitem); _context.Update(souvenir); } await _context.SaveChangesAsync(); HttpContext.Session.SetString("QUALITYPRODUCT", ""); HttpContext.Session.SetInt32("CartCount", 0); return(View("~/Views/Cart/PayBill.cshtml")); }
public async Task <IActionResult> Create(PSouvenir souvenir) { if (ModelState.IsValid) { var sou = new Souvenir(); using (var ms = new MemoryStream()) { await souvenir.image.CopyToAsync(ms); sou.SouImage = ms.ToArray(); sou.SouQuantity = souvenir.SouQuantity; sou.SouDescription = souvenir.SouDescription; sou.SouName = souvenir.SouName; sou.SouPrice = souvenir.SouPrice; sou.SupplierID = souvenir.SupplierID; sou.CategoryID = souvenir.CategoryID; } _context.Add(sou); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "CategoryID", souvenir.CategoryID); ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "SupplierID", souvenir.SupplierID); return(View(souvenir)); }
public async Task <IActionResult> Create([Bind("CustomerID,HomePhoneNumber,WorkPhoneNumber,MobilePhoneNumber,FirstMidName,LastName,Address,Email,Password")] Customer customer) { if (ModelState.IsValid) { var message = new MimeMessage(); message.From.Add(new MailboxAddress("Chris", "*****@*****.**")); message.To.Add(new MailboxAddress("Quality Souvenirs", customer.Email)); message.Subject = "Your Quality Souvenirs account"; message.Body = new TextPart("plain") { Text = "Thanks for registering with Quality Souvenirs" + Environment.NewLine + Environment.NewLine + "Your login is " + customer.Email + Environment.NewLine + Environment.NewLine + "Your password is " + customer.Password + Environment.NewLine + Environment.NewLine + "Kindest Regards" + Environment.NewLine + Environment.NewLine + "Quality Souvenirs" }; using (var client = new MailKit.Net.Smtp.SmtpClient()) { client.Connect("smtp.gmail.com", 587, false); client.Authenticate("*****@*****.**", "W3sb24da"); client.Send(message); client.Disconnect(true); } _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(RegisterConfirmation))); } return(View(customer)); }
public async Task <IActionResult> Create([Bind("CategoryID,Name")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("SupplierID,SupName,SupPno,SupEmail")] Supplier supplier) { if (ModelState.IsValid) { _context.Add(supplier); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(supplier)); }
public async Task <IActionResult> Create([Bind("OrderID,UserID,OrdDate,OrdStatus,OrdSDate,OrdCost")] Order order) { if (ModelState.IsValid) { _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserID"] = new SelectList(_context.Users, "UserID", "UserID", order.UserID); return(View(order)); }
public async Task <IActionResult> Create([Bind("SouvenirID,Name,Description,SupplierID,CategoryID,Price,ImagePath")] Souvenir souvenir) { if (ModelState.IsValid) { _context.Add(souvenir); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryID"] = new SelectList(_context.Categories, "CategoryID", "Name", souvenir.CategoryID); ViewData["SupplierID"] = new SelectList(_context.Suppliers, "SupplierID", "Name", souvenir.SupplierID); return(View(souvenir)); }