示例#1
0
 public void UpdateUser(UserInformation oldUserInfo)
 {
     var cn = new SqlConnection(connectionString);
     try
     {
         var cmd =
             new SqlCommand(
                 "UPDATE UsersInformation SET FirstName = @FirstName, LastName = @LastName, UserCod = @UserCod, IsAsoc = @IsAsoc, AsocId = @AsocId WHERE UserId = @userId",
                 cn);
         cmd.Parameters.AddWithValue("@FirstName", oldUserInfo.FirstName);
         cmd.Parameters.AddWithValue("@LastName", oldUserInfo.LastName);
         cmd.Parameters.AddWithValue("@UserCod", oldUserInfo.UserCod);
         cmd.Parameters.AddWithValue("@IsAsoc", oldUserInfo.IsAsoc);
         cmd.Parameters.AddWithValue("@AsocId", oldUserInfo.AsocId);
         cmd.Parameters.AddWithValue("@userId", oldUserInfo.UserId);
         cn.Open();
         cmd.ExecuteNonQuery();
     }
     catch (Exception)
     {
         logger.Error(string.Format("UpdateUser| userId:{0}", oldUserInfo.UserId));
     }
     finally
     {
         cn.Close();
     }
 }
示例#2
0
 public UserInformation GetUserInformationByCod(string cod)
 {
     UserInformation userInformation = null;
     var cn = new SqlConnection(connectionString);
     try
     {
         var cmd =
             new SqlCommand(
                 "SELECT ui.UserId,ui.FirstName, ui.LastName, u.UserName, m.Email FROM UsersInformation as ui INNER JOIN aspnet_Users as u ON u.UserId = ui.UserId INNER JOIN aspnet_Membership m on u.UserId = m.UserId WHERE ui.UserCod = @cod",
                 cn);
         cmd.Parameters.AddWithValue("@cod", cod);
         cn.Open();
         var reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             userInformation = new UserInformation
             {
                 UserId = new Guid(reader[0].ToString()),
                 FirstName = reader[1].ToString(),
                 LastName = reader[2].ToString(),
                 UserCod = cod,
                 UserName = reader[3].ToString(),
                 Email = reader[4].ToString()
             };
         }
     }
     catch (Exception)
     {
         logger.Error(string.Format("GetUserInformationByCod| cod:{0}", cod));
     }
     finally
     {
         cn.Close();
     }
     return userInformation;
 }
示例#3
0
 public UserInformation GetUserInformationById(Guid userId)
 {
     UserInformation userInformation = null;
     var cn = new SqlConnection(connectionString);
     SqlDataReader reader = null;
     try
     {
         var cmd = new SqlCommand("SELECT * FROM UsersInformation WHERE UserId = @userId", cn);
         cmd.Parameters.AddWithValue("@userId", userId);
         cn.Open();
         reader = cmd.ExecuteReader();
         if (reader.Read())
         {
             userInformation = new UserInformation
             {
                 UserId = userId,
                 FirstName = reader[1].ToString(),
                 LastName = reader[2].ToString(),
                 UserCod = reader[3].ToString(),
                 IsAsoc = Convert.ToBoolean(reader[4].ToString()),
                 AsocId = Convert.ToInt32(reader[5].ToString())
             };
         }
     }
     catch (Exception)
     {
         logger.Error(string.Format("GetUserInformationById| userId:{0}", userId));
     }
     finally
     {
         if (reader != null)
             reader.Close();
         cn.Close();
     }
     return userInformation;
 }