🚧 Work in progress on entities

WORK-EF_WebAPI
Antoine PEREDERII 1 year ago
parent 4dcacf163f
commit 39de7eb0ae

@ -8,6 +8,7 @@
using Entities; using Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations.Operations;
namespace DbContextLib namespace DbContextLib
{ {
@ -112,6 +113,11 @@ namespace DbContextLib
modelBuilder.Entity<AthleteEntity>() modelBuilder.Entity<AthleteEntity>()
.Property(at => at.IdAthlete) .Property(at => at.IdAthlete)
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
// add image column type
// modelBuilder.Entity<AthleteEntity>()
// .Property(at => at.ProfilPicture)
// .HasColumnType("image");
//primary key of StatisticEntity //primary key of StatisticEntity
modelBuilder.Entity<StatisticEntity>() modelBuilder.Entity<StatisticEntity>()
@ -121,7 +127,7 @@ namespace DbContextLib
.Property(s => s.IdStatistic) .Property(s => s.IdStatistic)
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
//primary key of //primary key of TrainingEntity
modelBuilder.Entity<TrainingEntity>() modelBuilder.Entity<TrainingEntity>()
.HasKey(t => t.IdTraining); .HasKey(t => t.IdTraining);
//generation mode (at insertion) //generation mode (at insertion)
@ -129,7 +135,7 @@ namespace DbContextLib
.Property(t => t.IdTraining) .Property(t => t.IdTraining)
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
//primary key of //primary key of NotificationEntity
modelBuilder.Entity<NotificationEntity>() modelBuilder.Entity<NotificationEntity>()
.HasKey(n => n.IdNotif); .HasKey(n => n.IdNotif);
//generation mode (at insertion) //generation mode (at insertion)
@ -137,28 +143,57 @@ namespace DbContextLib
.Property(n => n.IdNotif) .Property(n => n.IdNotif)
.ValueGeneratedOnAdd(); .ValueGeneratedOnAdd();
modelBuilder.Entity<FriendshipEntity>()
.HasKey(f => new { f.FollowingId, f.FollowerId });
modelBuilder.Entity<FriendshipEntity>()
.HasOne(fing => fing.Following)
.WithMany(fings => fings.Followings)
.HasForeignKey(fing => fing.FollowingId);
modelBuilder.Entity<FriendshipEntity>()
.HasOne(fer => fer.Follower)
.WithMany(fers => fers.Followers)
.HasForeignKey(fing => fing.FollowerId);
// !
// ? Plusieurs questions sur les required ou non, différence difficile à comprendre
modelBuilder.Entity<AthleteEntity>() modelBuilder.Entity<AthleteEntity>()
.HasMany(at => at.Trainings) .HasMany(at => at.TrainingsCoach)
.WithOne(n => n.Athlete) .WithOne(tc => tc.Coach)
.HasForeignKey(n => n.AthleteId) .HasForeignKey(tc => tc.CoachId);
.IsRequired();
modelBuilder.Entity<AthleteEntity>() modelBuilder.Entity<AthleteEntity>()
.HasMany(at => at.Trainings) .HasMany(at => at.TrainingsAthlete)
.WithOne(t => t.Athlete) .WithMany(ta => ta.Athletes);
.HasForeignKey(t => t.AthleteId)
.IsRequired(); modelBuilder.Entity<AthleteEntity>()
.HasMany(at => at.NotificationsReceived)
.WithMany(nr => nr.Receivers);
modelBuilder.Entity<AthleteEntity>()
.HasMany(at => at.NotificationsSent)
.WithOne(ns => ns.Sender)
.HasForeignKey(ns => ns.SenderId);
// required car on veut toujours savoir le receveur et l'envoyeur de la notification meme admin ou systeme
modelBuilder.Entity<AthleteEntity>() modelBuilder.Entity<AthleteEntity>()
.HasMany(at => at.Statistics) .HasMany(at => at.Statistics)
.WithOne(s => s.Athlete) .WithOne(s => s.Athlete)
.HasForeignKey(s => s.AthleteId) .HasForeignKey(s => s.AthleteId)
.IsRequired(); .IsRequired(false);
modelBuilder.Entity<AthleteEntity>() modelBuilder.Entity<AthleteEntity>()
.HasMany(at => at.Activities) .HasMany(at => at.Activities)
.WithOne(a => a.Athlete) .WithOne(a => a.Athlete)
.HasForeignKey(a => a.AthleteId) .HasForeignKey(a => a.AthleteId)
.IsRequired(false);
modelBuilder.Entity<ActivityEntity>()
.HasMany(a => a.HeartRates)
.WithOne(h => h.Activity)
.HasForeignKey(h => h.ActivityId)
.IsRequired(); .IsRequired();
modelBuilder.Entity<DataSourceEntity>() modelBuilder.Entity<DataSourceEntity>()
@ -167,17 +202,20 @@ namespace DbContextLib
.HasForeignKey(a => a.DataSourceId) .HasForeignKey(a => a.DataSourceId)
.IsRequired(); .IsRequired();
modelBuilder.Entity<ActivityEntity>()
.HasMany(a => a.HeartRates)
.WithOne(h => h.Activity)
.HasForeignKey(h => h.ActivityId)
.IsRequired();
modelBuilder.Entity<DataSourceEntity>() modelBuilder.Entity<DataSourceEntity>()
.HasMany(ds => ds.Activities) .HasMany(ds => ds.Activities)
.WithOne(at => at.DataSource) .WithOne(at => at.DataSource)
.HasForeignKey(at => at.DataSourceId) .HasForeignKey(at => at.DataSourceId)
.IsRequired(false); .IsRequired(false);
// modelBuilder.Entity<AthleteEntity>()
// .HasMany(fer => fer.Followers)
// .WithMany(fing => fing.Followings)
// .UsingEntity<FriendshipEntity>(
// l => l.HasOne<AthleteEntity>().WithMany().HasForeignKey(fer => fer.FollowerId),
// r => r.HasOne<AthleteEntity>().WithMany().HasForeignKey(fing => fing.FollowingId),
// j => j.Property(f => f.StartDate).HasDefaultValueSql("CURRENT_TIMESTAMP")
// );
} }
} }
} }

@ -87,18 +87,25 @@ namespace Entities
/// </summary> /// </summary>
public bool IsCoach { get; set; } public bool IsCoach { get; set; }
public required byte[] ProfilPicture { get; set; }
public ICollection<ActivityEntity> Activities { get; set; } = new List<ActivityEntity>(); public ICollection<ActivityEntity> Activities { get; set; } = new List<ActivityEntity>();
public ICollection<StatisticEntity> Statistics { get; set; } = new List<StatisticEntity>(); public ICollection<StatisticEntity> Statistics { get; set; } = new List<StatisticEntity>();
public ICollection<TrainingEntity> Trainings { get; set; } = new List<TrainingEntity>(); public ICollection<TrainingEntity> TrainingsAthlete { get; set; } = new List<TrainingEntity>();
public ICollection<TrainingEntity> TrainingsCoach { get; set; } = new List<TrainingEntity>();
public ICollection<NotificationEntity> Notifications { get; set; } = new List<NotificationEntity>(); public ICollection<NotificationEntity> NotificationsReceived { get; set; } = new List<NotificationEntity>();
public ICollection<NotificationEntity> NotificationsSent { get; set; } = new List<NotificationEntity>();
public int? DataSourceId { get; set; } public int? DataSourceId { get; set; }
public DataSourceEntity? DataSource { get; set; } public DataSourceEntity? DataSource { get; set; }
public ICollection<AthleteEntity> public ICollection<FriendshipEntity> Followers { get; set; } = [];
public ICollection<FriendshipEntity> Followings { get; set; } = [];
} }
} }

