Beispiel #1
0
        public IActionResult ForgotPassword(Customer customer, string firstPassword)
        {
            if (firstPassword != customer.PasswordHash)
            {
                // New Password does not match
                TempData["message"] = "Password don't match!";
                return(View());
            }

            var isCustomer = DineOutContext.Customer.Where(r => r.Email == customer.Email).FirstOrDefault();

            if (isCustomer != null)
            {
                // Customer exist
                string[] salt = isCustomer.PasswordHash.Split(":");

                // Password match and will be updated
                string newSashed = GenerateHash(customer.PasswordHash, salt[0]);
                // Overwrite to delete the string passsword
                isCustomer.PasswordHash = String.Format("{0}:{1}", salt[0], newSashed);
                DineOutContext.Update(isCustomer);
                DineOutContext.SaveChanges();
                return(RedirectToAction("CustomerLogin"));
            }
            else
            {
                // Customer does not exist
                TempData["message"] = "User does not exist";
                return(View());
            }
        }
        public IActionResult Update_Menu(int restaurant_id, int menu_id, string menu_title)
        {
            var menu_row = DineOutContext.Menu.Where(r => r.RestaurantId == restaurant_id)
                           .Where(r => r.MenuId == menu_id)
                           .FirstOrDefault();

            Menu menu_object = menu_row;

            menu_object.Title = menu_title;
            Console.WriteLine(menu_object);

            DineOutContext.Update(menu_object);
            DineOutContext.SaveChanges();

            TempData["message"] = $"Title updated!";
            return(RedirectToAction("Menu"));
        }
        public IActionResult ChangeQuantity(int orderId, int itemId, int orderItemId, int quantity)
        {
            /// action called when an item's quantity is being changed by the customer
            /// @param int orderId
            /// @param int itemId
            /// @param int orderItemId
            /// @param int quantity
            var itemUpdate = DineOutContext.Order_Item
                             .Where(r => r.OrderItemId == orderItemId)
                             .Where(r => r.ItemId == itemId).FirstOrDefault();

            itemUpdate.Quantity = quantity;
            DineOutContext.Update(itemUpdate);
            DineOutContext.SaveChanges();

            return(RedirectToAction("OrderSummary",
                                    new { orderId = orderId }));
        }
        public IActionResult Update_Menu(int restaurant_id, int menu_id, string menu_title)
        {
            var profile_id = HttpContext.Session.GetString("restaurant_owner_Id");

            if (profile_id != null)
            {
                var menu_row = DineOutContext.Menu.Where(r => r.RestaurantId == restaurant_id)
                               .Where(r => r.MenuId == menu_id)
                               .FirstOrDefault();

                Menu menu_object = menu_row;

                menu_object.Title = menu_title;
                Console.WriteLine(menu_object);

                DineOutContext.Update(menu_object);
                DineOutContext.SaveChanges();

                TempData["message"] = $"Title updated!";
                return(RedirectToAction("Menu"));
            }
            return(RedirectToAction("OwnerLogin"));
        }
        public IActionResult ForgotPassword(Customer customer, string oldPassword, string firstPassword)
        {
            var isCustomer = DineOutContext.Customer.Where(r => r.Email == customer.Email).FirstOrDefault();


            if (firstPassword != customer.PasswordHash)
            {
                // New Password does not match
                return(View());
            }
            if (isCustomer != null)
            {
                // Customer exist
                string[] salt         = isCustomer.PasswordHash.Split(":");
                string   newHashedPin = GenerateHash(oldPassword, salt[0]);
                bool     isValid      = newHashedPin.Equals(salt[1]);
                if (isValid == true)
                {
                    // Password match and will be updated
                    string newSashed = GenerateHash(customer.PasswordHash, salt[0]);
                    // Overwrite to delete the string passsword
                    isCustomer.PasswordHash = String.Format("{0}:{1}", salt[0], newSashed);
                    DineOutContext.Update(isCustomer);
                    DineOutContext.SaveChanges();
                    return(RedirectToAction("CustomerLogin"));
                }
                else
                {
                    // Old password does not match
                    return(View());
                }
            }
            else
            {
                // Customer does not exist
                return(View());
            }
        }