64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
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 DeploymentGroupRepository : IDeploymentGroupInterface
|
|
{
|
|
private readonly DataContext _context;
|
|
|
|
public DeploymentGroupRepository(DataContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public ICollection<DeploymentGroupModel> GetDeploymentGroups()
|
|
{
|
|
return _context.DeploymentGroups.ToList();
|
|
}
|
|
|
|
public DeploymentGroupModel GetDeploymentGroupById(Guid Id)
|
|
{
|
|
return _context.DeploymentGroups
|
|
.Include(t => t.Template)
|
|
.ThenInclude(tc => tc.TemplateCategory)
|
|
.ThenInclude(s => s.Service)
|
|
.Include(d => d.Deployments)
|
|
.ThenInclude(vm => vm.VirtualMachine)
|
|
.Where(dg => dg.Id == Id).FirstOrDefault();
|
|
}
|
|
|
|
public bool AddDeploymentGroupById(DeploymentGroupModel deploymentgroup)
|
|
{
|
|
_context.Add(deploymentgroup);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool DeleteDeploymentGroupById(DeploymentGroupModel deploymentgroup)
|
|
{
|
|
_context.Remove(deploymentgroup);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool EditDeploymentGroupById(DeploymentGroupModel deploymentgroup)
|
|
{
|
|
_context.Update(deploymentgroup);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool CheckDeploymentGroupById(Guid Id)
|
|
{
|
|
return _context.DeploymentGroups
|
|
.Any(d => d.Id == Id);
|
|
}
|
|
|
|
public bool SaveChanges()
|
|
{
|
|
var saved = _context.SaveChanges();
|
|
return saved > 0 ? true : false;
|
|
}
|
|
}
|
|
}
|