initial commit
This commit is contained in:
88
Repository/DomainRepository.cs
Normal file
88
Repository/DomainRepository.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.SelfService.Portal.Core.API.Context;
|
||||
using Microsoft.SelfService.Portal.Core.API.Interfaces;
|
||||
using Microsoft.SelfService.Portal.Core.API.Models;
|
||||
|
||||
namespace Microsoft.SelfService.Portal.Core.API.Repository
|
||||
{
|
||||
public class DomainRepository : IDomainInterface
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public DomainRepository(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
public ICollection<DomainModel> GetDomains()
|
||||
{
|
||||
return _context.Domains
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public DomainModel GetDomainById(Guid Id)
|
||||
{
|
||||
return _context.Domains
|
||||
.Where(d => d.Id == Id)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
public bool AddDomainById(DomainModel domain)
|
||||
{
|
||||
_context.Add(domain);
|
||||
return SaveChanges();
|
||||
}
|
||||
public bool DeleteDomainById(DomainModel domain)
|
||||
{
|
||||
_context.Remove(domain);
|
||||
return SaveChanges();
|
||||
}
|
||||
public bool EditDomainById(DomainModel domain)
|
||||
{
|
||||
_context.Update(domain);
|
||||
return SaveChanges();
|
||||
}
|
||||
|
||||
public DomainModel GetDomainByIdInEnvironments(Guid Id)
|
||||
{
|
||||
return _context.Domains
|
||||
.Include(ed => ed.EnvironmentDomains)
|
||||
.ThenInclude(e => e.Environment)
|
||||
.Where(d => d.Id == Id)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
public DomainModel GetVirtualMachinesByDomainId(Guid Id)
|
||||
{
|
||||
return _context.Domains
|
||||
.Where(d => d.Id == Id)
|
||||
.Include(vm => vm.VirtualMachines)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool LinkDomainByIdToEnvironment(EnvironmentDomainsModel environmentDomain)
|
||||
{
|
||||
_context.Add(environmentDomain);
|
||||
return SaveChanges();
|
||||
}
|
||||
public bool UnlinkDomainByIdFromEnvironment(EnvironmentDomainsModel environmentDomain)
|
||||
{
|
||||
_context.Remove(environmentDomain);
|
||||
return SaveChanges();
|
||||
}
|
||||
|
||||
public bool CheckDomainById(Guid Id)
|
||||
{
|
||||
return _context.Domains
|
||||
.Any(d => d.Id == Id);
|
||||
}
|
||||
public bool CheckDomainByName(string Name)
|
||||
{
|
||||
return _context.Domains
|
||||
.Any(p => p.Name == Name);
|
||||
}
|
||||
|
||||
public bool SaveChanges()
|
||||
{
|
||||
var saved = _context.SaveChanges();
|
||||
return saved > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user