@ -0,0 +1,14 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Entities;
public class FriendshipEntity
{
[ForeignKey("FollowingId")]
public int FollowingId { get; set; }
public AthleteEntity Following { get; set; }
[ForeignKey("FollowerId")]
public int FollowerId { get; set; }
public AthleteEntity Follower { get; set; }
public DateTime StartDate { get; set; }
}

@ -49,8 +49,9 @@ namespace Entities
[MaxLength(100)] [MaxLength(100)]
public string Urgence { get; set; } = null!; public string Urgence { get; set; } = null!;
public int AthleteId { get; set; } public int SenderId { get; set; }
public AthleteEntity Athlete { get; set; } = null!; public AthleteEntity Sender { get; set; } = null!;
public ICollection<AthleteEntity> Receivers { get; set; } = new List<AthleteEntity>();
} }
} }

@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
public class Picture
{
[Key]
public Guid Id { get; set; }
[Required]
public byte[] Bytes { get; set; }
}

@ -53,8 +53,9 @@ namespace Entities
[MaxLength(300)] [MaxLength(300)]
public string? FeedBack { get; set; } public string? FeedBack { get; set; }
public int AthleteId { get; set; } public int CoachId { get; set; }
public AthleteEntity Athlete { get; set; } = null!; public AthleteEntity Coach { get; set; } = null!;
public ICollection<AthleteEntity> Athletes { get; set; } = new List<AthleteEntity>();
} }
} }

@ -0,0 +1,49 @@
//-----------------------------------------------------------------------
// FILENAME: FriendshipStubbedContext.cs
// PROJECT: StubbedContextLib
// SOLUTION: HeartTrack
// DATE CREATED: 22/02/2024
// AUTHOR: Antoine PEREDERII
//-----------------------------------------------------------------------
using DbContextLib;
using Entities;
using Microsoft.EntityFrameworkCore;
namespace StubbedContextLib
{
/// <summary>
/// Represents the stubbed context for friendship entities.
/// </summary>
public class FriendshipStubbedContext : DataSourceStubbedContext
{
/// <summary>
/// Initializes a new instance of the <see cref="FriendshipStubbedContext"/> class.
/// </summary>
public FriendshipStubbedContext() : base() { }
/// <summary>
/// Initializes a new instance of the <see cref="FriendshipStubbedContext"/> class with the specified options.
/// </summary>
/// <param name="options">The options for the context.</param>
public FriendshipStubbedContext(DbContextOptions<LibraryContext> options) : base(options) { }
/// <summary>
/// Configures the model for the heart rate stubbed context.
/// </summary>
/// <param name="modelBuilder">The model builder instance.</param>
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<FriendshipEntity>().HasData(
new FriendshipEntity { FollowerId = 1, FollowingId = 2 },
new FriendshipEntity { FollowerId = 1, FollowingId = 3 },
new FriendshipEntity { FollowerId = 1, FollowingId = 4 },
new FriendshipEntity { FollowerId = 1, FollowingId = 5 },
new FriendshipEntity { FollowerId = 2, FollowingId = 1 },
new FriendshipEntity { FollowerId = 2, FollowingId = 3 }
);
}
}
}

@ -15,7 +15,7 @@ namespace StubbedContextLib
/// <summary> /// <summary>
/// Represents the stubbed context for heart rate entities. /// Represents the stubbed context for heart rate entities.
/// </summary> /// </summary>
public class HeartRateStubbedContext : DataSourceStubbedContext public class HeartRateStubbedContext : FriendshipStubbedContext
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="HeartRateStubbedContext"/> class. /// Initializes a new instance of the <see cref="HeartRateStubbedContext"/> class.

