initial commit
This commit is contained in:
75
Repository/EnvironmentRepository.cs
Normal file
75
Repository/EnvironmentRepository.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
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 EnvironmentRepository : IEnvironmentInterface
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
||||
public EnvironmentRepository(DataContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public ICollection<EnvironmentModel> GetEnvironments()
|
||||
{
|
||||
return _context.Environments.ToList();
|
||||
}
|
||||
|
||||
public EnvironmentModel GetEnvironmentById(Guid Id)
|
||||
{
|
||||
return _context.Environments
|
||||
.Where(e => e.Id == Id).FirstOrDefault();
|
||||
}
|
||||
public bool AddEnvironmentById(EnvironmentModel environment)
|
||||
{
|
||||
_context.Add(environment);
|
||||
return SaveChanges();
|
||||
}
|
||||
public bool DeleteEnvironmentById(EnvironmentModel environment)
|
||||
{
|
||||
_context.Remove(environment);
|
||||
return SaveChanges();
|
||||
}
|
||||
public bool EditEnvironmentById(EnvironmentModel environment)
|
||||
{
|
||||
_context.Update(environment);
|
||||
return SaveChanges();
|
||||
}
|
||||
|
||||
public EnvironmentModel GetLinkedDomainsByEnvironmentId(Guid Id)
|
||||
{
|
||||
return _context.Environments
|
||||
.Include(ed => ed.EnvironmentDomains)
|
||||
.ThenInclude(d => d.Domain)
|
||||
.Where(e => e.Id == Id).FirstOrDefault();
|
||||
}
|
||||
|
||||
public ICollection<TemplateModel> GetAvailableTemplatesByEnvironmentId(Guid Id)
|
||||
{
|
||||
var environment = _context.Environments.Where(e => e.Id == Id).FirstOrDefault();
|
||||
|
||||
return _context.Templates.Where(t => t.CloudTemplate == environment.CloudEnabled).ToList();
|
||||
}
|
||||
|
||||
public bool CheckEnvironmentById(Guid Id)
|
||||
{
|
||||
return _context.Environments
|
||||
.Any(e => e.Id == Id);
|
||||
}
|
||||
public bool CheckEnvironmentByName(String Name)
|
||||
{
|
||||
return _context.Environments
|
||||
.Any(e => e.Name == Name);
|
||||
}
|
||||
|
||||
public bool SaveChanges()
|
||||
{
|
||||
var saved = _context.SaveChanges();
|
||||
return saved > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user