public async Task <IActionResult> Edit(int id, [Bind("NonAccountUserId,FirstName,LastName,Street,ZipCode,City,Email,Phone,OrderId")] NonAccountUser nonAccountUser)
        {
            if (id != nonAccountUser.NonAccountUserId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(nonAccountUser);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!NonAccountUserExists(nonAccountUser.NonAccountUserId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(nonAccountUser));
        }
        public async Task <IActionResult> Create([Bind("NonAccountUserId,FirstName,LastName,Street,ZipCode,City,Email,Phone,OrderId")] NonAccountUser nonAccountUser)
        {
            if (ModelState.IsValid)
            {
                _context.Add(nonAccountUser);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(nonAccountUser));
        }
Ejemplo n.º 3
0
        public Task SendOrderConfirmToUser(Order order, NonAccountUser user)
        {
            string from     = "*****@*****.**";
            string to       = "*****@*****.**";
            string subject  = "Orderbekräftelse";
            string htmlBody = "Hej! <br> <br> Tack för att du lagt en order hos oss på PizzAkuten! <br><br> Din beställning är på väg! <br><br>";

            htmlBody += "<table>";
            htmlBody += "<tr><td> Namn </td><td>Pris</td><td>Antal</td></tr>";
            foreach (var item in order.Cart.CartItems)
            {
                htmlBody += "<tr><td>" + item.Dish.Name + "</td><td>" + item.Dish.Price + "</td><td>" + item.Quantity + "</td></tr>";
            }

            htmlBody += "</table>";
            htmlBody += "Summa: " + order.TotalPrice;

            htmlBody += "<br> Order kommer sändas till följande adress: " +
                        "<br>" + user.FirstName + "<br>" + user.LastName + "<br>" + user.Street + "<br>" + user.ZipCode + "<br>" + user.City + "<br>";

            htmlBody += "Har du några frågor kontakta: PizzAkuten Tel: 123456789";


            MailMessage mailMessage = new MailMessage(from, to, subject, htmlBody);

            mailMessage.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("smtp-mail.outlook.com");

            client.Port                  = 587;
            client.DeliveryMethod        = SmtpDeliveryMethod.Network;
            client.UseDefaultCredentials = false;
            System.Net.NetworkCredential credentials =
                new System.Net.NetworkCredential("********", "********");
            client.EnableSsl   = true;
            client.Credentials = credentials;
            client.Send(mailMessage);
            return(Task.CompletedTask);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> ConfirmOrder(IFormCollection form)
        {
            if (form.Keys.Count != 0)
            {
                var model = new NonAccountUser();
                model.FirstName = form["FirstName"];
                model.LastName  = form["LastName"];
                model.Street    = form["Street"];
                model.ZipCode   = Convert.ToInt32(form["ZipCode"]);
                model.Phone     = form["Phone"];
                model.Email     = form["Email"];
                model.City      = form["City"];
                _context.NonAccountUsers.Add(model);
                _context.SaveChanges();
            }
            ;

            var order = _service.GetOrder();

            if (_signInManager.IsSignedIn(User))
            {
                var currentUser = User;
                order.ApplicationUser = await _userManager.FindByNameAsync(User.Identity.Name);

                var newOrder = _service.SaveOrderToDataBase(order);


                return(RedirectToAction("Create", "Payment", new { id = newOrder.OrderId }));
            }
            else if (!_signInManager.IsSignedIn(User))
            {
                order.NonAccountUser = _context.NonAccountUsers.Last();
                var savedOrder = _service.SaveOrderToDataBase(order);
                return(RedirectToAction("Create", "Payment", new { id = savedOrder.OrderId }));
            }

            return(RedirectToAction("Create", "Payment"));
        }