public IActionResult Register(Customer customer, string firstPassword)
        {
            if (firstPassword != customer.PasswordHash)
            {
                // Passwords don't match
                return(RedirectToAction("CustomerRegistration"));
            }
            // Generate Salt
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            byte[] buff = new byte[31];
            rng.GetBytes(buff);
            string salt = Convert.ToBase64String(buff);

            // Generate Hash
            string hashed = GenerateHash(customer.PasswordHash, salt);

            // Overwrite to delete the string passsword
            customer.PasswordHash = String.Format("{0}:{1}", salt, hashed);

            try
            {
                // Try to save new customer
                DineOutContext.Add(customer);
                DineOutContext.SaveChanges();
                return(RedirectToAction("Index"));
            }
            catch
            {
                // Return to same view if cannot save to database
                return(RedirectToAction("CustomerRegistration"));
            }
        }
        public IActionResult OrderDetails(
            int menuId, int customerId, int restaurantId)
        {
            ///The action that returns the orderable menu. this allows the customer to build their order
            ///@param int menuId
            ///@param int restaurantId
            ///@param int customerId
            //Those parameters are hard coded for testing purpose
            menuId       = 1;
            customerId   = 1;
            restaurantId = 1;

            Order nOrder = new Order
            {
                CustomerId   = customerId,
                RestaurantId = restaurantId,
                StatusId     = 1
            };

            DineOutContext.Add(nOrder);
            DineOutContext.SaveChanges();

            orderData.Order
                            = DineOutContext.Order.Find(nOrder.OrderId);
            orderData.Menu  = DineOutContext.Menu.Find(menuId);
            orderData.Items = DineOutContext.Item
                              .ToList().FindAll(x => x.MenuId == menuId);
            orderData.Restaurant = DineOutContext.Restaurant
                                   .Find(nOrder.RestaurantId);

            return(View(orderData));
        }
 public IActionResult SaveChanges(RestaurantProfile restaurantProfile)
 {
     if (ModelState.IsValid)
     {
         RestaurantProfile profileEntry = DineOutContext.RestaurantProfile
                                          .FirstOrDefault(r => r.RestaurantProfileId == restaurantProfile.RestaurantProfileId);
         if (profileEntry != null)
         {
             //profileEntry.Name = restaurantProfile.Name;
             profileEntry.Email = restaurantProfile.Email;
         }
         DineOutContext.SaveChanges();
         TempData["message"] = $"Your profile has been updated!";
     }
     return(RedirectToAction("Menu"));
 }
Beispiel #4
0
        public IActionResult OrderDetails(
            int menuId, int customerId, int restaurantId)
        {
            ///The action that returns the orderable menu. this allows the customer to build their order
            ///@param int menuId
            ///@param int restaurantId
            ///@param int customerId
            ///


            var customer_id = HttpContext.Session.GetString("customer_id");

            if (customer_id != null)
            {
                Order nOrder = new Order
                {
                    CustomerId   = Int32.Parse(customer_id),
                    RestaurantId = restaurantId,
                    StatusId     = 1,
                    CreatedOn    = DateTime.Now
                };
                DineOutContext.Order.Add(nOrder);
                DineOutContext.SaveChanges();

                orderData.Order
                                = DineOutContext.Order.Find(nOrder.OrderId);
                orderData.Menu  = DineOutContext.Menu.Find(menuId);
                orderData.Items = DineOutContext.Item
                                  .ToList().FindAll(x => x.MenuId == menuId);
                orderData.Restaurant = DineOutContext.Restaurant
                                       .Find(nOrder.RestaurantId);

                return(View(orderData));
            }
            return(RedirectToAction("CustomerLogin", "Customer",
                                    new
            {
                menuId = menuId,
                restaurantId = restaurantId
            }));
        }