private async Task AddPermision(MapTemplateContext _ctx) { var adminRole = await _ctx.Roles.FirstOrDefaultAsync(r => r.RoleName == "Administrator"); if (adminRole != null) { var mangementPermissions = new Permissions(); var permissions = mangementPermissions.GetPermissions(); foreach (var permission in permissions) { if (!_ctx.Permission.Any(x => x.Name == permission.Name)) { var newPermission = new Permission { Name = permission.Name, Category = permission.Category, Description = permission.Description, DisplayName = permission.DisplayName }; _ctx.Permission.Add(newPermission); _ctx.SaveChanges(); _ctx.PermissionRoles.Add(new PermissionRole { PermissionId = newPermission.Id, RoleId = adminRole.Id }); _ctx.SaveChanges(); } } } }
private void AddMapType(MapTemplateContext _ctx) { var mapTypeMange = new mapTypes(); var mapTypes = mapTypeMange.GetMapTypes(); foreach (var type in mapTypes) { var mapType = _ctx.MapTypes.SingleOrDefault(x => x.Id == type.Id); if (mapType == null) { var newType = new MapType { Id = type.Id, Name = type.Name, Value = type.Value }; _ctx.MapTypes.Add(newType); _ctx.SaveChanges(); } } }
public DemoContextSeed(ILogger <DemoContextSeed> logger, MapTemplateContext context) { _logger = logger; _ctx = context; }