private void UpdatePagePermissions(WeapsyDbContext context, Guid pageId, IEnumerable <PagePermissionDbEntity> pagePermissions) { var currentPagePermissions = context.Set <PagePermissionDbEntity>() .AsNoTracking() .Where(x => x.PageId == pageId) .ToList(); foreach (var currentPagePermission in currentPagePermissions) { var pagePermission = pagePermissions .FirstOrDefault(x => x.PageId == currentPagePermission.PageId && x.RoleId == currentPagePermission.RoleId && x.Type == currentPagePermission.Type); if (pagePermission == null) { context.Remove(currentPagePermission); } } foreach (var pagePermission in pagePermissions) { var existingPagePermissionDbEntity = currentPagePermissions .FirstOrDefault(x => x.PageId == pagePermission.PageId && x.RoleId == pagePermission.RoleId && x.Type == pagePermission.Type); if (existingPagePermissionDbEntity == null) { context.Add(pagePermission); } } }
private void UpdateMenuItemPermissions(WeapsyDbContext context, Guid menuItemId, IEnumerable <MenuItemPermissionDbEntity> menuItemPermissions) { var currentMenuItemPermissions = context.MenuItemPermissions .AsNoTracking() .Where(x => x.MenuItemId == menuItemId) .ToList(); foreach (var currentMenuItemPermission in currentMenuItemPermissions) { var menuItemPermission = menuItemPermissions .FirstOrDefault(x => x.MenuItemId == currentMenuItemPermission.MenuItemId && x.RoleId == currentMenuItemPermission.RoleId); if (menuItemPermission == null) { context.Remove(currentMenuItemPermission); } } foreach (var menuItemPermission in menuItemPermissions) { var currentPageModulePermission = currentMenuItemPermissions .FirstOrDefault(x => x.MenuItemId == menuItemPermission.MenuItemId && x.RoleId == menuItemPermission.RoleId); if (currentPageModulePermission == null) { context.Add(menuItemPermission); } } }
private void UpdateMenuItemLocalisations(WeapsyDbContext context, Guid menuItemId, IEnumerable <MenuItemLocalisationDbEntity> menuItemLocalisations) { var currentMenuItemLocalisations = context.MenuItemLocalisations .AsNoTracking() .Where(x => x.MenuItemId == menuItemId) .ToList(); foreach (var currentMenuItemLocalisation in currentMenuItemLocalisations) { var menuItemLocalisation = menuItemLocalisations .FirstOrDefault(x => x.MenuItemId == currentMenuItemLocalisation.MenuItemId && x.LanguageId == currentMenuItemLocalisation.LanguageId); if (menuItemLocalisation == null) { context.Remove(currentMenuItemLocalisation); } } foreach (var menuItemLocalisation in menuItemLocalisations) { var currentMenuItemLocalisation = context.MenuItemLocalisations.AsNoTracking() .FirstOrDefault(x => x.MenuItemId == menuItemLocalisation.MenuItemId && x.LanguageId == menuItemLocalisation.LanguageId); if (currentMenuItemLocalisation == null) { context.Add(menuItemLocalisation); } else { context.Entry(menuItemLocalisation).State = EntityState.Modified; } } }
private void UpdateMenuItems(WeapsyDbContext context, IEnumerable <MenuItemDbEntity> menuItemDbEntities) { foreach (var menuItemDbEntity in menuItemDbEntities) { var currentMenuItem = context.MenuItems.AsNoTracking().FirstOrDefault(x => x.Id == menuItemDbEntity.Id); if (currentMenuItem == null) { context.Add(menuItemDbEntity); } else { context.Entry(menuItemDbEntity).State = EntityState.Modified; UpdateMenuItemLocalisations(context, currentMenuItem.Id, menuItemDbEntity.MenuItemLocalisations); UpdateMenuItemPermissions(context, currentMenuItem.Id, menuItemDbEntity.MenuItemPermissions); } } }
private void UpdateMenuItemLocalisations(WeapsyDbContext context, IEnumerable <MenuItemLocalisationDbEntity> menuItemLocalisationDbEntities) { foreach (var menuItemLocalisationDbEntity in menuItemLocalisationDbEntities) { var currentMenuItemLocalisation = context.MenuItemLocalisations.AsNoTracking() .FirstOrDefault(x => x.MenuItemId == menuItemLocalisationDbEntity.MenuItemId && x.LanguageId == menuItemLocalisationDbEntity.LanguageId); if (currentMenuItemLocalisation == null) { context.Add(menuItemLocalisationDbEntity); } else { context.Entry(menuItemLocalisationDbEntity).State = EntityState.Modified; } } }
private void UpdatePageModuleLocalisations(WeapsyDbContext context, IEnumerable <PageModuleLocalisationDbEntity> pageModuleLocalisations) { foreach (var pageModuleLocalisation in pageModuleLocalisations) { var currentPageModuleLocalisation = context.Set <PageModuleLocalisationDbEntity>() .AsNoTracking() .FirstOrDefault(x => x.PageModuleId == pageModuleLocalisation.PageModuleId && x.LanguageId == pageModuleLocalisation.LanguageId); if (currentPageModuleLocalisation == null) { context.Add(pageModuleLocalisation); } else { context.Entry(pageModuleLocalisation).State = EntityState.Modified; } } }
private void UpdateSiteLocalisations(WeapsyDbContext context, IEnumerable <SiteLocalisationDbEntity> siteLocalisations) { foreach (var siteLocalisation in siteLocalisations) { var currentSiteLocalisation = context.Set <SiteLocalisationDbEntity>() .AsNoTracking() .FirstOrDefault(x => x.SiteId == siteLocalisation.SiteId && x.LanguageId == siteLocalisation.LanguageId); if (currentSiteLocalisation == null) { context.Add(siteLocalisation); } else { context.Entry(siteLocalisation).State = EntityState.Modified; } } }
private void UpdatePageModules(WeapsyDbContext context, IEnumerable <PageModuleDbEntity> pageModules) { foreach (var pageModule in pageModules) { var currentPageModule = context.Set <PageModuleDbEntity>() .AsNoTracking() .FirstOrDefault(x => x.ModuleId == pageModule.ModuleId && x.PageId == pageModule.PageId); if (currentPageModule == null) { context.Add(pageModule); } else { context.Entry(pageModule).State = EntityState.Modified; UpdatePageModuleLocalisations(context, pageModule.PageModuleLocalisations); UpdatePageModulePermissions(context, pageModule.Id, pageModule.PageModulePermissions); } } }
private void UpdatePageModuleLocalisations(WeapsyDbContext context, Guid pageModuleId, IEnumerable <PageModuleLocalisationDbEntity> pageModuleLocalisations) { var currentPageModuleLocalisations = context.PageModuleLocalisations .AsNoTracking() .Where(x => x.PageModuleId == pageModuleId) .ToList(); foreach (var currentPageModuleLocalisation in currentPageModuleLocalisations) { var pageModuleLocalisation = pageModuleLocalisations .FirstOrDefault(x => x.PageModuleId == currentPageModuleLocalisation.PageModuleId && x.LanguageId == currentPageModuleLocalisation.LanguageId); if (pageModuleLocalisation == null) { context.Remove(currentPageModuleLocalisation); } } foreach (var pageModuleLocalisation in pageModuleLocalisations) { var currentPageModuleLocalisation = context.PageModuleLocalisations .AsNoTracking() .FirstOrDefault(x => x.PageModuleId == pageModuleLocalisation.PageModuleId && x.LanguageId == pageModuleLocalisation.LanguageId); if (currentPageModuleLocalisation == null) { context.Add(pageModuleLocalisation); } else { context.Entry(pageModuleLocalisation).State = EntityState.Modified; } } }
private void UpdateSiteLocalisations(WeapsyDbContext context, Guid siteId, IEnumerable <SiteLocalisationDbEntity> siteLocalisations) { var currentSiteLocalisations = context.SiteLocalisations .AsNoTracking() .Where(x => x.SiteId == siteId) .ToList(); foreach (var currentSiteLocalisation in currentSiteLocalisations) { var siteLocalisation = siteLocalisations .FirstOrDefault(x => x.LanguageId == currentSiteLocalisation.LanguageId); if (siteLocalisation == null) { context.Remove(currentSiteLocalisation); } } foreach (var siteLocalisation in siteLocalisations) { var currentSiteLocalisation = context.SiteLocalisations .AsNoTracking() .FirstOrDefault(x => x.SiteId == siteLocalisation.SiteId && x.LanguageId == siteLocalisation.LanguageId); if (currentSiteLocalisation == null) { context.Add(siteLocalisation); } else { context.Entry(siteLocalisation).State = EntityState.Modified; } } }