Esempio n. 1
0
 private void button1_Click(object sender, EventArgs e)
 {
     UsersDAL user = new UsersDAL();
     UserDTO dto = new UserDTO();
     //----------------
     UserDTO dto1 = new UserDTO();
     dto1 = user.GetUserByLogin(login_txt.Text);
     //--------------
     if (checkIsEmptyField())
     {
         MessageBox.Show("Fill in the blank fields!");
     }
     else if (dto1.login == null)
     {
         dto.first_name = firstn_txt.Text;
         dto.last_name = lastn_txt.Text;
         dto.email = email_txt.Text;
         dto.phone_number = number_txt.Text;
         dto.login = login_txt.Text;
         dto.password = password_txt.Text;
         dto.id_role = 1;
         user.insertUser(dto);
         MagorPage m = new MagorPage();
         m.Show();
         clear_fun();
     }
     else 
     {
         MessageBox.Show("Input another login!");
     }
 }
Esempio n. 2
0
 public void insertUser(UserDTO insertedUser)
 {
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         Users user = new Users();
         user.id_user = insertedUser.id_user;
         user.first_name = insertedUser.first_name;
         user.last_name = insertedUser.last_name;
         user.email = insertedUser.email;
         user.phone_number = insertedUser.phone_number;
         user.login = insertedUser.login;
         user.password = insertedUser.password;
         user.id_role = insertedUser.id_role;
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
 private void login_btn_Click(object sender, EventArgs e)
 {
     UsersDAL user = new UsersDAL();
     UserDTO dto1 = new UserDTO();
     dto1 = user.GetUserByLogin(login_txt.Text);
     UserDTO dto2 = new UserDTO();
     dto2 = user.GetUserByPassword(password_txt.Text);
     if ((dto1!=null)&&(dto2!=null))
     {
         if (dto1.id_user == dto2.id_user)
         {
             MagorPage m = new MagorPage();
             m.Show();
         }
     }
     else
         MessageBox.Show("Enter correct Login or Password! ");
 }
Esempio n. 4
0
 public UserDTO GetUserByPassword(string password)
 {
     var user = new UserDTO();
     using (DeviceCategoryContext context = new DeviceCategoryContext())
     {
         user = context.Users.Select(u => new UserDTO
         {
             id_user = u.id_user,
             first_name = u.first_name,
             last_name = u.last_name,
             email = u.email,
             phone_number = u.phone_number,
             login = u.login,
             password = u.password,
             id_role = u.id_role
         }).FirstOrDefault(u => (u.password == password));
     }
     return user;
 }