OpenAuth.Net/OpenAuth.Repository/RelevanceRepository.cs

51 lines
1.6 KiB
C#
Raw Normal View History

using OpenAuth.Domain;
2015-11-30 11:58:18 +08:00
using OpenAuth.Domain.Interface;
using System;
2016-09-10 18:48:28 +08:00
using System.Collections.Generic;
using System.Linq;
2015-11-30 11:58:18 +08:00
namespace OpenAuth.Repository
{
public class RelevanceRepository : BaseRepository<Relevance>, IRelevanceRepository
2015-11-30 11:58:18 +08:00
{
public void DeleteBy(string key, params Guid[] firstIds)
2015-11-30 11:58:18 +08:00
{
Delete(u => firstIds.Contains(u.FirstId) && u.Key == key);
}
2016-04-13 14:56:34 +08:00
/// <summary>
/// 删除关联
/// </summary>
/// <param name="key">关联标识</param>
/// <param name="idMaps">关联的&lt;firstId, secondId&gt;数组</param>
public void DeleteBy(string key, ILookup<Guid, Guid> idMaps)
2016-04-13 14:56:34 +08:00
{
foreach (var sameVals in idMaps)
{
foreach (var value in sameVals)
{
Delete(u =>u.Key == key && u.FirstId == sameVals.Key && u.SecondId == value);
}
}
}
/// <summary>
/// 添加新的关联
/// </summary>
/// <param name="key">关联标识</param>
/// <param name="idMaps">关联的&lt;firstId, secondId&gt;数组</param>
public void AddRelevance(string key, ILookup<Guid, Guid> idMaps)
2015-11-30 11:58:18 +08:00
{
2016-09-10 18:48:28 +08:00
DeleteBy(key, idMaps);
BatchAdd((from sameVals in idMaps
from value in sameVals
select new Relevance
2015-11-30 11:58:18 +08:00
{
2016-09-10 18:48:28 +08:00
Key = key,
FirstId = sameVals.Key,
SecondId = value,
OperateTime = DateTime.Now
}).ToArray());
2015-11-30 11:58:18 +08:00
}
}
}