add extension method for excluding the contents of one list from another.
fix UpdateUser to use Exclude rather than Except method for linq. #98
This commit is contained in:
parent
5413b2e63a
commit
6e18b3461c
@ -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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user