コード例 #1
0
 public void ChangeLastName(User user, string newLastName)
 {
     if (ValidationHelpers.NameValidation(newLastName) == null)
     {
         MessageHelpers.ErrorMessage("Not a valid last name.");
         return;
     }
     user.FirstName = newLastName;
 }
コード例 #2
0
 public int ChooseFromMenu <T>(List <T> items)
 {
     while (true)
     {
         Console.WriteLine("Enter a number to choose an option: ");
         for (int i = 0; i < items.Count; i++)
         {
             Console.WriteLine($"{i + 1} - {items[i]}");
         }
         string userChoice = Console.ReadLine();
         int    choice     = ValidationHelpers.NumberValidation(userChoice, items.Count);
         if (choice == -1)
         {
             MessageHelpers.ErrorMessage("Incorrect input");
             continue;
         }
         return(choice);
     }
 }
コード例 #3
0
        public void ChangePassword(int id, string oldPassword, string newPassword)
        {
            var user = _db.GetAll().SingleOrDefault(user => user.Id == id);

            if (user.Password != oldPassword)
            {
                MessageHelpers.ErrorMessage("Please enter a correct old password.");
                return;
            }
            if (oldPassword == newPassword)
            {
                MessageHelpers.ErrorMessage("New password can not be old password.");
                return;
            }
            if (ValidationHelpers.PasswordValidation(newPassword) == null)
            {
                MessageHelpers.ErrorMessage("Not a valid new password.");
                return;
            }
            user.Password = newPassword;
            MessageHelpers.SuccessMessage("Password successfully changed.");
        }