Merge branch '#98-AssignIdentFromUserCreateFails' into Release0.2

This commit is contained in:
Chris.Watts90@outlook.com 2018-06-06 13:50:23 +01:00
commit 53b4499d37
3 changed files with 22 additions and 4 deletions

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SQLiteRepository.Extensions
{
public static class EnumerableExtensions
{
public static IEnumerable<TSource> Exclude<TSource, TKey>(this IEnumerable<TSource> source,
IEnumerable<TSource> exclude, Func<TSource, TKey> keySelector)
{
var excludedSet = new HashSet<TKey>(exclude.Select(keySelector));
return source.Where(item => !excludedSet.Contains(keySelector(item)));
}
}
}

View File

@ -9,6 +9,7 @@ using Interfaces;
using SQLite.Net; using SQLite.Net;
using SQLite.Net.Platform.Win32; using SQLite.Net.Platform.Win32;
using SQLiteRepository.Converters; using SQLiteRepository.Converters;
using SQLiteRepository.Extensions;
using SQLiteRepository.Properties; using SQLiteRepository.Properties;
namespace SQLiteRepository namespace SQLiteRepository
@ -241,12 +242,11 @@ namespace SQLiteRepository
public OperationResponse UpdateUser(User user, out int userIdResult) public OperationResponse UpdateUser(User user, out int userIdResult)
{ {
var ret = OperationResponse.NONE; var ret = OperationResponse.NONE;
//Get a list of current associated identifiers, convert into a list of Identifier Objects.. //Get a list of current associated identifiers, convert into a list of Identifier Objects..
var currentCards = var currentCards =
_connection.Query<CardUniqueId>(SQLiteProcedures.GET_CARDS_BY_USER_ID, user.UserId) _connection.Query<CardUniqueId>(SQLiteProcedures.GET_CARDS_BY_USER_ID, user.UserId)
.Select(IdentifierConverter.ConvertToIdentifierDto); .Select(IdentifierConverter.ConvertToIdentifierDto).ToList();
var cardsToRemove = currentCards.Except(user.AssociatedIdentifiers).Select(x => x.Id).ToList(); var cardsToRemove = currentCards.Exclude(user.AssociatedIdentifiers, x => x.Id).Select(x => x.Id).ToList();
#region Update/Create User #region Update/Create User
int userId; int userId;
@ -885,6 +885,5 @@ namespace SQLiteRepository
userId userId
); );
} }
} }
} }

View File

@ -83,6 +83,7 @@
<Compile Include="Converters\TimeLogConverter.cs" /> <Compile Include="Converters\TimeLogConverter.cs" />
<Compile Include="Converters\UserConverter.cs" /> <Compile Include="Converters\UserConverter.cs" />
<Compile Include="DBVersion.cs" /> <Compile Include="DBVersion.cs" />
<Compile Include="Extensions\Extensions.cs" />
<Compile Include="GroupDb.cs" /> <Compile Include="GroupDb.cs" />
<Compile Include="LogSourceDb.cs" /> <Compile Include="LogSourceDb.cs" />
<Compile Include="SQLiteRepository.cs" /> <Compile Include="SQLiteRepository.cs" />