78 lines
2.0 KiB
C#
78 lines
2.0 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 TargetRepository : ITargetInterface
|
|
{
|
|
private readonly DataContext _context;
|
|
|
|
public TargetRepository(DataContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public ICollection<TargetModel> GetTargets()
|
|
{
|
|
return _context.Targets
|
|
.Include(target => target.Domain)
|
|
.ToList();
|
|
}
|
|
|
|
public TargetModel GetTargetById(Guid Id)
|
|
{
|
|
return _context.Targets
|
|
.Where(v => v.Id == Id)
|
|
.Include(d => d.Domain)
|
|
.ThenInclude(e => e.EnvironmentDomains)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
public bool AddTargetById(TargetModel target)
|
|
{
|
|
_context.Add(target);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool EditTargetById(TargetModel target)
|
|
{
|
|
_context.Update(target);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public bool DeleteTargetById(TargetModel target)
|
|
{
|
|
_context.Remove(target);
|
|
return SaveChanges();
|
|
}
|
|
|
|
public TargetModel GetTargetByName(string Name)
|
|
{
|
|
return _context.Targets
|
|
.Where(v => v.Name == Name)
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
public bool CheckTargetById(Guid Id)
|
|
{
|
|
return _context.Targets
|
|
.Any(v => v.Id == Id);
|
|
}
|
|
|
|
public bool CheckTargetByName(string Name)
|
|
{
|
|
return _context.Targets
|
|
.Any(v => v.Name == Name);
|
|
}
|
|
|
|
public bool SaveChanges()
|
|
{
|
|
var saved = _context.SaveChanges();
|
|
return saved > 0 ? true : false;
|
|
}
|
|
}
|
|
}
|
|
|