Refactor code structure for improved readability and maintainability
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Microsoft.SelfService.Portal.Core.API.Context;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.SelfService.Portal.Core.API.Context;
|
||||
using Microsoft.SelfService.Portal.Core.API.Interfaces;
|
||||
using Microsoft.SelfService.Portal.Core.API.Models;
|
||||
|
||||
@@ -16,20 +17,60 @@ namespace Microsoft.SelfService.Portal.Core.API.Repository
|
||||
public ICollection<TemplateModel> GetTemplates()
|
||||
{
|
||||
return _context.Templates
|
||||
.AsNoTracking()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public TemplateModel GetTemplateById(Guid Id)
|
||||
{
|
||||
return _context.Templates
|
||||
.AsNoTracking()
|
||||
.Where(t => t.Id == Id)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool AddTemplateById(TemplateModel template)
|
||||
{
|
||||
_context.Add(template);
|
||||
return SaveChanges();
|
||||
}
|
||||
|
||||
public bool EditTemplateById(TemplateModel template)
|
||||
{
|
||||
_context.Update(template);
|
||||
return SaveChanges();
|
||||
}
|
||||
|
||||
public bool DeleteTemplateById(TemplateModel template)
|
||||
{
|
||||
_context.Remove(template);
|
||||
return SaveChanges();
|
||||
}
|
||||
|
||||
public bool CheckTemplateById(Guid Id)
|
||||
{
|
||||
return _context.Templates
|
||||
.Any(t => t.Id == Id);
|
||||
}
|
||||
}
|
||||
|
||||
public TemplateModel GetTemplateByName(string Name)
|
||||
{
|
||||
return _context.Templates
|
||||
.AsNoTracking()
|
||||
.Where(t => t.Name == Name)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public bool CheckTemplateByName(string Name)
|
||||
{
|
||||
return _context.Templates
|
||||
.Any(t => t.Name == Name);
|
||||
}
|
||||
|
||||
public bool SaveChanges()
|
||||
{
|
||||
var saved = _context.SaveChanges();
|
||||
return saved > 0 ? true : false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user