Improve validation and error handling in Controller methods
This commit is contained in:
@ -63,12 +63,11 @@ namespace Oqtane.Repository
|
||||
File file;
|
||||
if (tracking)
|
||||
{
|
||||
file = _db.File.Where(item => item.FileId == fileId).Include(item => item.Folder).FirstOrDefault();
|
||||
|
||||
file = _db.File.Include(item => item.Folder).FirstOrDefault(item => item.FileId == fileId);
|
||||
}
|
||||
else
|
||||
{
|
||||
file = _db.File.AsNoTracking().Where(item => item.FileId == fileId).Include(item => item.Folder).FirstOrDefault();
|
||||
file = _db.File.AsNoTracking().Include(item => item.Folder).FirstOrDefault(item => item.FileId == fileId);
|
||||
}
|
||||
if (file != null)
|
||||
{
|
||||
|
@ -61,7 +61,7 @@ namespace Oqtane.Repository
|
||||
Folder folder;
|
||||
if (tracking)
|
||||
{
|
||||
folder = _db.Folder.Where(item => item.FolderId == folderId).FirstOrDefault();
|
||||
folder = _db.Folder.Find(folderId);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -9,6 +9,7 @@ namespace Oqtane.Repository
|
||||
Module AddModule(Module module);
|
||||
Module UpdateModule(Module module);
|
||||
Module GetModule(int moduleId);
|
||||
Module GetModule(int moduleId, bool tracking);
|
||||
void DeleteModule(int moduleId);
|
||||
string ExportModule(int moduleId);
|
||||
bool ImportModule(int moduleId, string content);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -9,6 +9,7 @@ namespace Oqtane.Repository
|
||||
Notification AddNotification(Notification notification);
|
||||
Notification UpdateNotification(Notification notification);
|
||||
Notification GetNotification(int notificationId);
|
||||
Notification GetNotification(int notificationId, bool tracking);
|
||||
void DeleteNotification(int notificationId);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -10,6 +10,7 @@ namespace Oqtane.Repository
|
||||
PageModule AddPageModule(PageModule pageModule);
|
||||
PageModule UpdatePageModule(PageModule pageModule);
|
||||
PageModule GetPageModule(int pageModuleId);
|
||||
PageModule GetPageModule(int pageModuleId, bool tracking);
|
||||
PageModule GetPageModule(int pageId, int moduleId);
|
||||
void DeletePageModule(int pageModuleId);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -9,6 +9,7 @@ namespace Oqtane.Repository
|
||||
Page AddPage(Page page);
|
||||
Page UpdatePage(Page page);
|
||||
Page GetPage(int pageId);
|
||||
Page GetPage(int pageId, bool tracking);
|
||||
Page GetPage(int pageId, int userId);
|
||||
Page GetPage(string path, int siteId);
|
||||
void DeletePage(int pageId);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -9,6 +9,7 @@ namespace Oqtane.Repository
|
||||
Profile AddProfile(Profile profile);
|
||||
Profile UpdateProfile(Profile profile);
|
||||
Profile GetProfile(int profileId);
|
||||
Profile GetProfile(int profileId, bool tracking);
|
||||
void DeleteProfile(int profileId);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -10,6 +10,7 @@ namespace Oqtane.Repository
|
||||
Role AddRole(Role role);
|
||||
Role UpdateRole(Role role);
|
||||
Role GetRole(int roleId);
|
||||
Role GetRole(int roleId, bool tracking);
|
||||
void DeleteRole(int roleId);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -9,6 +9,7 @@ namespace Oqtane.Repository
|
||||
Site AddSite(Site site);
|
||||
Site UpdateSite(Site site);
|
||||
Site GetSite(int siteId);
|
||||
Site GetSite(int siteId, bool tracking);
|
||||
void DeleteSite(int siteId);
|
||||
void CreatePages(Site site, List<PageTemplate> pageTemplates);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using Oqtane.Models;
|
||||
|
||||
namespace Oqtane.Repository
|
||||
@ -9,6 +9,7 @@ namespace Oqtane.Repository
|
||||
User AddUser(User user);
|
||||
User UpdateUser(User user);
|
||||
User GetUser(int userId);
|
||||
User GetUser(int userId, bool tracking);
|
||||
User GetUser(string username);
|
||||
void DeleteUser(int userId);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace Oqtane.Repository
|
||||
UserRole AddUserRole(UserRole userRole);
|
||||
UserRole UpdateUserRole(UserRole userRole);
|
||||
UserRole GetUserRole(int userRoleId);
|
||||
UserRole GetUserRole(int userRoleId, bool tracking);
|
||||
void DeleteUserRole(int userRoleId);
|
||||
void DeleteUserRoles(int userId);
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
@ -48,12 +48,24 @@ namespace Oqtane.Repository
|
||||
|
||||
public Module GetModule(int moduleId)
|
||||
{
|
||||
Module module = _db.Module.Find(moduleId);
|
||||
return GetModule(moduleId, true);
|
||||
}
|
||||
|
||||
public Module GetModule(int moduleId, bool tracking)
|
||||
{
|
||||
Module module;
|
||||
if (tracking)
|
||||
{
|
||||
module = _db.Module.Find(moduleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
module = _db.Module.AsNoTracking().FirstOrDefault(item => item.ModuleId == moduleId);
|
||||
}
|
||||
if (module != null)
|
||||
{
|
||||
module.Permissions = _permissions.GetPermissionString("Module", module.ModuleId);
|
||||
}
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
@ -45,10 +45,21 @@ namespace Oqtane.Repository
|
||||
_db.SaveChanges();
|
||||
return notification;
|
||||
}
|
||||
|
||||
public Notification GetNotification(int notificationId)
|
||||
{
|
||||
return _db.Notification.Find(notificationId);
|
||||
return GetNotification(notificationId, true);
|
||||
}
|
||||
|
||||
public Notification GetNotification(int notificationId, bool tracking)
|
||||
{
|
||||
if (tracking)
|
||||
{
|
||||
return _db.Notification.Find(notificationId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _db.Notification.AsNoTracking().FirstOrDefault(item => item.NotificationId == notificationId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteNotification(int notificationId)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Extensions;
|
||||
@ -69,8 +69,22 @@ namespace Oqtane.Repository
|
||||
|
||||
public PageModule GetPageModule(int pageModuleId)
|
||||
{
|
||||
PageModule pagemodule = _db.PageModule.Include(item => item.Module) // eager load modules
|
||||
.SingleOrDefault(item => item.PageModuleId == pageModuleId);
|
||||
return GetPageModule(pageModuleId, true);
|
||||
}
|
||||
|
||||
public PageModule GetPageModule(int pageModuleId, bool tracking)
|
||||
{
|
||||
PageModule pagemodule;
|
||||
if (tracking)
|
||||
{
|
||||
pagemodule = _db.PageModule.Include(item => item.Module) // eager load modules
|
||||
.FirstOrDefault(item => item.PageModuleId == pageModuleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
pagemodule = _db.PageModule.AsNoTracking().Include(item => item.Module) // eager load modules
|
||||
.FirstOrDefault(item => item.PageModuleId == pageModuleId);
|
||||
}
|
||||
if (pagemodule != null)
|
||||
{
|
||||
pagemodule.Module.Permissions = _permissions.GetPermissionString("Module", pagemodule.ModuleId);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Extensions;
|
||||
@ -49,7 +49,21 @@ namespace Oqtane.Repository
|
||||
|
||||
public Page GetPage(int pageId)
|
||||
{
|
||||
Page page = _db.Page.Find(pageId);
|
||||
return GetPage(pageId, true);
|
||||
}
|
||||
|
||||
public Page GetPage(int pageId, bool tracking)
|
||||
{
|
||||
Page page;
|
||||
if (tracking)
|
||||
{
|
||||
page = _db.Page.Find(pageId);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
page = _db.Page.AsNoTracking().FirstOrDefault(item => item.PageId == pageId);
|
||||
}
|
||||
if (page != null)
|
||||
{
|
||||
page.Permissions = _permissions.GetPermissionString(EntityNames.Page, page.PageId);
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
@ -35,7 +35,19 @@ namespace Oqtane.Repository
|
||||
|
||||
public Profile GetProfile(int profileId)
|
||||
{
|
||||
return _db.Profile.Find(profileId);
|
||||
return GetProfile(profileId, true);
|
||||
}
|
||||
|
||||
public Profile GetProfile(int profileId, bool tracking)
|
||||
{
|
||||
if (tracking)
|
||||
{
|
||||
return _db.Profile.Find(profileId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _db.Profile.AsNoTracking().FirstOrDefault(item => item.ProfileId == profileId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteProfile(int profileId)
|
||||
|
@ -49,7 +49,19 @@ namespace Oqtane.Repository
|
||||
|
||||
public Role GetRole(int roleId)
|
||||
{
|
||||
return _db.Role.Find(roleId);
|
||||
return GetRole(roleId, true);
|
||||
}
|
||||
|
||||
public Role GetRole(int roleId, bool tracking)
|
||||
{
|
||||
if (tracking)
|
||||
{
|
||||
return _db.Role.Find(roleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _db.Role.AsNoTracking().FirstOrDefault(item => item.RoleId == roleId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteRole(int roleId)
|
||||
|
@ -620,7 +620,19 @@ namespace Oqtane.Repository
|
||||
|
||||
public Site GetSite(int siteId)
|
||||
{
|
||||
return _db.Site.Find(siteId);
|
||||
return GetSite(siteId, true);
|
||||
}
|
||||
|
||||
public Site GetSite(int siteId, bool tracking)
|
||||
{
|
||||
if (tracking)
|
||||
{
|
||||
return _db.Site.Find(siteId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _db.Site.AsNoTracking().FirstOrDefault(item => item.SiteId == siteId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteSite(int siteId)
|
||||
|
@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Oqtane.Models;
|
||||
@ -35,7 +35,19 @@ namespace Oqtane.Repository
|
||||
|
||||
public User GetUser(int userId)
|
||||
{
|
||||
return _db.User.Find(userId);
|
||||
return GetUser(userId, true);
|
||||
}
|
||||
|
||||
public User GetUser(int userId, bool tracking)
|
||||
{
|
||||
if (tracking)
|
||||
{
|
||||
return _db.User.Find(userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _db.User.AsNoTracking().FirstOrDefault(item => item.UserId == userId);
|
||||
}
|
||||
}
|
||||
|
||||
public User GetUser(string username)
|
||||
|
@ -46,10 +46,25 @@ namespace Oqtane.Repository
|
||||
|
||||
public UserRole GetUserRole(int userRoleId)
|
||||
{
|
||||
return _db.UserRole
|
||||
.Include(item => item.Role) // eager load roles
|
||||
.Include(item => item.User) // eager load users
|
||||
.SingleOrDefault(item => item.UserRoleId == userRoleId);
|
||||
return GetUserRole(userRoleId, true);
|
||||
}
|
||||
|
||||
public UserRole GetUserRole(int userRoleId, bool tracking)
|
||||
{
|
||||
if (tracking)
|
||||
{
|
||||
return _db.UserRole
|
||||
.Include(item => item.Role) // eager load roles
|
||||
.Include(item => item.User) // eager load users
|
||||
.FirstOrDefault(item => item.UserRoleId == userRoleId);
|
||||
}
|
||||
else
|
||||
{
|
||||
return _db.UserRole.AsNoTracking()
|
||||
.Include(item => item.Role) // eager load roles
|
||||
.Include(item => item.User) // eager load users
|
||||
.FirstOrDefault(item => item.UserRoleId == userRoleId);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteUserRole(int userRoleId)
|
||||
|
Reference in New Issue
Block a user