@ -11,7 +11,7 @@ using StubbedContextLib;
namespace StubbedContextLib.Migrations namespace StubbedContextLib.Migrations
{ {
[DbContext(typeof(TrainingStubbedContext))] [DbContext(typeof(TrainingStubbedContext))]
[Migration("20240226170604_MyMigrations")] [Migration("20240307081406_MyMigrations")]
partial class MyMigrations partial class MyMigrations
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -20,6 +20,36 @@ namespace StubbedContextLib.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2"); modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("AthleteEntityNotificationEntity", b =>
{
b.Property<int>("NotificationsReceivedIdNotif")
.HasColumnType("INTEGER");
b.Property<int>("ReceiversIdAthlete")
.HasColumnType("INTEGER");
b.HasKey("NotificationsReceivedIdNotif", "ReceiversIdAthlete");
b.HasIndex("ReceiversIdAthlete");
b.ToTable("AthleteEntityNotificationEntity");
});
modelBuilder.Entity("AthleteEntityTrainingEntity", b =>
{
b.Property<int>("AthletesIdAthlete")
.HasColumnType("INTEGER");
b.Property<int>("TrainingsAthleteIdTraining")
.HasColumnType("INTEGER");
b.HasKey("AthletesIdAthlete", "TrainingsAthleteIdTraining");
b.HasIndex("TrainingsAthleteIdTraining");
b.ToTable("AthleteEntityTrainingEntity");
});
modelBuilder.Entity("Entities.ActivityEntity", b => modelBuilder.Entity("Entities.ActivityEntity", b =>
{ {
b.Property<int>("IdActivity") b.Property<int>("IdActivity")
@ -409,6 +439,62 @@ namespace StubbedContextLib.Migrations
}); });
}); });
modelBuilder.Entity("Entities.FriendshipEntity", b =>
{
b.Property<int>("FollowingId")
.HasColumnType("INTEGER");
b.Property<int>("FollowerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("StartDate")
.HasColumnType("TEXT");
b.HasKey("FollowingId", "FollowerId");
b.HasIndex("FollowerId");
b.ToTable("FriendshipEntity");
b.HasData(
new
{
FollowingId = 2,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 3,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 4,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 5,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 1,
FollowerId = 2,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 3,
FollowerId = 2,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
});
});
modelBuilder.Entity("Entities.HeartRateEntity", b => modelBuilder.Entity("Entities.HeartRateEntity", b =>
{ {
b.Property<int>("IdHeartRate") b.Property<int>("IdHeartRate")
@ -506,9 +592,6 @@ namespace StubbedContextLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("AthleteId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Date") b.Property<DateTime>("Date")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@ -517,6 +600,9 @@ namespace StubbedContextLib.Migrations
.HasMaxLength(100) .HasMaxLength(100)
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("SenderId")
.HasColumnType("INTEGER");
b.Property<bool>("Statut") b.Property<bool>("Statut")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
@ -527,7 +613,7 @@ namespace StubbedContextLib.Migrations
b.HasKey("IdNotif"); b.HasKey("IdNotif");
b.HasIndex("AthleteId"); b.HasIndex("SenderId");
b.ToTable("Notification"); b.ToTable("Notification");
@ -535,45 +621,45 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdNotif = 1, IdNotif = 1,
AthleteId = 1,
Date = new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), Date = new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified),
Message = "You have a new activity to check", Message = "You have a new activity to check",
SenderId = 1,
Statut = true, Statut = true,
Urgence = "A" Urgence = "A"
}, },
new new
{ {
IdNotif = 2, IdNotif = 2,
AthleteId = 2,
Date = new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), Date = new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified),
Message = "You have a new athlete to check", Message = "You have a new athlete to check",
SenderId = 2,
Statut = false, Statut = false,
Urgence = "3" Urgence = "3"
}, },
new new
{ {
IdNotif = 3, IdNotif = 3,
AthleteId = 3,
Date = new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), Date = new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified),
Message = "You have a new heart rate to check", Message = "You have a new heart rate to check",
SenderId = 3,
Statut = true, Statut = true,
Urgence = "2" Urgence = "2"
}, },
new new
{ {
IdNotif = 4, IdNotif = 4,
AthleteId = 4,
Date = new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), Date = new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified),
Message = "You have a new data source to check", Message = "You have a new data source to check",
SenderId = 4,
Statut = false, Statut = false,
Urgence = "1" Urgence = "1"
}, },
new new
{ {
IdNotif = 5, IdNotif = 5,
AthleteId = 5,
Date = new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), Date = new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified),
Message = "You have a new notification to check", Message = "You have a new notification to check",
SenderId = 5,
Statut = true, Statut = true,
Urgence = "3" Urgence = "3"
}); });
@ -668,7 +754,7 @@ namespace StubbedContextLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("AthleteId") b.Property<int>("CoachId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<DateOnly>("Date") b.Property<DateOnly>("Date")
@ -690,7 +776,7 @@ namespace StubbedContextLib.Migrations
b.HasKey("IdTraining"); b.HasKey("IdTraining");
b.HasIndex("AthleteId"); b.HasIndex("CoachId");
b.ToTable("Training"); b.ToTable("Training");
@ -698,7 +784,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 1, IdTraining = 1,
AthleteId = 1, CoachId = 1,
Date = new DateOnly(2024, 1, 19), Date = new DateOnly(2024, 1, 19),
Description = "Running", Description = "Running",
FeedBack = "Good", FeedBack = "Good",
@ -708,7 +794,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 2, IdTraining = 2,
AthleteId = 5, CoachId = 5,
Date = new DateOnly(2024, 2, 20), Date = new DateOnly(2024, 2, 20),
Description = "Cycling", Description = "Cycling",
Latitude = 48.8566f, Latitude = 48.8566f,
@ -717,7 +803,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 3, IdTraining = 3,
AthleteId = 4, CoachId = 4,
Date = new DateOnly(2024, 2, 21), Date = new DateOnly(2024, 2, 21),
FeedBack = "Good", FeedBack = "Good",
Latitude = 48.8566f, Latitude = 48.8566f,
@ -726,7 +812,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 4, IdTraining = 4,
AthleteId = 3, CoachId = 3,
Date = new DateOnly(2024, 2, 22), Date = new DateOnly(2024, 2, 22),
Description = "Running", Description = "Running",
FeedBack = "Good", FeedBack = "Good",
@ -736,7 +822,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 5, IdTraining = 5,
AthleteId = 1, CoachId = 1,
Date = new DateOnly(2024, 2, 23), Date = new DateOnly(2024, 2, 23),
Description = "Cycling", Description = "Cycling",
Latitude = 48.8566f, Latitude = 48.8566f,
@ -744,13 +830,41 @@ namespace StubbedContextLib.Migrations
}); });
}); });
modelBuilder.Entity("AthleteEntityNotificationEntity", b =>
{
b.HasOne("Entities.NotificationEntity", null)
.WithMany()
.HasForeignKey("NotificationsReceivedIdNotif")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.AthleteEntity", null)
.WithMany()
.HasForeignKey("ReceiversIdAthlete")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("AthleteEntityTrainingEntity", b =>
{
b.HasOne("Entities.AthleteEntity", null)
.WithMany()
.HasForeignKey("AthletesIdAthlete")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.TrainingEntity", null)
.WithMany()
.HasForeignKey("TrainingsAthleteIdTraining")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.ActivityEntity", b => modelBuilder.Entity("Entities.ActivityEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Athlete")
.WithMany("Activities") .WithMany("Activities")
.HasForeignKey("AthleteId") .HasForeignKey("AthleteId");
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.DataSourceEntity", "DataSource") b.HasOne("Entities.DataSourceEntity", "DataSource")
.WithMany("Activities") .WithMany("Activities")
@ -770,6 +884,25 @@ namespace StubbedContextLib.Migrations
b.Navigation("DataSource"); b.Navigation("DataSource");
}); });
modelBuilder.Entity("Entities.FriendshipEntity", b =>
{
b.HasOne("Entities.AthleteEntity", "Follower")
.WithMany("Followers")
.HasForeignKey("FollowerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.AthleteEntity", "Following")
.WithMany("Followings")
.HasForeignKey("FollowingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Follower");
b.Navigation("Following");
});
modelBuilder.Entity("Entities.HeartRateEntity", b => modelBuilder.Entity("Entities.HeartRateEntity", b =>
{ {
b.HasOne("Entities.ActivityEntity", "Activity") b.HasOne("Entities.ActivityEntity", "Activity")
@ -783,35 +916,33 @@ namespace StubbedContextLib.Migrations
modelBuilder.Entity("Entities.NotificationEntity", b => modelBuilder.Entity("Entities.NotificationEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Sender")
.WithMany("Notifications") .WithMany("NotificationsSent")
.HasForeignKey("AthleteId") .HasForeignKey("SenderId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Athlete"); b.Navigation("Sender");
}); });
modelBuilder.Entity("Entities.StatisticEntity", b => modelBuilder.Entity("Entities.StatisticEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Athlete")
.WithMany("Statistics") .WithMany("Statistics")
.HasForeignKey("AthleteId") .HasForeignKey("AthleteId");
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Athlete"); b.Navigation("Athlete");
}); });
modelBuilder.Entity("Entities.TrainingEntity", b => modelBuilder.Entity("Entities.TrainingEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Coach")
.WithMany("Trainings") .WithMany("TrainingsCoach")
.HasForeignKey("AthleteId") .HasForeignKey("CoachId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Athlete"); b.Navigation("Coach");
}); });
modelBuilder.Entity("Entities.ActivityEntity", b => modelBuilder.Entity("Entities.ActivityEntity", b =>
@ -823,11 +954,15 @@ namespace StubbedContextLib.Migrations
{ {
b.Navigation("Activities"); b.Navigation("Activities");
b.Navigation("Notifications"); b.Navigation("Followers");
b.Navigation("Followings");
b.Navigation("NotificationsSent");
b.Navigation("Statistics"); b.Navigation("Statistics");
b.Navigation("Trainings"); b.Navigation("TrainingsCoach");
}); });
modelBuilder.Entity("Entities.DataSourceEntity", b => modelBuilder.Entity("Entities.DataSourceEntity", b =>

@ -85,8 +85,7 @@ namespace StubbedContextLib.Migrations
name: "FK_Activity_Athlete_AthleteId", name: "FK_Activity_Athlete_AthleteId",
column: x => x.AthleteId, column: x => x.AthleteId,
principalTable: "Athlete", principalTable: "Athlete",
principalColumn: "IdAthlete", principalColumn: "IdAthlete");
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_Activity_DataSource_DataSourceId", name: "FK_Activity_DataSource_DataSourceId",
column: x => x.DataSourceId, column: x => x.DataSourceId,
@ -94,6 +93,31 @@ namespace StubbedContextLib.Migrations
principalColumn: "IdSource"); principalColumn: "IdSource");
}); });
migrationBuilder.CreateTable(
name: "FriendshipEntity",
columns: table => new
{
FollowingId = table.Column<int>(type: "INTEGER", nullable: false),
FollowerId = table.Column<int>(type: "INTEGER", nullable: false),
StartDate = table.Column<DateTime>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_FriendshipEntity", x => new { x.FollowingId, x.FollowerId });
table.ForeignKey(
name: "FK_FriendshipEntity_Athlete_FollowerId",
column: x => x.FollowerId,
principalTable: "Athlete",
principalColumn: "IdAthlete",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_FriendshipEntity_Athlete_FollowingId",
column: x => x.FollowingId,
principalTable: "Athlete",
principalColumn: "IdAthlete",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Notification", name: "Notification",
columns: table => new columns: table => new
@ -104,14 +128,14 @@ namespace StubbedContextLib.Migrations
Date = table.Column<DateTime>(type: "TEXT", nullable: false), Date = table.Column<DateTime>(type: "TEXT", nullable: false),
Statut = table.Column<bool>(type: "INTEGER", nullable: false), Statut = table.Column<bool>(type: "INTEGER", nullable: false),
Urgence = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false), Urgence = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
AthleteId = table.Column<int>(type: "INTEGER", nullable: false) SenderId = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Notification", x => x.IdNotif); table.PrimaryKey("PK_Notification", x => x.IdNotif);
table.ForeignKey( table.ForeignKey(
name: "FK_Notification_Athlete_AthleteId", name: "FK_Notification_Athlete_SenderId",
column: x => x.AthleteId, column: x => x.SenderId,
principalTable: "Athlete", principalTable: "Athlete",
principalColumn: "IdAthlete", principalColumn: "IdAthlete",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -137,8 +161,7 @@ namespace StubbedContextLib.Migrations
name: "FK_Statistic_Athlete_AthleteId", name: "FK_Statistic_Athlete_AthleteId",
column: x => x.AthleteId, column: x => x.AthleteId,
principalTable: "Athlete", principalTable: "Athlete",
principalColumn: "IdAthlete", principalColumn: "IdAthlete");
onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
@ -152,14 +175,14 @@ namespace StubbedContextLib.Migrations
Latitude = table.Column<float>(type: "REAL", nullable: false), Latitude = table.Column<float>(type: "REAL", nullable: false),
Longitude = table.Column<float>(type: "REAL", nullable: false), Longitude = table.Column<float>(type: "REAL", nullable: false),
FeedBack = table.Column<string>(type: "TEXT", maxLength: 300, nullable: true), FeedBack = table.Column<string>(type: "TEXT", maxLength: 300, nullable: true),
AthleteId = table.Column<int>(type: "INTEGER", nullable: false) CoachId = table.Column<int>(type: "INTEGER", nullable: false)
}, },
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Training", x => x.IdTraining); table.PrimaryKey("PK_Training", x => x.IdTraining);
table.ForeignKey( table.ForeignKey(
name: "FK_Training_Athlete_AthleteId", name: "FK_Training_Athlete_CoachId",
column: x => x.AthleteId, column: x => x.CoachId,
principalTable: "Athlete", principalTable: "Athlete",
principalColumn: "IdAthlete", principalColumn: "IdAthlete",
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
@ -190,6 +213,54 @@ namespace StubbedContextLib.Migrations
onDelete: ReferentialAction.Cascade); onDelete: ReferentialAction.Cascade);
}); });
migrationBuilder.CreateTable(
name: "AthleteEntityNotificationEntity",
columns: table => new
{
NotificationsReceivedIdNotif = table.Column<int>(type: "INTEGER", nullable: false),
ReceiversIdAthlete = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AthleteEntityNotificationEntity", x => new { x.NotificationsReceivedIdNotif, x.ReceiversIdAthlete });
table.ForeignKey(
name: "FK_AthleteEntityNotificationEntity_Athlete_ReceiversIdAthlete",
column: x => x.ReceiversIdAthlete,
principalTable: "Athlete",
principalColumn: "IdAthlete",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AthleteEntityNotificationEntity_Notification_NotificationsReceivedIdNotif",
column: x => x.NotificationsReceivedIdNotif,
principalTable: "Notification",
principalColumn: "IdNotif",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "AthleteEntityTrainingEntity",
columns: table => new
{
AthletesIdAthlete = table.Column<int>(type: "INTEGER", nullable: false),
TrainingsAthleteIdTraining = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AthleteEntityTrainingEntity", x => new { x.AthletesIdAthlete, x.TrainingsAthleteIdTraining });
table.ForeignKey(
name: "FK_AthleteEntityTrainingEntity_Athlete_AthletesIdAthlete",
column: x => x.AthletesIdAthlete,
principalTable: "Athlete",
principalColumn: "IdAthlete",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_AthleteEntityTrainingEntity_Training_TrainingsAthleteIdTraining",
column: x => x.TrainingsAthleteIdTraining,
principalTable: "Training",
principalColumn: "IdTraining",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "Athlete", table: "Athlete",
columns: new[] { "IdAthlete", "DataSourceId", "DateOfBirth", "Email", "FirstName", "IsCoach", "LastName", "Length", "Password", "Sexe", "Username", "Weight" }, columns: new[] { "IdAthlete", "DataSourceId", "DateOfBirth", "Email", "FirstName", "IsCoach", "LastName", "Length", "Password", "Sexe", "Username", "Weight" },
@ -233,14 +304,23 @@ namespace StubbedContextLib.Migrations
{ 5, 3, new DateOnly(1991, 1, 1), "bruce.lee@example.com", "Bruce", false, "Lee", 2.0, "hello321", "M", "Lee", 90f } { 5, 3, new DateOnly(1991, 1, 1), "bruce.lee@example.com", "Bruce", false, "Lee", 2.0, "hello321", "M", "Lee", 90f }
}); });
migrationBuilder.InsertData(
table: "FriendshipEntity",
columns: new[] { "FollowerId", "FollowingId", "StartDate" },
values: new object[,]
{
{ 1, 3, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) },
{ 1, 4, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) }
});
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "Notification", table: "Notification",
columns: new[] { "IdNotif", "AthleteId", "Date", "Message", "Statut", "Urgence" }, columns: new[] { "IdNotif", "Date", "Message", "SenderId", "Statut", "Urgence" },
values: new object[,] values: new object[,]
{ {
{ 1, 1, new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), "You have a new activity to check", true, "A" }, { 1, new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), "You have a new activity to check", 1, true, "A" },
{ 3, 3, new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), "You have a new heart rate to check", true, "2" }, { 3, new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), "You have a new heart rate to check", 3, true, "2" },
{ 4, 4, new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), "You have a new data source to check", false, "1" } { 4, new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), "You have a new data source to check", 4, false, "1" }
}); });
migrationBuilder.InsertData( migrationBuilder.InsertData(
@ -256,7 +336,7 @@ namespace StubbedContextLib.Migrations
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "Training", table: "Training",
columns: new[] { "IdTraining", "AthleteId", "Date", "Description", "FeedBack", "Latitude", "Longitude" }, columns: new[] { "IdTraining", "CoachId", "Date", "Description", "FeedBack", "Latitude", "Longitude" },
values: new object[,] values: new object[,]
{ {
{ 1, 1, new DateOnly(2024, 1, 19), "Running", "Good", 48.8566f, 2.3522f }, { 1, 1, new DateOnly(2024, 1, 19), "Running", "Good", 48.8566f, 2.3522f },
@ -274,6 +354,17 @@ namespace StubbedContextLib.Migrations
{ 4, 5, 0.5f, 20f, 3, new DateOnly(2024, 1, 2), 5, new TimeOnly(16, 1, 55), false, 0, 0, 0.5f, new TimeOnly(15, 0, 0), "Walking", 0.5f, 0.5f } { 4, 5, 0.5f, 20f, 3, new DateOnly(2024, 1, 2), 5, new TimeOnly(16, 1, 55), false, 0, 0, 0.5f, new TimeOnly(15, 0, 0), "Walking", 0.5f, 0.5f }
}); });
migrationBuilder.InsertData(
table: "FriendshipEntity",
columns: new[] { "FollowerId", "FollowingId", "StartDate" },
values: new object[,]
{
{ 2, 1, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) },
{ 1, 2, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) },
{ 2, 3, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) },
{ 1, 5, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified) }
});
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "HeartRate", table: "HeartRate",
columns: new[] { "IdHeartRate", "ActivityId", "Altitude", "Bpm", "Latitude", "Longitude", "Temperature", "Time" }, columns: new[] { "IdHeartRate", "ActivityId", "Altitude", "Bpm", "Latitude", "Longitude", "Temperature", "Time" },
@ -285,11 +376,11 @@ namespace StubbedContextLib.Migrations
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "Notification", table: "Notification",
columns: new[] { "IdNotif", "AthleteId", "Date", "Message", "Statut", "Urgence" }, columns: new[] { "IdNotif", "Date", "Message", "SenderId", "Statut", "Urgence" },
values: new object[,] values: new object[,]
{ {
{ 2, 2, new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), "You have a new athlete to check", false, "3" }, { 2, new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), "You have a new athlete to check", 2, false, "3" },
{ 5, 5, new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), "You have a new notification to check", true, "3" } { 5, new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), "You have a new notification to check", 5, true, "3" }
}); });
migrationBuilder.InsertData( migrationBuilder.InsertData(
@ -299,7 +390,7 @@ namespace StubbedContextLib.Migrations
migrationBuilder.InsertData( migrationBuilder.InsertData(
table: "Training", table: "Training",
columns: new[] { "IdTraining", "AthleteId", "Date", "Description", "FeedBack", "Latitude", "Longitude" }, columns: new[] { "IdTraining", "CoachId", "Date", "Description", "FeedBack", "Latitude", "Longitude" },
values: new object[] { 2, 5, new DateOnly(2024, 2, 20), "Cycling", null, 48.8566f, 2.3522f }); values: new object[] { 2, 5, new DateOnly(2024, 2, 20), "Cycling", null, 48.8566f, 2.3522f });
migrationBuilder.InsertData( migrationBuilder.InsertData(
@ -327,15 +418,30 @@ namespace StubbedContextLib.Migrations
table: "Athlete", table: "Athlete",
column: "DataSourceId"); column: "DataSourceId");
migrationBuilder.CreateIndex(
name: "IX_AthleteEntityNotificationEntity_ReceiversIdAthlete",
table: "AthleteEntityNotificationEntity",
column: "ReceiversIdAthlete");
migrationBuilder.CreateIndex(
name: "IX_AthleteEntityTrainingEntity_TrainingsAthleteIdTraining",
table: "AthleteEntityTrainingEntity",
column: "TrainingsAthleteIdTraining");
migrationBuilder.CreateIndex(
name: "IX_FriendshipEntity_FollowerId",
table: "FriendshipEntity",
column: "FollowerId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_HeartRate_ActivityId", name: "IX_HeartRate_ActivityId",
table: "HeartRate", table: "HeartRate",
column: "ActivityId"); column: "ActivityId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Notification_AthleteId", name: "IX_Notification_SenderId",
table: "Notification", table: "Notification",
column: "AthleteId"); column: "SenderId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Statistic_AthleteId", name: "IX_Statistic_AthleteId",
@ -343,23 +449,32 @@ namespace StubbedContextLib.Migrations
column: "AthleteId"); column: "AthleteId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Training_AthleteId", name: "IX_Training_CoachId",
table: "Training", table: "Training",
column: "AthleteId"); column: "CoachId");
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder) protected override void Down(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "HeartRate"); name: "AthleteEntityNotificationEntity");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Notification"); name: "AthleteEntityTrainingEntity");
migrationBuilder.DropTable(
name: "FriendshipEntity");
migrationBuilder.DropTable(
name: "HeartRate");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Statistic"); name: "Statistic");
migrationBuilder.DropTable(
name: "Notification");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Training"); name: "Training");

