public SecurityModels.User GetUser(int id) { SecurityModels.User user = new SecurityModels.User(); using (SqlConnection con = new SqlConnection(securityConnectionString)) { using (SqlCommand cmd = new SqlCommand("GetUser", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id; con.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { user.id = Convert.ToInt32(reader["ID"].ToString()); user.userName = reader["UserName"].ToString(); user.password = reader["Password"].ToString(); user.firstName = reader["firstName"].ToString(); user.lastName = reader["lastName"].ToString(); user.email = reader["Email"].ToString(); user.active = id == 0 ? false : Convert.ToBoolean(reader["Active"].ToString()); user.roles = GetUserRoles(reader["Roles"].ToString()); user.permissions = reader["Permissions"].ToString(); } } con.Close(); } return(user); }
public int UpdateUserProfile(SecurityModels.User user) { DataTable tblRoles = new DataTable(); tblRoles.Columns.Add("Name", typeof(string)); tblRoles.Columns.Add("assigned", typeof(bool)); if (user.roles != null) { foreach (SecurityModels.UserRole userRole in user.roles) { if (userRole.assigned) { DataRow row = tblRoles.NewRow(); row["Name"] = userRole.name; row["assigned"] = userRole.assigned; tblRoles.Rows.Add(row); } } } try { using (SqlConnection con = new SqlConnection(securityConnectionString)) { using (SqlCommand cmd = new SqlCommand("UpdateUserProfile", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@Id", SqlDbType.Int).Value = user.id; cmd.Parameters.Add("@UserName", SqlDbType.VarChar, 20).Value = user.userName; cmd.Parameters.Add("@Password", SqlDbType.VarChar, 20).Value = user.password; cmd.Parameters.Add("@Active", SqlDbType.Bit).Value = user.active ? 1 : 0; cmd.Parameters.Add("@firstName", SqlDbType.VarChar, 50).Value = user.firstName; cmd.Parameters.Add("@lastName", SqlDbType.VarChar, 50).Value = user.lastName; cmd.Parameters.Add("@Email", SqlDbType.VarChar, 100).Value = user.email; cmd.Parameters.Add("@Roles", SqlDbType.Structured, 0).Value = tblRoles; con.Open(); user.id = Convert.ToInt32(cmd.ExecuteScalar()); } con.Close(); } } catch { throw; } return(user.id); }
public IActionResult UpdateUserProfile([FromBody] SecurityModels.User user) { user.id = securityInventoryRepo.UpdateUserProfile(user); return(StatusCode(StatusCodes.Status200OK, user.id)); }
public IActionResult GetUser(int id) { SecurityModels.User user = securityInventoryRepo.GetUser(id); return(StatusCode(StatusCodes.Status200OK, user)); }