public void Seed(MeetingContext context, IWebHostEnvironment env, IOptions <MeetingSettings> settings, ILogger <MeetingContextSeed> logger) { var policy = CreatePolicy(logger, nameof(MeetingContextSeed)); policy.Execute(() => { foreach (var role in GetPreconfiguredRoles()) { AddOrInsert(context, role); } context.SaveChanges(); }); }
private void AddOrInsert(MeetingContext context, Role role) { Role entity = context.Roles.Find(role.Id); if (null == entity) { context.Add(role); } else { entity.Active = role.Active; entity.Name = role.Name; entity.Note = role.Note; entity.Order = role.Order; context.Update(entity); } }