Classes to manage friendships between groups,
People can have one-directional friendships and names,
Groups can have people and their relationships.
var groupTask = Group.GetGroupAsync(10);
var group = await groupTask;
group.RandomizeFriendships();
group.Show();
group.People.ForEach(p => p.Introduce());
Mr Herman Knight
Mr Mahmoud Demir
Mrs Toni Ross
Mr حسین سالاری
Mr Salah Tonnaer
Mr Mario Herrero
Mr Cristobal Gonzalez
Miss Dirce Ribeiro
Ms Valentine Siekmann
Mr Mustafa Okumuş
× 0 0 1 1 1 0 1 0 0
0 × 0 0 0 0 1 0 1 0
0 0 × 0 0 0 0 0 0 0
1 0 0 × 1 0 0 0 0 1
1 0 0 1 × 1 0 0 0 0
1 0 0 0 1 × 0 0 0 0
0 1 0 0 0 0 × 0 1 0
1 0 0 0 0 0 0 × 0 0
0 0 0 0 0 0 1 0 × 0
0 0 0 1 0 0 0 0 0 ×
My name is Mr Herman Knight,
My friends are
Mr حسین سالاری
Mr Salah Tonnaer
Mr Mario Herrero
Miss Dirce Ribeiro
My name is Mr Mahmoud Demir,
My friends are
Mr Cristobal Gonzalez
Ms Valentine Siekmann
My name is Mrs Toni Ross,
I have no friends...
My name is Mr حسین سالاری,
My friends are
Mr Herman Knight
Mr Salah Tonnaer
Mr Mustafa Okumuş
My name is Mr Salah Tonnaer,
My friends are
Mr Herman Knight
Mr حسین سالاری
Mr Mario Herrero
My name is Mr Mario Herrero,
My friends are
Mr Herman Knight
Mr Salah Tonnaer
My name is Mr Cristobal Gonzalez,
My friends are
Mr Mahmoud Demir
Ms Valentine Siekmann
My name is Miss Dirce Ribeiro,
My friends are
Mr Herman Knight
My name is Ms Valentine Siekmann,
My friends are
Mr Cristobal Gonzalez
My name is Mr Mustafa Okumuş,
My friends are
Mr حسین سالاری
var robbie = new Person("Robbie");
var heather = new Person("Heather");
Person.CreateFriendship(robbie, heather);
heather.Unfriend(robbie)
Robbie
Heather
Corey
Stranger
0 1 1 0
1 0 1 0
1 0 0 0
0 0 1 0
My name is Robbie,
My friends are
Heather
Corey
My name is Heather,
My friends are
Robbie
Corey
My name is Corey,
My friends are
Robbie
My name is Stranger,
My friends are
Corey
var graph = new int[3,3]
{
{0,1,1},
{1,0,0},
{1,1,0}
};
var names = new List<String> {"Gavin", "Scott", "Robbie"};
var group2 = new Group(graph, names);
group2.Show();
foreach (Person p in group2.People)
{
p.Introduce();
};
Gavin
Scott
Robbie
0 1 1
1 0 0
1 1 0
My name is Gavin,
My friends are
Scott
Robbie
My name is Scott,
My friends are
Gavin
My name is Robbie,
My friends are
Gavin
Scott
robbie@BOOK:~/Scratch$ service postgresql status
12/main (port 5432): online
{ "ConnectionStrings": { "DefaultConnection": "Server={{server}};Port={{port}};Database={{db_name}};User Id={{user_name}};Password={{password}};" } }
robbie@BOOK:~/Scratch$ dotnet-ef migrations script Build started... Build succeeded. info: Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 5.0.6 initialized 'ScratchContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: None CREATE TABLE IF NOT EXISTS "__EFMigrationsHistory" ( "MigrationId" character varying(150) NOT NULL, "ProductVersion" character varying(32) NOT NULL, CONSTRAINT "PK___EFMigrationsHistory" PRIMARY KEY ("MigrationId") );
START TRANSACTION;
CREATE TABLE "Persons" ( "Id" integer NOT NULL GENERATED BY DEFAULT AS IDENTITY, "Name" character varying(100) NULL, CONSTRAINT "PK_Persons" PRIMARY KEY ("Id") );
CREATE TABLE "Friendships" ( "Id" integer NOT NULL, "PersonId" integer NOT NULL, "OtherPersonId" integer NOT NULL, CONSTRAINT "PK_Friendships" PRIMARY KEY ("Id"), CONSTRAINT "FK_Friendships_Persons_Id" FOREIGN KEY ("Id") REFERENCES "Persons" ("Id") ON DELETE CASCADE, CONSTRAINT "FK_Friendships_Persons_OtherPersonId" FOREIGN KEY ("OtherPersonId") REFERENCES "Persons" ("Id") ON DELETE CASCADE );
CREATE INDEX "IX_Friendships_OtherPersonId" ON "Friendships" ("OtherPersonId");
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20210512185014_Initial', '5.0.6');
COMMIT;
START TRANSACTION;
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20210512203130_Second', '5.0.6');
COMMIT;
START TRANSACTION;
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20210512203404_Third', '5.0.6');
COMMIT;
START TRANSACTION;
ALTER TABLE "Friendships" DROP CONSTRAINT "FK_Friendships_Persons_Id";
ALTER TABLE "Friendships" DROP CONSTRAINT "PK_Friendships";
ALTER TABLE "Friendships" ADD CONSTRAINT "PK_Friendships" PRIMARY KEY ("PersonId", "OtherPersonId");
ALTER TABLE "Friendships" ADD CONSTRAINT "FK_Friendships_Persons_PersonId" FOREIGN KEY ("PersonId") REFERENCES "Persons" ("Id") ON DELETE CASCADE;
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20210512204516_Fourth', '5.0.6');
COMMIT;
START TRANSACTION;
ALTER TABLE "Friendships" DROP CONSTRAINT "PK_Friendships";
ALTER TABLE "Friendships" ALTER COLUMN "Id" DROP DEFAULT; ALTER TABLE "Friendships" ALTER COLUMN "Id" ADD GENERATED BY DEFAULT AS IDENTITY;
ALTER TABLE "Friendships" ADD CONSTRAINT "PK_Friendships" PRIMARY KEY ("Id");
CREATE INDEX "IX_Friendships_PersonId" ON "Friendships" ("PersonId");
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion") VALUES ('20210512205414_Fifth', '5.0.6');
COMMIT;
Build started... Build succeeded. info: Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 5.0.6 initialized 'ScratchContext' using provider 'Npgsql.EntityFrameworkCore.PostgreSQL' with options: None info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (9ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory'); info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT EXISTS (SELECT 1 FROM pg_catalog.pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace WHERE c.relname='__EFMigrationsHistory'); info: Microsoft.EntityFrameworkCore.Database.Command[20101] Executed DbCommand (1ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] SELECT "MigrationId", "ProductVersion" FROM "__EFMigrationsHistory" ORDER BY "MigrationId"; info: Microsoft.EntityFrameworkCore.Migrations[20405] No migrations were applied. The database is already up to date. No migrations were applied. The database is already up to date. Done.