Ejemplo n.º 1
0
        /// <summary>
        /// GET order ready action to send notification email to customer
        /// </summary>
        /// <param name="id">An order ID</param>
        /// <returns>Redirect to Order Index</returns>
        public IActionResult OrderReady(ulong id)
        {
            Order order = _context.OrderDB.SingleOrDefault(o => o.ID == id);

            // Send message telling user their order is ready for pickup
            string[] emailArgs = CreateOrderReadyEmail(_context.UserDB.FirstOrDefault(u => u.ID == order.UserID), order);
            NotificationService.SendEmail(_context.UserDB.FirstOrDefault(u => u.ID == order.UserID)?.Email, emailArgs[0], emailArgs[1]);

            _context.OrderDB.Remove(_context.OrderDB.FirstOrDefault(o => o.ID == id));
            _context.SaveDatabase(_context.OrderDB);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> SignUp([Bind("FirstName,LastName,Email,Password")] User newUser)
        {
            if (ModelState.IsValid)
            {
                var dbUser = (from user in _context.UserDB
                              where (user.Email == newUser.Email)
                              select user).FirstOrDefault();
                if (dbUser == null)
                {
                    newUser.Password = Helpers.Utilities.GenerateDjb264Hash(newUser.Password).ToString();
                    _context.UserDB.Add(newUser);
                    _context.SaveDatabase(_context.UserDB);

                    var claims = new List <Claim>
                    {
                        new Claim(ClaimTypes.NameIdentifier, newUser.ID.ToString()),
                        new Claim(ClaimTypes.Role, newUser.UserPermissions.ToString())
                    };

                    HttpContext.Session.Set("UserID", Encoding.ASCII.GetBytes(newUser.ID.ToString()));

                    await HttpContext.SignInAsync(new ClaimsPrincipal(new ClaimsIdentity(claims, "login")));

                    return(RedirectToAction("Index", "Menus"));
                }
                else
                {
                    return(View(newUser));
                }
            }
            return(View(newUser));
        }
        /// <summary>
        /// GET An Order confirmation view.
        /// </summary>
        /// <returns>Order Index View</returns>
        public IActionResult Index()
        {
            float subTotal    = 0f;
            Order activeOrder = _context.UserDB.FirstOrDefault(u => u.ID == UserID).ActiveOrder;

            foreach (var item in activeOrder.Items)
            {
                subTotal += item.Price;
            }
            activeOrder.CalculateTotal(subTotal);
            activeOrder.PickupTime = DateTime.Now.AddMinutes(15);
            _context.UserDB.FirstOrDefault(u => u.ID == UserID).ActiveOrder = activeOrder;
            _context.SaveDatabase(_context.UserDB);
            return(View(activeOrder));
        }