public void Delete(User user)
 {
     var userForDeletion = _allUsers.Find(u => u.Id == user.Id);
     _allUsers.Remove(userForDeletion);
     Serialize();
     GetAllUsers();
 }
        public EditUserForm(User user)
        {
            NameTextBox.Text = user.Name;
            PhoneTextBox.Text = user.PhoneNumber;
            AddressTextBox.Text = user.Address;
            PostTextBox.Text = user.Post;
            _id = user.Id;
            _password = user.Password;

            InitializeComponent();
        }
        public void Add(User user)
        {
            if (AllUsers.Any(u => u.Name == user.Name))
            {
                throw new InvalidOperationException("UserName is already used");
            }

            AllUsers.Add(user);
            Serialize();
            GetAllUsers();
        }
 public void Change(User user)
 {
     var userToChange = _allUsers.Find(u => u.Id == user.Id);
     if (AllUsers.Any(u => u.Name == user.Name))
     {
         throw new InvalidOperationException("UserName is already used");
     }
     _allUsers.Remove(userToChange);
     _allUsers.Add(user);
     Serialize();
     GetAllUsers();
 }
        private void RemoveUserButton_Click(object sender, EventArgs e)
        {
            try
            {
                if ((_id) == AssignmentManagementClient.CurrentUser.Id)
                {
                    throw new InvalidOperationException("Can't remove myself");
                }

                var user = new User {Id = _id};
                AssignmentManagementClient.UsersOrganizer.Delete(user);
                Close();
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void LogInButton_Click(object sender, EventArgs e)
        {
            try
            {
                var user = new User
                {
                    Name = NameTextBox.Text,
                };

                user.CreateNewPassword(PasswordTextBox.Text);

                var loggedUser = AssignmentManagementClient.UsersOrganizer.LogIn(user);
                AssignmentManagementClient.CurrentUser = loggedUser;
                NameTextBox.Enabled = false;
                PasswordTextBox.Enabled = false;
                LogInButton.Enabled = false;
                QuitButton.Enabled = true;
                QuitButton.Visible = true;

                if (loggedUser is Admin)
                {
                    UsersList.Visible = true;
                    UsersList.Enabled = true;
                    foreach (var userFromList in AssignmentManagementClient.UsersOrganizer.AllUsers)
                    {
                        UsersList.Items.Add(userFromList.Name);
                    }
                }

                foreach (var assignment in loggedUser.GetAssignments())
                {
                    AssignmentsList.Items.Add(assignment.Name);
                }
            }
            catch (InvalidOperationException exception)
            {
                MessageBox.Show(exception.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public void EditUser(User user)
 {
 }
        public User LogIn(User user)
        {
            GetAllUsers();
            var loggedUser = _allUsers.Find(u => u.Password == user.Password && u.Name == user.Name);
            if (loggedUser == null)
            {
                throw new InvalidOperationException("UserName or password is incorrect");
            }

            return loggedUser;
        }