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, 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() .Where(d => taloyhtioPMCId.Equals(d.TaloyhtioPMCId) && condoPMS.Equals(d.PMSCondoName)); _log.Information($"End GetMappingByPMSCondoName"); return query.FirstOrDefault(); } catch (StorageException e) { throw e; } } public IEnumerable GetMappings(IEnumerable pmsCondosName = null) { _log.Information($"Start GetMappings"); try { var allCondos = _table.CreateQuery().ToArray(); if (pmsCondosName != null) { return allCondos.Where(x => pmsCondosName.Contains(x.PMSCondoName)); } return allCondos; } catch (StorageException e) { throw e; } } } }