Taylohtio/IDP/parsers/parser-management-fee/common/repository/CondoMappingRepository.cs

56 lines
1.9 KiB
C#

using taloyhtio.idp.parser.common.model;
using Microsoft.Azure.Storage;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
namespace taloyhtio.idp.parser.common.repository
{
public class CondoMappingRepository : BaseRepository<CondoMapping>, ICondoMappingRepository
{
public CondoMappingRepository(ILogger log, string storageConnectionString, EventsHandlerFactory eventsFactory = null) :
base(log, storageConnectionString, eventsFactory)
{ }
public CondoMapping GetMappingByPMSCondoName(Guid taloyhtioPMCId, string condoPMS)
{
_log.Information($"Start GetMappingByPMSCondoName {taloyhtioPMCId}, {condoPMS}");
if (Guid.Empty.Equals(taloyhtioPMCId)) throw new ArgumentNullException(nameof(taloyhtioPMCId));
if (string.IsNullOrEmpty(condoPMS)) throw new ArgumentNullException(nameof(condoPMS));
try
{
var query = _table.CreateQuery<CondoMapping>()
.Where(d => taloyhtioPMCId.Equals(d.TaloyhtioPMCId) && condoPMS.Equals(d.PMSCondoName));
_log.Information($"End GetMappingByPMSCondoName");
return query.FirstOrDefault();
}
catch (StorageException e)
{
throw e;
}
}
public IEnumerable<CondoMapping> GetMappings(IEnumerable<string> pmsCondosName = null)
{
_log.Information($"Start GetMappings");
try
{
var allCondos = _table.CreateQuery<CondoMapping>().ToArray();
if (pmsCondosName != null)
{
return allCondos.Where(x => pmsCondosName.Contains(x.PMSCondoName));
}
return allCondos;
}
catch (StorageException e)
{
throw e;
}
}
}
}