initial commit
This commit is contained in:
61
Repository/DeploymentRepository.cs
Normal file
61
Repository/DeploymentRepository.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user