@ -17,6 +17,36 @@ namespace StubbedContextLib.Migrations
#pragma warning disable 612, 618 #pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "8.0.2"); modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("AthleteEntityNotificationEntity", b =>
{
b.Property<int>("NotificationsReceivedIdNotif")
.HasColumnType("INTEGER");
b.Property<int>("ReceiversIdAthlete")
.HasColumnType("INTEGER");
b.HasKey("NotificationsReceivedIdNotif", "ReceiversIdAthlete");
b.HasIndex("ReceiversIdAthlete");
b.ToTable("AthleteEntityNotificationEntity");
});
modelBuilder.Entity("AthleteEntityTrainingEntity", b =>
{
b.Property<int>("AthletesIdAthlete")
.HasColumnType("INTEGER");
b.Property<int>("TrainingsAthleteIdTraining")
.HasColumnType("INTEGER");
b.HasKey("AthletesIdAthlete", "TrainingsAthleteIdTraining");
b.HasIndex("TrainingsAthleteIdTraining");
b.ToTable("AthleteEntityTrainingEntity");
});
modelBuilder.Entity("Entities.ActivityEntity", b => modelBuilder.Entity("Entities.ActivityEntity", b =>
{ {
b.Property<int>("IdActivity") b.Property<int>("IdActivity")
@ -406,6 +436,62 @@ namespace StubbedContextLib.Migrations
}); });
}); });
modelBuilder.Entity("Entities.FriendshipEntity", b =>
{
b.Property<int>("FollowingId")
.HasColumnType("INTEGER");
b.Property<int>("FollowerId")
.HasColumnType("INTEGER");
b.Property<DateTime>("StartDate")
.HasColumnType("TEXT");
b.HasKey("FollowingId", "FollowerId");
b.HasIndex("FollowerId");
b.ToTable("FriendshipEntity");
b.HasData(
new
{
FollowingId = 2,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 3,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 4,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 5,
FollowerId = 1,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 1,
FollowerId = 2,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
},
new
{
FollowingId = 3,
FollowerId = 2,
StartDate = new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)
});
});
modelBuilder.Entity("Entities.HeartRateEntity", b => modelBuilder.Entity("Entities.HeartRateEntity", b =>
{ {
b.Property<int>("IdHeartRate") b.Property<int>("IdHeartRate")
@ -503,9 +589,6 @@ namespace StubbedContextLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("AthleteId")
.HasColumnType("INTEGER");
b.Property<DateTime>("Date") b.Property<DateTime>("Date")
.HasColumnType("TEXT"); .HasColumnType("TEXT");
@ -514,6 +597,9 @@ namespace StubbedContextLib.Migrations
.HasMaxLength(100) .HasMaxLength(100)
.HasColumnType("TEXT"); .HasColumnType("TEXT");
b.Property<int>("SenderId")
.HasColumnType("INTEGER");
b.Property<bool>("Statut") b.Property<bool>("Statut")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
@ -524,7 +610,7 @@ namespace StubbedContextLib.Migrations
b.HasKey("IdNotif"); b.HasKey("IdNotif");
b.HasIndex("AthleteId"); b.HasIndex("SenderId");
b.ToTable("Notification"); b.ToTable("Notification");
@ -532,45 +618,45 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdNotif = 1, IdNotif = 1,
AthleteId = 1,
Date = new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified), Date = new DateTime(2023, 12, 25, 13, 0, 40, 0, DateTimeKind.Unspecified),
Message = "You have a new activity to check", Message = "You have a new activity to check",
SenderId = 1,
Statut = true, Statut = true,
Urgence = "A" Urgence = "A"
}, },
new new
{ {
IdNotif = 2, IdNotif = 2,
AthleteId = 2,
Date = new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified), Date = new DateTime(2023, 12, 26, 13, 10, 40, 0, DateTimeKind.Unspecified),
Message = "You have a new athlete to check", Message = "You have a new athlete to check",
SenderId = 2,
Statut = false, Statut = false,
Urgence = "3" Urgence = "3"
}, },
new new
{ {
IdNotif = 3, IdNotif = 3,
AthleteId = 3,
Date = new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified), Date = new DateTime(2023, 12, 26, 16, 10, 4, 0, DateTimeKind.Unspecified),
Message = "You have a new heart rate to check", Message = "You have a new heart rate to check",
SenderId = 3,
Statut = true, Statut = true,
Urgence = "2" Urgence = "2"
}, },
new new
{ {
IdNotif = 4, IdNotif = 4,
AthleteId = 4,
Date = new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified), Date = new DateTime(2024, 1, 12, 9, 30, 50, 0, DateTimeKind.Unspecified),
Message = "You have a new data source to check", Message = "You have a new data source to check",
SenderId = 4,
Statut = false, Statut = false,
Urgence = "1" Urgence = "1"
}, },
new new
{ {
IdNotif = 5, IdNotif = 5,
AthleteId = 5,
Date = new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified), Date = new DateTime(2024, 2, 22, 12, 10, 0, 0, DateTimeKind.Unspecified),
Message = "You have a new notification to check", Message = "You have a new notification to check",
SenderId = 5,
Statut = true, Statut = true,
Urgence = "3" Urgence = "3"
}); });
@ -665,7 +751,7 @@ namespace StubbedContextLib.Migrations
.ValueGeneratedOnAdd() .ValueGeneratedOnAdd()
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<int>("AthleteId") b.Property<int>("CoachId")
.HasColumnType("INTEGER"); .HasColumnType("INTEGER");
b.Property<DateOnly>("Date") b.Property<DateOnly>("Date")
@ -687,7 +773,7 @@ namespace StubbedContextLib.Migrations
b.HasKey("IdTraining"); b.HasKey("IdTraining");
b.HasIndex("AthleteId"); b.HasIndex("CoachId");
b.ToTable("Training"); b.ToTable("Training");
@ -695,7 +781,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 1, IdTraining = 1,
AthleteId = 1, CoachId = 1,
Date = new DateOnly(2024, 1, 19), Date = new DateOnly(2024, 1, 19),
Description = "Running", Description = "Running",
FeedBack = "Good", FeedBack = "Good",
@ -705,7 +791,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 2, IdTraining = 2,
AthleteId = 5, CoachId = 5,
Date = new DateOnly(2024, 2, 20), Date = new DateOnly(2024, 2, 20),
Description = "Cycling", Description = "Cycling",
Latitude = 48.8566f, Latitude = 48.8566f,
@ -714,7 +800,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 3, IdTraining = 3,
AthleteId = 4, CoachId = 4,
Date = new DateOnly(2024, 2, 21), Date = new DateOnly(2024, 2, 21),
FeedBack = "Good", FeedBack = "Good",
Latitude = 48.8566f, Latitude = 48.8566f,
@ -723,7 +809,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 4, IdTraining = 4,
AthleteId = 3, CoachId = 3,
Date = new DateOnly(2024, 2, 22), Date = new DateOnly(2024, 2, 22),
Description = "Running", Description = "Running",
FeedBack = "Good", FeedBack = "Good",
@ -733,7 +819,7 @@ namespace StubbedContextLib.Migrations
new new
{ {
IdTraining = 5, IdTraining = 5,
AthleteId = 1, CoachId = 1,
Date = new DateOnly(2024, 2, 23), Date = new DateOnly(2024, 2, 23),
Description = "Cycling", Description = "Cycling",
Latitude = 48.8566f, Latitude = 48.8566f,
@ -741,13 +827,41 @@ namespace StubbedContextLib.Migrations
}); });
}); });
modelBuilder.Entity("AthleteEntityNotificationEntity", b =>
{
b.HasOne("Entities.NotificationEntity", null)
.WithMany()
.HasForeignKey("NotificationsReceivedIdNotif")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.AthleteEntity", null)
.WithMany()
.HasForeignKey("ReceiversIdAthlete")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("AthleteEntityTrainingEntity", b =>
{
b.HasOne("Entities.AthleteEntity", null)
.WithMany()
.HasForeignKey("AthletesIdAthlete")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.TrainingEntity", null)
.WithMany()
.HasForeignKey("TrainingsAthleteIdTraining")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Entities.ActivityEntity", b => modelBuilder.Entity("Entities.ActivityEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Athlete")
.WithMany("Activities") .WithMany("Activities")
.HasForeignKey("AthleteId") .HasForeignKey("AthleteId");
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.DataSourceEntity", "DataSource") b.HasOne("Entities.DataSourceEntity", "DataSource")
.WithMany("Activities") .WithMany("Activities")
@ -767,6 +881,25 @@ namespace StubbedContextLib.Migrations
b.Navigation("DataSource"); b.Navigation("DataSource");
}); });
modelBuilder.Entity("Entities.FriendshipEntity", b =>
{
b.HasOne("Entities.AthleteEntity", "Follower")
.WithMany("Followers")
.HasForeignKey("FollowerId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Entities.AthleteEntity", "Following")
.WithMany("Followings")
.HasForeignKey("FollowingId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Follower");
b.Navigation("Following");
});
modelBuilder.Entity("Entities.HeartRateEntity", b => modelBuilder.Entity("Entities.HeartRateEntity", b =>
{ {
b.HasOne("Entities.ActivityEntity", "Activity") b.HasOne("Entities.ActivityEntity", "Activity")
@ -780,35 +913,33 @@ namespace StubbedContextLib.Migrations
modelBuilder.Entity("Entities.NotificationEntity", b => modelBuilder.Entity("Entities.NotificationEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Sender")
.WithMany("Notifications") .WithMany("NotificationsSent")
.HasForeignKey("AthleteId") .HasForeignKey("SenderId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Athlete"); b.Navigation("Sender");
}); });
modelBuilder.Entity("Entities.StatisticEntity", b => modelBuilder.Entity("Entities.StatisticEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Athlete")
.WithMany("Statistics") .WithMany("Statistics")
.HasForeignKey("AthleteId") .HasForeignKey("AthleteId");
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Athlete"); b.Navigation("Athlete");
}); });
modelBuilder.Entity("Entities.TrainingEntity", b => modelBuilder.Entity("Entities.TrainingEntity", b =>
{ {
b.HasOne("Entities.AthleteEntity", "Athlete") b.HasOne("Entities.AthleteEntity", "Coach")
.WithMany("Trainings") .WithMany("TrainingsCoach")
.HasForeignKey("AthleteId") .HasForeignKey("CoachId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Athlete"); b.Navigation("Coach");
}); });
modelBuilder.Entity("Entities.ActivityEntity", b => modelBuilder.Entity("Entities.ActivityEntity", b =>
@ -820,11 +951,15 @@ namespace StubbedContextLib.Migrations
{ {
b.Navigation("Activities"); b.Navigation("Activities");
b.Navigation("Notifications"); b.Navigation("Followers");
b.Navigation("Followings");
b.Navigation("NotificationsSent");
b.Navigation("Statistics"); b.Navigation("Statistics");
b.Navigation("Trainings"); b.Navigation("TrainingsCoach");
}); });
modelBuilder.Entity("Entities.DataSourceEntity", b => modelBuilder.Entity("Entities.DataSourceEntity", b =>

@ -37,11 +37,11 @@ namespace StubbedContextLib
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
modelBuilder.Entity<NotificationEntity>().HasData( modelBuilder.Entity<NotificationEntity>().HasData(
new NotificationEntity { IdNotif = 1, Message = "You have a new activity to check", Date = new DateTime(2023, 12, 25, 13, 00, 40), Statut = true, Urgence = "A", AthleteId = 1 }, new NotificationEntity { IdNotif = 1, Message = "You have a new activity to check", Date = new DateTime(2023, 12, 25, 13, 00, 40), Statut = true, Urgence = "A", SenderId = 1 },
new NotificationEntity { IdNotif = 2, Message = "You have a new athlete to check", Date = new DateTime(2023, 12, 26, 13, 10, 40), Statut = false, Urgence = "3", AthleteId = 2 }, new NotificationEntity { IdNotif = 2, Message = "You have a new athlete to check", Date = new DateTime(2023, 12, 26, 13, 10, 40), Statut = false, Urgence = "3", SenderId = 2 },
new NotificationEntity { IdNotif = 3, Message = "You have a new heart rate to check", Date = new DateTime(2023, 12, 26, 16, 10, 04), Statut = true, Urgence = "2", AthleteId = 3 }, new NotificationEntity { IdNotif = 3, Message = "You have a new heart rate to check", Date = new DateTime(2023, 12, 26, 16, 10, 04), Statut = true, Urgence = "2", SenderId = 3 },
new NotificationEntity { IdNotif = 4, Message = "You have a new data source to check", Date = new DateTime(2024, 01, 12, 09, 30, 50), Statut = false, Urgence = "1", AthleteId = 4 }, new NotificationEntity { IdNotif = 4, Message = "You have a new data source to check", Date = new DateTime(2024, 01, 12, 09, 30, 50), Statut = false, Urgence = "1", SenderId = 4 },
new NotificationEntity { IdNotif = 5, Message = "You have a new notification to check", Date = new DateTime(2024, 02, 22, 12, 10, 00), Statut = true, Urgence = "3", AthleteId = 5 } new NotificationEntity { IdNotif = 5, Message = "You have a new notification to check", Date = new DateTime(2024, 02, 22, 12, 10, 00), Statut = true, Urgence = "3", SenderId = 5 }
); );
} }
} }

