예제 #1
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (textBox2.Text == textBox4.Text)
     {
         COMuser user = new COMuser();
         user.CategoryName = textBox3.Text;
         user.Email        = textBox1.Text;
         user.Password     = textBox2.Text;
         user.ImageURL     = BLLcategory.GetCategoryById(6).ImageURL;
         try
         {
             BLLuser.AddUser(user);
         }
         catch (Exception ex)
         {
             MessageBox.Show("error: add user didnt success: " + ex);
         }
     }
     else
     {
         MessageBox.Show("verify password isnt like password. try again.");
     }
     groupBox1.Visible = false;
     textBox1.Text     = string.Empty;
     textBox2.Text     = string.Empty;
     textBox4.Text     = string.Empty;
     textBox3.Text     = string.Empty;
 }
예제 #2
0
 public static List <COMuser> GetUsers()
 {
     //using (DBEntities context = new DBEntities())
     //{
     //    return MAPPER.ConvertListDALuserToListCOMuser(context.Users_tbl.ToList());
     //}
     using (var connection = new MySqlConnection(csb.ConnectionString))
     {
         List <COMuser> list = new List <COMuser>();
         connection.Open();
         MySqlCommand select_all_users = new MySqlCommand("SELECT * FROM users_tbl", connection);
         using (var reader = select_all_users.ExecuteReader())
         {
             while (reader.Read())
             {
                 //TODO: put the right syntax here
                 COMuser user = new COMuser()
                 {
                     UserId       = Convert.ToInt32(reader["userId"]),
                     Password     = Convert.ToString(reader["password"]),
                     Email        = Convert.ToString(reader["email"]),
                     ImageURL     = Convert.ToString(reader["imageURL"]),
                     CategoryName = Convert.ToString(reader["categoryName"]),
                 };
                 list.Add(user);
             }
         }
         return(list);
     }
 }
예제 #3
0
 public static COMuser GetUserById(int id)
 {
     //using (DBEntities context = new DBEntities())
     //{
     //    return MAPPER.ConvertDALuserToCOMuser(context.Users_tbl.FirstOrDefault(u => u.UserId == id));
     //}
     using (var connection = new MySqlConnection(csb.ConnectionString))
     {
         COMuser u = new COMuser();
         connection.Open();
         MySqlCommand get_user_by_id = new MySqlCommand("SELECT * FROM users_tbl WHERE userId=@uId;", connection);
         get_user_by_id.Parameters.AddWithValue("uId", id);
         using (var reader = get_user_by_id.ExecuteReader())
         {
             if (reader.Read())
             {
                 u.UserId       = Convert.ToInt32(reader["userId"]);
                 u.Password     = Convert.ToString(reader["password"]);
                 u.Email        = Convert.ToString(reader["email"]);
                 u.CategoryName = Convert.ToString(reader["categoryName"]);
                 u.ImageURL     = Convert.ToString(reader["imageURL"]);
             }
         }
         return(u);
     }
 }
        public IHttpActionResult GetUserById(int id)
        {
            COMuser user = BLLuser.GetUserById(id);

            if (user == null)
            {
                return(BadRequest("user does not exist"));
            }
            return(Ok(user));
        }
예제 #5
0
 public static void AddUser(COMuser user)
 {
     //using (DBEntities context = new DBEntities())
     //{
     //    context.Users_tbl.Add(MAPPER.ConvertCOMuserToDALuser(user));
     //    context.SaveChanges();
     //}
     using (var connection = new MySqlConnection(csb.ConnectionString))
     {
         Int64 userId = nextUserId();
         connection.Open();
         MySqlCommand insert_table = new MySqlCommand("INSERT INTO users_tbl (email, password, categoryName,imageURL,userId) values (@Email,@Password,@CategoryName, @ImageURL, @UserId);", connection);
         insert_table.Parameters.AddWithValue("Email", user.Email);
         insert_table.Parameters.AddWithValue("Password", user.Password);
         insert_table.Parameters.AddWithValue("CategoryName", user.CategoryName);
         insert_table.Parameters.AddWithValue("ImageURL", user.ImageURL);
         insert_table.Parameters.AddWithValue("UserId", userId);
         insert_table.ExecuteNonQuery();
         connection.Close();
     }
 }
예제 #6
0
 public static void AddUser(COMuser user)
 {
     DALuser.AddUser(user);
 }