/// <summary> /// The Add. /// </summary> /// <param name="context"> /// The context. /// </param> public static void Add(FirebrickContext context) { var userRole1 = new UserRole { UserRoleId = 1, RoleId = 1, UserId = 1 }; var userRole2 = new UserRole { UserRoleId = 2, RoleId = 10, UserId = 1 }; var userRole3 = new UserRole { UserRoleId = 3, RoleId = 9, UserId = 2 }; var userRole4 = new UserRole { UserRoleId = 4, RoleId = 10, UserId = 2 }; context.UserRoles.AddOrUpdate(userRole1); context.UserRoles.AddOrUpdate(userRole2); context.UserRoles.AddOrUpdate(userRole3); context.UserRoles.AddOrUpdate(userRole4); try { context.SaveChanges(); } catch (DbEntityValidationException dbEx) { foreach (DbEntityValidationResult validationErrors in dbEx.EntityValidationErrors) { foreach (DbValidationError validationError in validationErrors.ValidationErrors) { Debug.WriteLine( "Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage); } } } }
private void AddNewUserRole(int roleId, int userId) { UserRole newUserRole = this.userRolesService.Get(roleId, userId); if (newUserRole == null) { newUserRole = new UserRole { RoleId = roleId, UserId = userId }; this.userRolesService.Add(newUserRole); } }