@ -37,11 +37,11 @@ namespace StubbedContextLib
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
modelBuilder.Entity<TrainingEntity>().HasData( modelBuilder.Entity<TrainingEntity>().HasData(
new TrainingEntity { IdTraining = 1, Date = new DateOnly(2024, 01, 19), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", AthleteId = 1 }, new TrainingEntity { IdTraining = 1, Date = new DateOnly(2024, 01, 19), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", CoachId = 1 },
new TrainingEntity { IdTraining = 2, Date = new DateOnly(2024, 02, 20), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f, AthleteId = 5 }, new TrainingEntity { IdTraining = 2, Date = new DateOnly(2024, 02, 20), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f, CoachId = 5 },
new TrainingEntity { IdTraining = 3, Date = new DateOnly(2024, 02, 21), Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", AthleteId = 4 }, new TrainingEntity { IdTraining = 3, Date = new DateOnly(2024, 02, 21), Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", CoachId = 4 },
new TrainingEntity { IdTraining = 4, Date = new DateOnly(2024, 02, 22), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", AthleteId = 3 }, new TrainingEntity { IdTraining = 4, Date = new DateOnly(2024, 02, 22), Description = "Running", Latitude = 48.8566f, Longitude = 2.3522f, FeedBack = "Good", CoachId = 3 },
new TrainingEntity { IdTraining = 5, Date = new DateOnly(2024, 02, 23), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f, AthleteId = 1 } new TrainingEntity { IdTraining = 5, Date = new DateOnly(2024, 02, 23), Description = "Cycling", Latitude = 48.8566f, Longitude = 2.3522f, CoachId = 1 }
); );
} }
} }

