Skip to content

Commit

Permalink
Merge pull request #4046 from sbwalker/dev
Browse files Browse the repository at this point in the history
use consistent naming in SiteRepository
  • Loading branch information
sbwalker authored Mar 21, 2024
2 parents 0309a86 + 4b05a49 commit d1d7ff0
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions Oqtane.Server/Repository/SiteRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Oqtane.Enums;
Expand Down Expand Up @@ -55,25 +54,25 @@ public SiteRepository(IDbContextFactory<TenantDBContext> factory, IRoleRepositor
// asynchronous methods
public async Task<IEnumerable<Site>> GetSitesAsync()
{
using var ctx = _factory.CreateDbContext();
return await ctx.Site.OrderBy(item => item.Name).ToListAsync();
using var db = _factory.CreateDbContext();
return await db.Site.OrderBy(item => item.Name).ToListAsync();
}

public async Task<Site> AddSiteAsync(Site site)
{
site.SiteGuid = Guid.NewGuid().ToString();
using var ctx = _factory.CreateDbContext();
ctx.Site.Add(site);
await ctx.SaveChangesAsync();
using var db = _factory.CreateDbContext();
db.Site.Add(site);
await db.SaveChangesAsync();
CreateSite(site);
return site;
}

public async Task<Site> UpdateSiteAsync(Site site)
{
using var ctx = _factory.CreateDbContext();
ctx.Entry(site).State = EntityState.Modified;
await ctx.SaveChangesAsync();
using var db = _factory.CreateDbContext();
db.Entry(site).State = EntityState.Modified;
await db.SaveChangesAsync();
return site;
}

Expand All @@ -84,23 +83,23 @@ public async Task<Site> GetSiteAsync(int siteId)

public async Task<Site> GetSiteAsync(int siteId, bool tracking)
{
using var ctx = _factory.CreateDbContext();
using var db = _factory.CreateDbContext();
if (tracking)
{
return await ctx.Site.FindAsync(siteId);
return await db.Site.FindAsync(siteId);
}
else
{
return await ctx.Site.AsNoTracking().FirstOrDefaultAsync(item => item.SiteId == siteId);
return await db.Site.AsNoTracking().FirstOrDefaultAsync(item => item.SiteId == siteId);
}
}

public async Task DeleteSiteAsync(int siteId)
{
using var ctx = _factory.CreateDbContext();
var site = ctx.Site.Find(siteId);
ctx.Site.Remove(site);
await ctx.SaveChangesAsync();
using var db = _factory.CreateDbContext();
var site = db.Site.Find(siteId);
db.Site.Remove(site);
await db.SaveChangesAsync();
}

// synchronous methods
Expand All @@ -112,19 +111,19 @@ public IEnumerable<Site> GetSites()

public Site AddSite(Site site)
{
using var ctx = _factory.CreateDbContext();
using var db = _factory.CreateDbContext();
site.SiteGuid = Guid.NewGuid().ToString();
ctx.Site.Add(site);
ctx.SaveChanges();
db.Site.Add(site);
db.SaveChanges();
CreateSite(site);
return site;
}

public Site UpdateSite(Site site)
{
using var ctx = _factory.CreateDbContext();
ctx.Entry(site).State = EntityState.Modified;
ctx.SaveChanges();
using var db = _factory.CreateDbContext();
db.Entry(site).State = EntityState.Modified;
db.SaveChanges();
return site;
}

Expand All @@ -135,23 +134,23 @@ public Site GetSite(int siteId)

public Site GetSite(int siteId, bool tracking)
{
using var ctx = _factory.CreateDbContext();
using var db = _factory.CreateDbContext();
if (tracking)
{
return ctx.Site.Find(siteId);
return db.Site.Find(siteId);
}
else
{
return ctx.Site.AsNoTracking().FirstOrDefault(item => item.SiteId == siteId);
return db.Site.AsNoTracking().FirstOrDefault(item => item.SiteId == siteId);
}
}

public void DeleteSite(int siteId)
{
using var ctx = _factory.CreateDbContext();
var site = ctx.Site.Find(siteId);
ctx.Site.Remove(site);
ctx.SaveChanges();
using var db = _factory.CreateDbContext();
var site = db.Site.Find(siteId);
db.Site.Remove(site);
db.SaveChanges();
}


Expand Down

0 comments on commit d1d7ff0

Please sign in to comment.