87 lines
2.8 KiB
C#
87 lines
2.8 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.JsonDocuments;
|
|
using Microsoft.SelfService.Portal.Core.API.Models;
|
|
|
|
namespace Microsoft.SelfService.Portal.Core.API.Repository
|
|
{
|
|
public class DeploymentRepository : IDeploymentInterface
|
|
{
|
|
private readonly DataContext _context;
|
|
|
|
public DeploymentRepository(DataContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public ICollection<DeploymentModel> GetDeployments()
|
|
{
|
|
return _context.Deployments.ToList();
|
|
}
|
|
|
|
public DeploymentModel GetDeploymentById(Guid Id)
|
|
{
|
|
return _context.Deployments
|
|
.Include(vm => vm.Target)
|
|
.Include(dg => dg.DeploymentGroup)
|
|
.ThenInclude(t => t.Template)
|
|
.Where(d => d.Id == Id).FirstOrDefault();
|
|
}
|
|
|
|
public bool AddDeploymentById(DeploymentModel deployment)
|
|
{
|
|
deployment.JSONData = ConfigurationDocumentValidator.NormalizeAndValidate(
|
|
deployment.JSONData,
|
|
ConfigurationDocumentKind.DeploymentOverride).JsonData;
|
|
|
|
_context.Add(deployment);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool DeleteDeploymentById(DeploymentModel deployment)
|
|
{
|
|
_context.Remove(deployment);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool EditDeploymentById(DeploymentModel deployment)
|
|
{
|
|
deployment.JSONData = ConfigurationDocumentValidator.NormalizeAndValidate(
|
|
deployment.JSONData,
|
|
ConfigurationDocumentKind.DeploymentOverride).JsonData;
|
|
|
|
_context.Update(deployment);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public DeploymentModel GetDeploymentByCompositeId(Guid deploymentGroupId, Guid targetId)
|
|
{
|
|
return _context.Deployments
|
|
.Include(vm => vm.Target)
|
|
.Include(dg => dg.DeploymentGroup)
|
|
.ThenInclude(t => t.Template)
|
|
.FirstOrDefault(d => d.DeploymentGroupId == deploymentGroupId && d.TargetId == targetId);
|
|
}
|
|
|
|
public bool CheckDeploymentById(Guid Id)
|
|
{
|
|
return _context.Deployments
|
|
.Any(d => d.Id == Id);
|
|
}
|
|
|
|
public bool CheckDeploymentByCompositeId(Guid deploymentGroupId, Guid targetId)
|
|
{
|
|
return _context.Deployments
|
|
.Any(d => d.DeploymentGroupId == deploymentGroupId && d.TargetId == targetId);
|
|
}
|
|
|
|
public bool SaveChanges()
|
|
{
|
|
var saved = _context.SaveChanges();
|
|
return saved > 0 ? true : false;
|
|
}
|
|
}
|
|
}
|
|
|