public void Save(User user)
 {
     if (user.ID == 0)
     {
         Insert(user);
     }
     else
     {
         Update(user);
     }
 }
Example #2
0
        private void toolStripButtonAdd_Click(object sender, EventArgs e)
        {
            User user = new User();
            FormAddEditUser formAddUser = new FormAddEditUser(user);

            if (formAddUser.ShowDialog() == DialogResult.OK)
            {
                UsersRepository usersRepository = new UsersRepository();
                usersRepository.Save(user);

                BindControls();
            }
        }
 public FormAddEditUser(User user)
 {
     InitializeComponent();
     this.user = user;
 }
 private void Update(User user)
 {
     dataBase.Entry(user).State = EntityState.Modified;
     dataBase.SaveChanges();
 }
 private void Insert(User user)
 {
     dataBase.Users.Add(user);
     dataBase.SaveChanges();
 }
 public void Delete(User user)
 {
     dataBase.Entry(user).State = EntityState.Deleted;
     dataBase.SaveChanges();
 }
 public static User AuthenticateUser(string username, string password)
 {
     UsersRepository userRepository = new UsersRepository();
     LoggedUser = userRepository.GetByUsernameAndPassword(username, password);
     return LoggedUser;
 }