More user mapping

pull/618/head
tidusjar 8 years ago
parent d4da525985
commit bbe52a17d8

@ -56,10 +56,13 @@ namespace PlexRequests.UI.Modules
{ {
var localUsers = await UserMapper.GetUsersAsync(); var localUsers = await UserMapper.GetUsersAsync();
var model = new List<UserManagementUsersViewModel>(); var model = new List<UserManagementUsersViewModel>();
var usersDb = UserLoginsRepo.GetAll().ToList();
foreach (var user in localUsers) foreach (var user in localUsers)
{ {
var userDb = UserLoginsRepo.Get(user.UserGuid); var userDb = usersDb.FirstOrDefault(x => x.UserId == user.UserGuid);
model.Add(MapLocalUser(user, userDb.LastLoggedIn)); model.Add(MapLocalUser(user, userDb?.LastLoggedIn ?? DateTime.MinValue));
} }
var plexSettings = await PlexSettings.GetSettingsAsync(); var plexSettings = await PlexSettings.GetSettingsAsync();
@ -70,7 +73,7 @@ namespace PlexRequests.UI.Modules
foreach (var u in plexUsers.User) foreach (var u in plexUsers.User)
{ {
var userDb = UserLoginsRepo.Get(u.Id); var userDb = usersDb.FirstOrDefault(x => x.UserId == u.Id);
model.Add(new UserManagementUsersViewModel model.Add(new UserManagementUsersViewModel
{ {
Username = u.Username, Username = u.Username,
@ -82,7 +85,7 @@ namespace PlexRequests.UI.Modules
{ {
Thumb = u.Thumb Thumb = u.Thumb
}, },
LastLoggedIn = userDb.LastLoggedIn, LastLoggedIn = userDb?.LastLoggedIn ?? DateTime.MinValue,
}); });
} }
} }
@ -155,8 +158,8 @@ namespace PlexRequests.UI.Modules
userFound.UserProperties = ByteConverterHelper.ReturnBytes(currentProps); userFound.UserProperties = ByteConverterHelper.ReturnBytes(currentProps);
var user = UserMapper.EditUser(userFound); var user = UserMapper.EditUser(userFound);
var dbUser = UserLoginsRepo.Get(user.UserGuid); var dbUser = UserLoginsRepo.GetAll().FirstOrDefault(x => x.UserId == user.UserGuid);
var retUser = MapLocalUser(user, dbUser.LastLoggedIn); var retUser = MapLocalUser(user, dbUser?.LastLoggedIn ?? DateTime.MinValue);
return Response.AsJson(retUser); return Response.AsJson(retUser);
} }

Loading…
Cancel
Save