@ -16,6 +16,8 @@ class Program
DataSourceTests(db); DataSourceTests(db);
AthleteTests(db); AthleteTests(db);
FriendshipTests(db);
} }
} }
catch (Exception ex) catch (Exception ex)
@ -34,12 +36,12 @@ class Program
{ {
Console.WriteLine($"\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); Console.WriteLine($"\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}");
Console.WriteLine("\tFréquences cardiaques :"); Console.WriteLine("\t\tFréquences cardiaques :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var heartRate in activity.HeartRates) foreach (var heartRate in activity.HeartRates)
{ {
Console.WriteLine($"\t\t{heartRate.IdHeartRate} - {heartRate.Altitude}, {heartRate.Time}, {heartRate.Temperature}, {heartRate.Bpm}, {heartRate.Longitude}, {heartRate.Latitude}"); Console.WriteLine($"\t\t\t{heartRate.IdHeartRate} - {heartRate.Altitude}, {heartRate.Time}, {heartRate.Temperature}, {heartRate.Bpm}, {heartRate.Longitude}, {heartRate.Latitude}");
} }
} }
@ -52,12 +54,12 @@ class Program
{ {
Console.WriteLine($"\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); Console.WriteLine($"\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}");
Console.WriteLine("\tFréquences cardiaques :"); Console.WriteLine("\t\tFréquences cardiaques :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var heartRate in activity.HeartRates) foreach (var heartRate in activity.HeartRates)
{ {
Console.WriteLine($"\t\t{heartRate.IdHeartRate} - {heartRate.Altitude}, {heartRate.Time}, {heartRate.Temperature}, {heartRate.Bpm}, {heartRate.Longitude}, {heartRate.Latitude}"); Console.WriteLine($"\t\t\t{heartRate.IdHeartRate} - {heartRate.Altitude}, {heartRate.Time}, {heartRate.Temperature}, {heartRate.Bpm}, {heartRate.Longitude}, {heartRate.Latitude}");
} }
} }
} }
@ -69,24 +71,24 @@ class Program
Console.WriteLine("Sources de données :"); Console.WriteLine("Sources de données :");
Console.WriteLine("---------------------------------"); Console.WriteLine("---------------------------------");
foreach (var dataSource in db.DataSourcesSet.Include(ds => ds.Activities)) foreach (var dataSource in db.DataSourcesSet.Include(ds => ds.Activities).Include(ds => ds.Athletes))
{ {
Console.WriteLine($"\t{dataSource.IdSource} - {dataSource.Model}"); Console.WriteLine($"\t{dataSource.IdSource} - {dataSource.Model}");
Console.WriteLine("\tActivités :"); Console.WriteLine("\t\tActivités :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var activity in dataSource.Activities) foreach (var activity in dataSource.Activities)
{ {
Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); Console.WriteLine($"\t\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}");
} }
Console.WriteLine("\tAthletes :"); Console.WriteLine("\t\tAthletes :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var athlete in dataSource.Athletes) foreach (var athlete in dataSource.Athletes)
{ {
Console.WriteLine($"\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); Console.WriteLine($"\t\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
} }
} }
@ -95,24 +97,24 @@ class Program
Console.WriteLine("Accès à la source de données d'id '2' :"); Console.WriteLine("Accès à la source de données d'id '2' :");
Console.WriteLine("---------------------------------"); Console.WriteLine("---------------------------------");
foreach (var dataSource in db.DataSourcesSet.Where(ds => ds.IdSource == 2).Include(ds => ds.Activities)) foreach (var dataSource in db.DataSourcesSet.Where(ds => ds.IdSource == 2).Include(ds => ds.Activities).Include(ds => ds.Athletes))
{ {
Console.WriteLine($"\t{dataSource.IdSource} - {dataSource.Model}"); Console.WriteLine($"\t{dataSource.IdSource} - {dataSource.Model}");
Console.WriteLine("\tActivités :"); Console.WriteLine("\t\tActivités :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var activity in dataSource.Activities) foreach (var activity in dataSource.Activities)
{ {
Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); Console.WriteLine($"\t\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}");
} }
Console.WriteLine("\tAthletes :"); Console.WriteLine("\t\tAthletes :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var athlete in dataSource.Athletes) foreach (var athlete in dataSource.Athletes)
{ {
Console.WriteLine($"\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); Console.WriteLine($"\t\t\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
} }
} }
@ -126,48 +128,62 @@ class Program
Console.WriteLine("Athlètes :"); Console.WriteLine("Athlètes :");
Console.WriteLine("---------------------------------"); Console.WriteLine("---------------------------------");
// ! Pas oublier de faire tous les includes necessaire ! foreach (var athlete in db.AthletesSet.Include(a => a.Statistics).Include(a => a.Activities).Include(a => a.TrainingsAthlete).Include(a => a.NotificationsSent).Include(a => a.DataSource).Include(a => a.TrainingsCoach).Include(a => a.NotificationsReceived))
// ? Mais comment ?
foreach (var athlete in db.AthletesSet.Include(a => a.Statistics))
{ {
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine("\tStatistiques :"); Console.WriteLine("\t\tStatistiques :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var statistic in athlete.Statistics) foreach (var statistic in athlete.Statistics)
{ {
Console.WriteLine($"\t\t{statistic.IdStatistic} - {statistic.Date}, {statistic.AverageCaloriesBurned}, {statistic.AverageHeartRate}, {statistic.MaximumHeartRate}"); Console.WriteLine($"\t\t\t{statistic.IdStatistic} - {statistic.Date}, {statistic.AverageCaloriesBurned}, {statistic.AverageHeartRate}, {statistic.MaximumHeartRate}");
} }
Console.WriteLine("\tActivités :"); Console.WriteLine("\t\tActivités :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var activity in athlete.Activities) foreach (var activity in athlete.Activities)
{ {
Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); Console.WriteLine($"\t\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}");
}
Console.WriteLine("\t\tEntraînements :");
Console.WriteLine("\t\t---------------------------------");
foreach (var training in athlete.TrainingsAthlete)
{
Console.WriteLine($"\t\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}");
}
Console.WriteLine("\t\tEntrainements données :");
Console.WriteLine("\t\t---------------------------------");
foreach (var training in athlete.TrainingsCoach)
{
Console.WriteLine($"\t\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}");
} }
Console.WriteLine("\tEntraînements :"); Console.WriteLine("\t\tNotifications reçus :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var training in athlete.Trainings) foreach (var notification in athlete.NotificationsReceived)
{ {
Console.WriteLine($"\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}"); Console.WriteLine($"\t\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}");
} }
Console.WriteLine("\tNotifications :"); Console.WriteLine("\t\tNotifications données :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var notification in athlete.Notifications) foreach (var notification in athlete.NotificationsSent)
{ {
Console.WriteLine($"\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}"); Console.WriteLine($"\t\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}");
} }
Console.WriteLine("\tSources de données :"); Console.WriteLine("\t\tSources de données :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
Console.WriteLine("\t\t" + (athlete.DataSource?.Model ?? "Aucune source de données")); Console.WriteLine("\t\t\t" + (athlete.DataSource?.Model ?? "Aucune source de données"));
} }
Console.WriteLine("---------------------------------\n"); Console.WriteLine("---------------------------------\n");
@ -175,49 +191,117 @@ class Program
Console.WriteLine("Accès à l'athlète d'id '2' :"); Console.WriteLine("Accès à l'athlète d'id '2' :");
Console.WriteLine("---------------------------------"); Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Where(a => a.IdAthlete == 2).Include(a => a.Statistics)) foreach (var athlete in db.AthletesSet.Where(a => a.IdAthlete == 2).Include(a => a.Statistics).Include(a => a.Activities).Include(a => a.TrainingsAthlete).Include(a => a.NotificationsSent).Include(a => a.DataSource).Include(a => a.TrainingsCoach).Include(a => a.NotificationsReceived))
{ {
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}"); Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine("\tStatistiques :"); Console.WriteLine("\t\tStatistiques :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var statistic in athlete.Statistics) foreach (var statistic in athlete.Statistics)
{ {
Console.WriteLine($"\t\t{statistic.IdStatistic} - {statistic.Date}, {statistic.AverageCaloriesBurned}, {statistic.AverageHeartRate}, {statistic.MaximumHeartRate}"); Console.WriteLine($"\t\t\t{statistic.IdStatistic} - {statistic.Date}, {statistic.AverageCaloriesBurned}, {statistic.AverageHeartRate}, {statistic.MaximumHeartRate}");
} }
Console.WriteLine("\tActivités :"); Console.WriteLine("\t\tActivités :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var activity in athlete.Activities) foreach (var activity in athlete.Activities)
{ {
Console.WriteLine($"\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}"); Console.WriteLine($"\t\t\t{activity.IdActivity} - {activity.Type}, {activity.Date}, {activity.StartTime}, {activity.EndTime}, {activity.EffortFelt}, {activity.Variability}, {activity.Variance}, {activity.StandardDeviation}, {activity.Average}, {activity.Maximum}, {activity.Minimum}, {activity.AverageTemperature}, {activity.HasAutoPause}");
} }
Console.WriteLine("\tEntraînements :"); Console.WriteLine("\t\tEntraînements :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var training in athlete.Trainings) foreach (var training in athlete.TrainingsAthlete)
{ {
Console.WriteLine($"\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}"); Console.WriteLine($"\t\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}");
} }
Console.WriteLine("\tNotifications :"); Console.WriteLine("\t\tEntrainements données :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
foreach (var notification in athlete.Notifications) foreach (var training in athlete.TrainingsCoach)
{ {
Console.WriteLine($"\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}"); Console.WriteLine($"\t\t\t{training.IdTraining} - {training.Date}, {training.Latitude}, {training.Longitude}, {training.Description}, {training.FeedBack}");
} }
Console.WriteLine("\tSources de données :"); Console.WriteLine("\t\tNotifications reçus :");
Console.WriteLine("\t---------------------------------"); Console.WriteLine("\t\t---------------------------------");
Console.WriteLine("\t\t" + (athlete.DataSource?.Model ?? "Aucune source de données")); foreach (var notification in athlete.NotificationsReceived)
{
Console.WriteLine($"\t\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}");
}
Console.WriteLine("\t\tNotifications données :");
Console.WriteLine("\t\t---------------------------------");
foreach (var notification in athlete.NotificationsSent)
{
Console.WriteLine($"\t\t\t{notification.IdNotif} - {notification.Date}, {notification.Statut}, {notification.Message}");
}
Console.WriteLine("\t\tSources de données :");
Console.WriteLine("\t\t---------------------------------");
Console.WriteLine("\t\t\t" + (athlete.DataSource?.Model ?? "Aucune source de données"));
} }
Console.WriteLine("---------------------------------\n"); Console.WriteLine("---------------------------------\n");
} }
static void FriendshipTests(LibraryContext db)
{
Console.WriteLine("Accès à toutes les amitiés :");
Console.WriteLine("Amitiés :");
Console.WriteLine("---------------------------------");
foreach (var athlete in db.AthletesSet.Include(f => f.Followers).Include(f => f.Followings))
{
Console.WriteLine($"\t{athlete.IdAthlete} - {athlete.FirstName}, {athlete.LastName}, {athlete.DateOfBirth}, {athlete.Sexe}, {athlete.Weight}, {athlete.IsCoach}");
Console.WriteLine($"");
Console.WriteLine($"");
Console.WriteLine($"\t\t{athlete.Followers.Aggregate("", (seed, kvp) => $"{seed} [{kvp.FollowerId} ; {kvp.FollowingId} ; {kvp.StartDate.ToString("dd/MM/yyyy hh:mm:ss")}]")}");
// Console.WriteLine("\t\tFollowers :");
// Console.WriteLine("\t\t---------------------------------");
// foreach (var followers in athlete.Followers)
// {
// Console.WriteLine($"\t\t\t{followers.IdAthlete} - {followers.FirstName}, {followers.LastName}, {followers.DateOfBirth}, {followers.Sexe}, {followers.Weight}, {followers.IsCoach}");
// }
// Console.WriteLine("\t\tFollowings :");
// Console.WriteLine("\t\t---------------------------------");
// foreach (var following in athlete.Followings)
// {
// // Console.WriteLine($"\t\t{following.Followings.Aggregate("", (seed, kvp) => $"{seed} [{kvp.ArtistEntityId} ; {kvp.CreatedOn.ToString("dd/MM/yyyy hh:mm:ss")}]")}");
// Console.WriteLine($"\t\t\t{following.IdAthlete} - {following.FirstName}, {following.LastName}, {following.DateOfBirth}, {following.Sexe}, {following.Weight}, {following.IsCoach}");
// }
// using (MyDbContext db = new MyDbContext())
// {
// WriteLine("Content of database (albums) : ");
// foreach (var al in db.Albums.Include(a => a.Artists))
// {
// WriteLine($"\t{al}");
// WriteLine($"\t\t{al.AlbumArtists.Aggregate("", (seed, kvp) => $"{seed} [{kvp.ArtistEntityId} ; {kvp.CreatedOn.ToString("dd/MM/yyyy hh:mm:ss")}]")}");
// }
// WriteLine("Content of database (artists) : ");
// foreach (var ar in db.Artists)
// {
// WriteLine($"\t{ar}");
// WriteLine($"\t\t{ar.ArtistAlbums.Aggregate("", (seed, kvp) => $"{seed} [{kvp.AlbumEntityId} ; {kvp.CreatedOn.ToString("dd/MM/yyyy hh:mm:ss")}]")}");
// }
// }
}
}
} }
Loading…
Cancel
Save