11
11
using Microsoft . AspNetCore . Mvc ;
12
12
using Microsoft . Extensions . Logging ;
13
13
using System ;
14
- using System . Threading ;
15
-
14
+ using System . Threading ;
15
+ using System . Threading . Tasks ;
16
+
16
17
[ Authorize , Route ( "api/[controller]" ) ]
17
18
public class AuthController : BaseController < AuthController >
18
19
{
@@ -30,7 +31,7 @@ public IActionResult OnAADLogin()
30
31
//extract user name from identity passed in via token
31
32
//check if that user record is in DB. If not, add it.
32
33
//InitLocalUser: this property checks for user, adds to db and returns a fully formed user model if one does not exist.
33
- var returned = InitLocalUser ( ) ;
34
+ var returned = InitLocalUser ( ) . Result ;
34
35
UserModel user = returned . Item1 ;
35
36
String strError = returned . Item2 ;
36
37
@@ -62,7 +63,7 @@ public IActionResult QueryCurrentOrganization()
62
63
/// </summary>
63
64
/// <returns></returns>
64
65
/// <exception cref="ArgumentNullException"></exception>
65
- protected ( UserModel , string ) InitLocalUser ( )
66
+ protected async Task < ( UserModel , string ) > InitLocalUser ( )
66
67
{
67
68
bool bCheckOrganization = false ;
68
69
bool bUpdateUser = false ;
@@ -143,7 +144,7 @@ public IActionResult QueryCurrentOrganization()
143
144
else
144
145
{
145
146
// When more than 1 record, it means they have signed up (and then left) more than
146
- // once. This is okay, but we pick the most recent one.
147
+ // once. This is okay, but we pick the most recent (newest) one.
147
148
// listMatchEmailAddress.Sort((em1, em2) => DateTime?.Compare(em1.Created, em2.Created));
148
149
listMatchEmailAddress . Sort ( ( em1 , em2 ) =>
149
150
{
@@ -152,8 +153,8 @@ public IActionResult QueryCurrentOrganization()
152
153
return DateTime . Compare ( dt1 , dt2 ) ;
153
154
} ) ;
154
155
155
- // We must have at least 2 records or this line gives an exception
156
- int iItem = listMatchEmailAddress . Count - 1 ;
156
+ int iItem = listMatchEmailAddress . Count - 1 ; // We must have at least 2 records this index causes an exception
157
+ if ( iItem < 0 ) iItem = 0 ; // Just to make sure this is within range
157
158
158
159
// We use the most recent records that we have for this user.
159
160
um = listMatchEmailAddress [ iItem ] ;
@@ -165,20 +166,19 @@ public IActionResult QueryCurrentOrganization()
165
166
bUpdateUser = true ; // Synch UserModel changes
166
167
bCheckOrganization = true ; // Check the user's organization.
167
168
168
- // Note: If we want to automate the removal of duplicate records and logging of it,
169
- // we would do that here with code like the following:
169
+ // Removing duplicate records.
170
+ // We log it, just so there is a record of it.
170
171
171
- //////// for (int iDeleteMe = 0; iDeleteMe < listMatchEmailAddress.Count - 1; iDeleteMe++)
172
- //////// {
173
- //////// if (listMatchEmailAddress[iDeleteMe].ID != null)
174
- //////// {
175
- //////// string strWarning = $"InitLocalUser|| About to delete record {iDeleteMe} of {listMatchEmailAddress.Count} from public.user. Id: {listMatchEmailAddress[iDeleteMe].ID.Value} Email: {listMatchEmailAddress[iDeleteMe].Email}";
176
- //////// _logger.LogWarning(strWarning);
172
+ for ( int iDeleteMe = 0 ; iDeleteMe < listMatchEmailAddress . Count - 1 ; iDeleteMe ++ )
173
+ {
174
+ if ( listMatchEmailAddress [ iDeleteMe ] . ID != null )
175
+ {
176
+ string strWarning = $ "InitLocalUser|| About to delete record { iDeleteMe } of { listMatchEmailAddress . Count } from public.user. Id: { listMatchEmailAddress [ iDeleteMe ] . ID . Value } Email: { listMatchEmailAddress [ iDeleteMe ] . Email } ";
177
+ _logger . LogWarning ( strWarning ) ;
177
178
178
- //////// await _dalUser.DeleteAsync(listMatchEmailAddress[iDeleteMe].ID.Value, base.DalUserToken);
179
- //////// }
180
- ////////}
181
-
179
+ await _dalUser . DeleteAsync ( listMatchEmailAddress [ iDeleteMe ] . ID . Value , base . DalUserToken ) ;
180
+ }
181
+ }
182
182
}
183
183
}
184
184
@@ -233,6 +233,5 @@ public IActionResult QueryCurrentOrganization()
233
233
return ( um , null ) ;
234
234
235
235
}
236
-
237
236
}
238
237
}
0 commit comments