public static Userr GetUserById(int id) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Id", id) }; string query = "SELECT * FROM Users WHERE Id = @Id"; DataAccess dbAcess = new DataAccess(); DataTable dt = dbAcess.ExecuteParamerizedSelectCommand(query, CommandType.Text, parameters); if (dt != null) { if (dt.Rows.Count > 0) { Userr user = new Userr(); user.Id = Convert.ToInt32(dt.Rows[0]["Id"]); user.Username = dt.Rows[0]["UserName"].ToString(); user.FullName = dt.Rows[0]["FullName"].ToString(); user.Email = dt.Rows[0]["Email"].ToString(); user.PhoneNumber = dt.Rows[0]["PhoneNumber"].ToString(); user.BirthDay = dt.Rows[0]["Birthday"].ToString(); user.UserType = Convert.ToInt32(dt.Rows[0]["UserType"]); user.RegistrationDate = dt.Rows[0]["RegistrationDate"].ToString(); return user; } } return null; }
public static bool Update(Userr u) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@Id", u.Id), new SqlParameter("@FullName", u.FullName), new SqlParameter("@Email", u.Email), new SqlParameter("@PhoneNumber", u.PhoneNumber), }; string query = "UPDATE Users SET FullName = @FullName, Email = @Email, PhoneNumber = @PhoneNumber WHERE Id = @Id"; DataAccess dbAcess = new DataAccess(); return dbAcess.ExecuteNonQuery(query, CommandType.Text, parameters); }
public static bool Save(Userr u) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@FullName", u.FullName), new SqlParameter("@Password", u.Password), new SqlParameter("@UserName", u.Username), new SqlParameter("@Email", u.Email), new SqlParameter("@PhoneNumber", u.PhoneNumber), new SqlParameter("@BirthDay", u.BirthDay), new SqlParameter("@UserType",u.UserType), new SqlParameter("@RegistrationDate", u.RegistrationDate) }; string insertCommand = "INSERT INTO Users VALUES(@Email, @Password, @UserName, @FullName, @PhoneNumber, @BirthDay, @UserType, @RegistrationDate)"; DataAccess dbAcess = new DataAccess(); bool executeResult = dbAcess.ExecuteNonQuery(insertCommand, CommandType.Text, parameters); return executeResult; }