62 lines
1.7 KiB
C#
62 lines
1.7 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 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.VirtualMachine)
|
|
.Include(dg => dg.DeploymentGroup)
|
|
.ThenInclude(t => t.Template)
|
|
.Where(d => d.Id == Id).FirstOrDefault();
|
|
}
|
|
|
|
public bool AddDeploymentById(DeploymentModel deployment)
|
|
{
|
|
_context.Add(deployment);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool DeleteDeploymentById(DeploymentModel deployment)
|
|
{
|
|
_context.Remove(deployment);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool EditDeploymentById(DeploymentModel deployment)
|
|
{
|
|
_context.Update(deployment);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool CheckDeploymentById(Guid Id)
|
|
{
|
|
return _context.Deployments
|
|
.Any(d => d.Id == Id);
|
|
}
|
|
|
|
public bool SaveChanges()
|
|
{
|
|
var saved = _context.SaveChanges();
|
|
return saved > 0 ? true : false;
|
|
}
|
|
}
|
|
}
|