Adding
This commit is contained in:
+62
@@ -0,0 +1,62 @@
|
||||
using LCU.API.Internal.RepoApi.Repos.Exceptions;
|
||||
using LCU.API.Internal.RepoApi.Repos.Models;
|
||||
using LCU.API.Internal.RepoApi.Repos.Persistence;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LCU.API.Internal.RepoApi.Repos.Repositories
|
||||
{
|
||||
public class RepoManualStatusRepository : BaseRepository, IRepoManualStatusRepository
|
||||
{
|
||||
public RepoManualStatusRepository(AppDbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<RepoManualStatus>> ListAllAsync()
|
||||
{
|
||||
return await _context.RepoManualStatuses.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<string>> ListWatchStatusesAsync()
|
||||
{
|
||||
var statusSet = await (from status in _context.RepoManualStatuses
|
||||
where status.WatchForStatusChanges == true
|
||||
select status).ToListAsync();
|
||||
|
||||
return statusSet.Select(x => x.Description).ToList() as IReadOnlyCollection<string>;
|
||||
}
|
||||
|
||||
public async Task AddAsync(RepoManualStatus repoManualStatus)
|
||||
{
|
||||
// Only Create the Alert if an identical one doesn't already exist
|
||||
var duplicateStatus = (
|
||||
from status in _context.RepoManualStatuses
|
||||
where status.Description.ToUpper().Trim() == repoManualStatus.Description.ToUpper().Trim()
|
||||
select status
|
||||
);
|
||||
|
||||
if (!duplicateStatus.Any())
|
||||
{
|
||||
await _context.RepoManualStatuses.AddAsync(repoManualStatus);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new DuplicateResourceException("RepoManualStatus");
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<RepoManualStatus> FindByIdAsync(int id)
|
||||
{
|
||||
return await _context.RepoManualStatuses.FindAsync(id);
|
||||
}
|
||||
|
||||
public void Update(RepoManualStatus repoManualStatus)
|
||||
{
|
||||
_context.RepoManualStatuses.Update(repoManualStatus);
|
||||
}
|
||||
|
||||
public void Remove(RepoManualStatus repoManualStatus)
|
||||
{
|
||||
_context.RepoManualStatuses.Remove(repoManualStatus);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user