65 lines
2.1 KiB
C#
65 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using LCU.API.Collections.RepoApi.Exceptions;
|
|
using LCU.Shared.Collections.RepoApiLib.Models;
|
|
using LCU.Shared.Collections.RepoApiLib.Repositories;
|
|
using Serilog;
|
|
|
|
namespace LCU.API.Collections.RepoApi.Services
|
|
{
|
|
public class RepoCompanySelectionService : IRepoCompanySelectionService
|
|
{
|
|
private readonly IRepoCompanySelectionRepository _repoCompanySelectionRepository;
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
|
public RepoCompanySelectionService(
|
|
IRepoCompanySelectionRepository repoCompanySelectionRepository,
|
|
IUnitOfWork unitOfWork)
|
|
{
|
|
_repoCompanySelectionRepository = repoCompanySelectionRepository;
|
|
_unitOfWork = unitOfWork;
|
|
}
|
|
|
|
public async Task<IEnumerable<RepoCompanySelection>> ListAllAsync()
|
|
{
|
|
try
|
|
{
|
|
return await _repoCompanySelectionRepository.ListAllAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, "Failure retrieving Repo Companies");
|
|
throw new ServerErrorException();
|
|
}
|
|
}
|
|
|
|
public async Task<RepoCompanySelection> GetAsync(int id)
|
|
{
|
|
RepoCompanySelection repoCompanySelection;
|
|
try
|
|
{
|
|
repoCompanySelection = await _repoCompanySelectionRepository.FindByIdAsync(id);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure retrieving Repo Company Selection with id: {id}");
|
|
throw new NotFoundException($"Repo Company Selection with id {id} not found");
|
|
}
|
|
|
|
if (repoCompanySelection == null)
|
|
{
|
|
throw new NotFoundException($"Repo Company Selection with id {id} not found");
|
|
}
|
|
|
|
return repoCompanySelection;
|
|
}
|
|
|
|
public async Task SaveChangesAsync(IList<RepoCompanySelection> repoCompanySelections)
|
|
{
|
|
_repoCompanySelectionRepository.SaveRange(repoCompanySelections);
|
|
await _unitOfWork.CompleteAsync();
|
|
}
|
|
|
|
}
|
|
} |