diff --git a/Code/groupH_M32COM.Angular/Controllers/EventController.cs b/Code/groupH_M32COM.Angular/Controllers/EventController.cs index b32d482..394e1a8 100644 --- a/Code/groupH_M32COM.Angular/Controllers/EventController.cs +++ b/Code/groupH_M32COM.Angular/Controllers/EventController.cs @@ -14,14 +14,16 @@ namespace groupH_M32COM.Angular.Controllers [ApiController] public class EventController : ControllerBase { + private RCBoatDBContext _context; private RCBoatRepository repo; public EventController(RCBoatDBContext context) { + this._context = context; this.repo = new RCBoatRepository(context); } // GET: api/Event - [Authorize] + //[Authorize] [HttpGet] public IEnumerable Get() { diff --git a/Code/groupH_M32COM.Angular/DROPDBSTUFF.sql b/Code/groupH_M32COM.Angular/DROPDBSTUFF.sql new file mode 100644 index 0000000..7370939 --- /dev/null +++ b/Code/groupH_M32COM.Angular/DROPDBSTUFF.sql @@ -0,0 +1,14 @@ +-- Script Date: 23/03/2019 12:33 - ErikEJ.SqlCeScripting version 3.5.2.80 +DROP TABLE [__EFMigrationsHistory]; +DROP TABLE [Boats]; +DROP TABLE [CrewMembers]; +DROP TABLE [EventPrizes]; +DROP TABLE [Events]; +DROP TABLE [Promotions]; +DROP TABLE [Sponsorships]; +DROP TABLE [Locations]; + +DROP TABLE [EventDetailBoat]; +DROP TABLE [EventDetailPrizes]; +DROP TABLE [EventDetailPromotion]; + diff --git a/Code/groupH_M32COM.Angular/DTO/EventsDTO.cs b/Code/groupH_M32COM.Angular/DTO/EventsDTO.cs index f6866b3..f8258d1 100644 --- a/Code/groupH_M32COM.Angular/DTO/EventsDTO.cs +++ b/Code/groupH_M32COM.Angular/DTO/EventsDTO.cs @@ -17,11 +17,11 @@ namespace groupH_M32COM.Angular.DTO public int LocationID { get; set; } public BoatModel EventType { get; set; } public List Promotions { get; set; } - public List Notes { get; set; } + public List Notes { get; set; } public List RegisterdBoats { get; set; } public BoatDTO WinningBoat { get; set; } - public void Inflate(EventDetail eventDetails,RCBoatRepository repo) + public void Inflate(Event eventDetails,RCBoatRepository repo) { this.ID = eventDetails.ID; this.Description = eventDetails.Description; @@ -29,10 +29,10 @@ namespace groupH_M32COM.Angular.DTO this.EndDate = eventDetails.End_Date; this.Location = eventDetails.Location; this.EventType = eventDetails.EventType; - this.Promotions = eventDetails.Promotions.ToList(); - this.Notes = eventDetails.Prizes.ToList(); - this.RegisterdBoats = eventDetails.RegisterdBoats.Select(x => { var boat = new BoatDTO();boat.Inflate(x); return boat; }).ToList(); - this.WinningBoat = repo.GetBoatDTO(eventDetails.WinningBoatId); + //this.Promotions = eventDetails.Promotions.ToList(); + //this.Notes = eventDetails.Prizes.ToList(); + //this.RegisterdBoats = eventDetails.Boats.Select(x => { var boat = new BoatDTO();boat.Inflate(x); return boat; }).ToList(); + //this.WinningBoat = repo.GetBoatDTO(eventDetails.WinningBoatId); } } } diff --git a/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatDBContext.cs b/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatDBContext.cs index 11e3a56..3a2baec 100644 --- a/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatDBContext.cs +++ b/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatDBContext.cs @@ -16,121 +16,74 @@ namespace groupH_M32COM.Angular.DatabaseClasses public DbSet Boats { get; set; } public DbSet CrewMembers { get; set; } - public DbSet Events { get; set; } - public DbSet EventPrizes { get; set; } + public DbSet Events { get; set; } + public DbSet EventPrizes { get; set; } public DbSet Locations { get; set; } public DbSet Promotions { get; set; } public DbSet SponsorShips { get; set; } + public DbSet EventDetailPromotion { get; set; } + public DbSet EventDetailBoat { get; set; } + public DbSet EventDetailPrizes { get; set; } protected override void OnModelCreating(ModelBuilder modelBuilder) { - var promotion = new Promotion() + modelBuilder.Entity(x => { - ID = 1, - Description = "Description", - PromotionalManagerName = "Timmy", - ContactNumber = "54654654", - }; + x.HasKey(bc => new { bc.EventId, bc.PromotionId }); - var location = new Location() - { - ID = 1, - City="Coventry", - Country ="England", - PostCode = "cv19ll" - }; + x.HasOne(bc => bc.Event) + .WithMany(b => b.Promotions) + .HasForeignKey(bc => bc.EventId); - var sponsorship = new SponsorShip() - { - ID = 1, - CompanyName= "Description", - SponsorAmount = 1000, - }; + x.HasOne(bc => bc.Promotion) + .WithMany(c => c.Events) + .HasForeignKey(bc => bc.PromotionId); - var eventPrizes = new EventPrizes() - { - ID = 1, - Note = "Event Note", - PrizeMoney = 1000, - WinningPosition = WinningPositions.First - }; + x.HasData(new EventDetailPromotion() + { + PromotionId = 1, + EventId = 1 + }); + }); - var crewmember1 = new CrewMember() + modelBuilder.Entity(x => { - ID = 1, - FirstName = "Adam", - LastName = "Davis", - Boat = null, - BoatID = 1, - Email = "AdamDavis@G.Com", - DOB = DateTime.Now, - Password = "dadas", - Phone = "14521256", - Role = CrewRole.Captin, - Username = "Captin Davis" - }; - - var crewmember2 = new CrewMember() - { - ID = 2, - FirstName = "Jo", - LastName = "Bob", - Boat = null, - BoatID = 1, - Email = "JoBob@G.Com", - DOB = DateTime.Now, - Password = "dadas", - Phone = "14521256", - Role = CrewRole.BoatEngineer, - Username = "Enginer Jo" - }; - - var crewmember3 = new CrewMember() - { - ID = 3, - FirstName = "Phill", - LastName = "Crack", - Boat = null, - BoatID = 1, - Email = "PhillCrack@G.Com", - DOB = DateTime.Now, - Password = "dadas", - Phone = "14521256", - Role = CrewRole.BoatRecovery, - Username = "Recover Phill" - }; - - var eventDetail = new EventDetail() - { - ID = 1, - Description = "SpeedBoats", - End_Date = DateTime.Now, - StartDate = DateTime.Now, - LocationID = 1, - WinningBoatId =1 - }; - - var boat = new Boat() - { - ID = 1, - Description = "Blue and shiny and very fast ayyyyeeee", - Model = BoatModel.WindPower, - }; + x.HasKey(bc => new { bc.EventId, bc.BoatId }); - modelBuilder.Entity(entity => + x.HasOne(bc => bc.Event) + .WithMany(b => b.Boats) + .HasForeignKey(bc => bc.EventId); + + x.HasOne(bc => bc.Boat) + .WithMany(c => c.Events) + .HasForeignKey(bc => bc.BoatId); + + x.HasData(new EventDetailBoat() { - entity.HasKey(e => e.ID); + BoatId = 1, + EventId = 1 + }); + + }); + + modelBuilder.Entity(x => + { + x.HasKey(bc => new { bc.EventId, bc.PrizeId }); - entity.Property(e => e.Model) - .IsRequired(); + x.HasOne(bc => bc.Event) + .WithMany(b => b.Prizes) + .HasForeignKey(bc => bc.EventId); - entity.Property(e => e.Description) - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); + x.HasOne(bc => bc.Prize) + .WithMany(c => c.Events) + .HasForeignKey(bc => bc.PrizeId); - entity.HasData(boat); + x.HasData(new EventDetailPrizes() + { + PrizeId = 1, + EventId = 1 }); + }); modelBuilder.Entity(entity => { @@ -166,13 +119,52 @@ namespace groupH_M32COM.Angular.DatabaseClasses ; entity.HasData( - crewmember1, - crewmember2, - crewmember3 + new CrewMember() + { + ID = 1, + FirstName = "Adam", + LastName = "Davis", + Boat = null, + BoatID = 1, + Email = "AdamDavis@G.Com", + DOB = DateTime.Now, + Password = "dadas", + Phone = "14521256", + Role = CrewRole.Captin, + Username = "Captin Davis" + }, + new CrewMember() + { + ID = 2, + FirstName = "Jo", + LastName = "Bob", + Boat = null, + BoatID = 1, + Email = "JoBob@G.Com", + DOB = DateTime.Now, + Password = "dadas", + Phone = "14521256", + Role = CrewRole.BoatEngineer, + Username = "Enginer Jo" + }, + new CrewMember() + { + ID = 3, + FirstName = "Phill", + LastName = "Crack", + Boat = null, + BoatID = 1, + Email = "PhillCrack@G.Com", + DOB = DateTime.Now, + Password = "dadas", + Phone = "14521256", + Role = CrewRole.BoatRecovery, + Username = "Recover Phill" + } ); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { entity.HasKey(e => e.ID); @@ -189,7 +181,15 @@ namespace groupH_M32COM.Angular.DatabaseClasses .IsRequired() ; - entity.HasData(eventDetail); + entity.HasData(new Event() + { + ID = 1, + Description = "SpeedBoats", + End_Date = DateTime.Now, + StartDate = DateTime.Now, + LocationID = 1, + WinningBoatId = 1 + }); }); modelBuilder.Entity(entity => @@ -209,26 +209,39 @@ namespace groupH_M32COM.Angular.DatabaseClasses .IsRequired() ; - - entity.HasData(promotion); + + entity.HasData(new Promotion() + { + ID = 1, + Description = "Description", + PromotionalManagerName = "Timmy", + ContactNumber = "54654654", + }); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { entity.HasKey(e => e.ID); entity.Property(e => e.ID) - .IsRequired() + .IsRequired() ; entity.Property(e => e.Note) .IsRequired() .HasMaxLength(100) ; + entity.Property(e => e.PrizeMoney) .IsRequired() ; - entity.HasData(eventPrizes); + entity.HasData(new EventPrize() + { + ID = 1, + Note = "Event Note", + PrizeMoney = 1000, + WinningPosition = WinningPositions.First, + }); }); modelBuilder.Entity(entity => @@ -246,7 +259,12 @@ namespace groupH_M32COM.Angular.DatabaseClasses .IsRequired() ; - entity.HasData(sponsorship); + entity.HasData(new SponsorShip() + { + ID = 1, + CompanyName = "Description", + SponsorAmount = 1000, + }); }); modelBuilder.Entity(entity => @@ -268,9 +286,34 @@ namespace groupH_M32COM.Angular.DatabaseClasses .IsRequired() .HasMaxLength(100) ; - entity.HasData(location); + entity.HasData(new Location() + { + ID = 1, + City = "Coventry", + Country = "England", + PostCode = "cv19ll" + }); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ID); + + entity.Property(e => e.Model) + .IsRequired(); + + entity.Property(e => e.Description) + .IsRequired() + .HasMaxLength(100) + .IsUnicode(false); + + entity.HasData(new Boat() + { + ID = 1, + Description = "Blue and shiny and very fast ayyyyeeee", + Model = BoatModel.WindPower, + }); + }); } } } diff --git a/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatRepository.cs b/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatRepository.cs index c9d5201..318c9b4 100644 --- a/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatRepository.cs +++ b/Code/groupH_M32COM.Angular/DatabaseClasses/RCBoatRepository.cs @@ -27,7 +27,7 @@ namespace groupH_M32COM.Angular.DatabaseClasses public EventsDTO GetEventDTO(int id) { - EventDetail eventDetail = this._context.Events.FirstOrDefault(x => x.ID == id); + Event eventDetail = this._context.Events.FirstOrDefault(x => x.ID == id); var DTO = new EventsDTO(); DTO.Inflate(eventDetail, this); return DTO; diff --git a/Code/groupH_M32COM.Angular/Migrations/20190322234135_UpdateBuilder.Designer.cs b/Code/groupH_M32COM.Angular/Migrations/20190322234135_UpdateBuilder.Designer.cs deleted file mode 100644 index 3747a69..0000000 --- a/Code/groupH_M32COM.Angular/Migrations/20190322234135_UpdateBuilder.Designer.cs +++ /dev/null @@ -1,279 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using groupH_M32COM.Angular.DatabaseClasses; - -namespace groupH_M32COM.Angular.Migrations -{ - [DbContext(typeof(RCBoatDBContext))] - [Migration("20190322234135_UpdateBuilder")] - partial class UpdateBuilder - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.1.8-servicing-32085"); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Boat", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("Description") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("Event_DetailID"); - - b.Property("Model"); - - b.HasKey("ID"); - - b.HasIndex("Event_DetailID"); - - b.ToTable("Boats"); - - b.HasData( - new { ID = 1, Description = "Blue and shiny and very fast ayyyyeeee", Model = 1 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Crew_Member", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("BoatID"); - - b.Property("DOB"); - - b.Property("Email") - .IsRequired(); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("Password") - .IsRequired() - .HasMaxLength(10) - .IsUnicode(false); - - b.Property("Phone"); - - b.Property("Role"); - - b.Property("Username") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false); - - b.HasKey("ID"); - - b.HasIndex("BoatID"); - - b.ToTable("CrewMembers"); - - b.HasData( - new { ID = 1, BoatID = 1, DOB = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), Email = "AdamDavis@G.Com", FirstName = "Adam", LastName = "Davis", Password = "dadas", Phone = "14521256", Role = 0, Username = "Captin Davis" }, - new { ID = 2, BoatID = 1, DOB = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), Email = "JoBob@G.Com", FirstName = "Jo", LastName = "Bob", Password = "dadas", Phone = "14521256", Role = 1, Username = "Enginer Jo" }, - new { ID = 3, BoatID = 1, DOB = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), Email = "PhillCrack@G.Com", FirstName = "Phill", LastName = "Crack", Password = "dadas", Phone = "14521256", Role = 3, Username = "Recover Phill" } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Event_Detail", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("Description") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("End_Date"); - - b.Property("EventType"); - - b.Property("LocationID"); - - b.Property("StartDate"); - - b.Property("WinningBoatId"); - - b.HasKey("ID"); - - b.HasIndex("LocationID"); - - b.ToTable("Events"); - - b.HasData( - new { ID = 1, Description = "SpeedBoats", End_Date = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), EventType = 0, LocationID = 1, StartDate = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), WinningBoatId = 1 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.EventPrizes", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("Event_DetailID"); - - b.Property("Note") - .IsRequired() - .HasMaxLength(100); - - b.Property("PrizeMoney"); - - b.Property("WinningPosition"); - - b.HasKey("ID"); - - b.HasIndex("Event_DetailID"); - - b.ToTable("EventPrizes"); - - b.HasData( - new { ID = 1, Note = "Event Note", PrizeMoney = 1000, WinningPosition = 0 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Location", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("City") - .IsRequired() - .HasMaxLength(100); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100); - - b.Property("PostCode") - .IsRequired() - .HasMaxLength(100); - - b.HasKey("ID"); - - b.ToTable("Locations"); - - b.HasData( - new { ID = 1, City = "Coventry", Country = "England", PostCode = "cv19ll" } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Promotion", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("ContactNumber") - .IsRequired(); - - b.Property("Description") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("Event_DetailID"); - - b.Property("ImagePath"); - - b.Property("PromotionalManagerName") - .IsRequired(); - - b.HasKey("ID"); - - b.HasIndex("Event_DetailID"); - - b.ToTable("Promotions"); - - b.HasData( - new { ID = 1, ContactNumber = "54654654", Description = "Description", PromotionalManagerName = "Timmy" } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.SponsorShip", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("CompanyName") - .IsRequired() - .HasMaxLength(100); - - b.Property("PromotionID"); - - b.Property("SponsorAmount"); - - b.HasKey("ID"); - - b.HasIndex("PromotionID"); - - b.ToTable("SponsorShips"); - - b.HasData( - new { ID = 1, CompanyName = "Description", SponsorAmount = 1000 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Boat", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Event_Detail") - .WithMany("RegisterdBoats") - .HasForeignKey("Event_DetailID"); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Crew_Member", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Boat", "Boat") - .WithMany("CrewMembers") - .HasForeignKey("BoatID") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Event_Detail", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Location", "Location") - .WithMany() - .HasForeignKey("LocationID") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.EventPrizes", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Event_Detail") - .WithMany("Prizes") - .HasForeignKey("Event_DetailID"); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Promotion", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Event_Detail") - .WithMany("Promotions") - .HasForeignKey("Event_DetailID"); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.SponsorShip", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Promotion") - .WithMany("Sponsorships") - .HasForeignKey("PromotionID"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Code/groupH_M32COM.Angular/Migrations/20190322234135_UpdateBuilder.cs b/Code/groupH_M32COM.Angular/Migrations/20190322234135_UpdateBuilder.cs deleted file mode 100644 index 35a2e11..0000000 --- a/Code/groupH_M32COM.Angular/Migrations/20190322234135_UpdateBuilder.cs +++ /dev/null @@ -1,263 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace groupH_M32COM.Angular.Migrations -{ - public partial class UpdateBuilder : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateTable( - name: "Locations", - columns: table => new - { - ID = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - City = table.Column(maxLength: 100, nullable: false), - Country = table.Column(maxLength: 100, nullable: false), - PostCode = table.Column(maxLength: 100, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Locations", x => x.ID); - }); - - migrationBuilder.CreateTable( - name: "Events", - columns: table => new - { - ID = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Description = table.Column(unicode: false, maxLength: 100, nullable: false), - StartDate = table.Column(nullable: false), - End_Date = table.Column(nullable: false), - LocationID = table.Column(nullable: false), - EventType = table.Column(nullable: false), - WinningBoatId = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Events", x => x.ID); - table.ForeignKey( - name: "FK_Events_Locations_LocationID", - column: x => x.LocationID, - principalTable: "Locations", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Boats", - columns: table => new - { - ID = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Description = table.Column(unicode: false, maxLength: 100, nullable: false), - Model = table.Column(nullable: false), - Event_DetailID = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Boats", x => x.ID); - table.ForeignKey( - name: "FK_Boats_Events_Event_DetailID", - column: x => x.Event_DetailID, - principalTable: "Events", - principalColumn: "ID", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "EventPrizes", - columns: table => new - { - ID = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Note = table.Column(maxLength: 100, nullable: false), - PrizeMoney = table.Column(nullable: false), - WinningPosition = table.Column(nullable: false), - Event_DetailID = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_EventPrizes", x => x.ID); - table.ForeignKey( - name: "FK_EventPrizes_Events_Event_DetailID", - column: x => x.Event_DetailID, - principalTable: "Events", - principalColumn: "ID", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "Promotions", - columns: table => new - { - ID = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Description = table.Column(unicode: false, maxLength: 100, nullable: false), - PromotionalManagerName = table.Column(nullable: false), - ContactNumber = table.Column(nullable: false), - ImagePath = table.Column(nullable: true), - Event_DetailID = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_Promotions", x => x.ID); - table.ForeignKey( - name: "FK_Promotions_Events_Event_DetailID", - column: x => x.Event_DetailID, - principalTable: "Events", - principalColumn: "ID", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.CreateTable( - name: "CrewMembers", - columns: table => new - { - ID = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - DOB = table.Column(nullable: false), - FirstName = table.Column(unicode: false, maxLength: 100, nullable: false), - LastName = table.Column(unicode: false, maxLength: 100, nullable: false), - Email = table.Column(nullable: false), - Phone = table.Column(nullable: true), - Username = table.Column(unicode: false, maxLength: 20, nullable: false), - Password = table.Column(unicode: false, maxLength: 10, nullable: false), - Role = table.Column(nullable: false), - BoatID = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_CrewMembers", x => x.ID); - table.ForeignKey( - name: "FK_CrewMembers_Boats_BoatID", - column: x => x.BoatID, - principalTable: "Boats", - principalColumn: "ID", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "SponsorShips", - columns: table => new - { - ID = table.Column(nullable: false) - .Annotation("Sqlite:Autoincrement", true), - CompanyName = table.Column(maxLength: 100, nullable: false), - SponsorAmount = table.Column(nullable: false), - PromotionID = table.Column(nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_SponsorShips", x => x.ID); - table.ForeignKey( - name: "FK_SponsorShips_Promotions_PromotionID", - column: x => x.PromotionID, - principalTable: "Promotions", - principalColumn: "ID", - onDelete: ReferentialAction.Restrict); - }); - - migrationBuilder.InsertData( - table: "Boats", - columns: new[] { "ID", "Description", "Event_DetailID", "Model" }, - values: new object[] { 1, "Blue and shiny and very fast ayyyyeeee", null, 1 }); - - migrationBuilder.InsertData( - table: "EventPrizes", - columns: new[] { "ID", "Event_DetailID", "Note", "PrizeMoney", "WinningPosition" }, - values: new object[] { 1, null, "Event Note", 1000, 0 }); - - migrationBuilder.InsertData( - table: "Locations", - columns: new[] { "ID", "City", "Country", "PostCode" }, - values: new object[] { 1, "Coventry", "England", "cv19ll" }); - - migrationBuilder.InsertData( - table: "Promotions", - columns: new[] { "ID", "ContactNumber", "Description", "Event_DetailID", "ImagePath", "PromotionalManagerName" }, - values: new object[] { 1, "54654654", "Description", null, null, "Timmy" }); - - migrationBuilder.InsertData( - table: "SponsorShips", - columns: new[] { "ID", "CompanyName", "PromotionID", "SponsorAmount" }, - values: new object[] { 1, "Description", null, 1000 }); - - migrationBuilder.InsertData( - table: "CrewMembers", - columns: new[] { "ID", "BoatID", "DOB", "Email", "FirstName", "LastName", "Password", "Phone", "Role", "Username" }, - values: new object[] { 1, 1, new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), "AdamDavis@G.Com", "Adam", "Davis", "dadas", "14521256", 0, "Captin Davis" }); - - migrationBuilder.InsertData( - table: "CrewMembers", - columns: new[] { "ID", "BoatID", "DOB", "Email", "FirstName", "LastName", "Password", "Phone", "Role", "Username" }, - values: new object[] { 2, 1, new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), "JoBob@G.Com", "Jo", "Bob", "dadas", "14521256", 1, "Enginer Jo" }); - - migrationBuilder.InsertData( - table: "CrewMembers", - columns: new[] { "ID", "BoatID", "DOB", "Email", "FirstName", "LastName", "Password", "Phone", "Role", "Username" }, - values: new object[] { 3, 1, new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), "PhillCrack@G.Com", "Phill", "Crack", "dadas", "14521256", 3, "Recover Phill" }); - - migrationBuilder.InsertData( - table: "Events", - columns: new[] { "ID", "Description", "End_Date", "EventType", "LocationID", "StartDate", "WinningBoatId" }, - values: new object[] { 1, "SpeedBoats", new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), 0, 1, new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), 1 }); - - migrationBuilder.CreateIndex( - name: "IX_Boats_Event_DetailID", - table: "Boats", - column: "Event_DetailID"); - - migrationBuilder.CreateIndex( - name: "IX_CrewMembers_BoatID", - table: "CrewMembers", - column: "BoatID"); - - migrationBuilder.CreateIndex( - name: "IX_EventPrizes_Event_DetailID", - table: "EventPrizes", - column: "Event_DetailID"); - - migrationBuilder.CreateIndex( - name: "IX_Events_LocationID", - table: "Events", - column: "LocationID"); - - migrationBuilder.CreateIndex( - name: "IX_Promotions_Event_DetailID", - table: "Promotions", - column: "Event_DetailID"); - - migrationBuilder.CreateIndex( - name: "IX_SponsorShips_PromotionID", - table: "SponsorShips", - column: "PromotionID"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "CrewMembers"); - - migrationBuilder.DropTable( - name: "EventPrizes"); - - migrationBuilder.DropTable( - name: "SponsorShips"); - - migrationBuilder.DropTable( - name: "Boats"); - - migrationBuilder.DropTable( - name: "Promotions"); - - migrationBuilder.DropTable( - name: "Events"); - - migrationBuilder.DropTable( - name: "Locations"); - } - } -} diff --git a/Code/groupH_M32COM.Angular/Migrations/RCBoatDBContextModelSnapshot.cs b/Code/groupH_M32COM.Angular/Migrations/RCBoatDBContextModelSnapshot.cs deleted file mode 100644 index d77c0f9..0000000 --- a/Code/groupH_M32COM.Angular/Migrations/RCBoatDBContextModelSnapshot.cs +++ /dev/null @@ -1,277 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using groupH_M32COM.Angular.DatabaseClasses; - -namespace groupH_M32COM.Angular.Migrations -{ - [DbContext(typeof(RCBoatDBContext))] - partial class RCBoatDBContextModelSnapshot : ModelSnapshot - { - protected override void BuildModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.1.8-servicing-32085"); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Boat", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("Description") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("Event_DetailID"); - - b.Property("Model"); - - b.HasKey("ID"); - - b.HasIndex("Event_DetailID"); - - b.ToTable("Boats"); - - b.HasData( - new { ID = 1, Description = "Blue and shiny and very fast ayyyyeeee", Model = 1 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Crew_Member", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("BoatID"); - - b.Property("DOB"); - - b.Property("Email") - .IsRequired(); - - b.Property("FirstName") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("LastName") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("Password") - .IsRequired() - .HasMaxLength(10) - .IsUnicode(false); - - b.Property("Phone"); - - b.Property("Role"); - - b.Property("Username") - .IsRequired() - .HasMaxLength(20) - .IsUnicode(false); - - b.HasKey("ID"); - - b.HasIndex("BoatID"); - - b.ToTable("CrewMembers"); - - b.HasData( - new { ID = 1, BoatID = 1, DOB = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), Email = "AdamDavis@G.Com", FirstName = "Adam", LastName = "Davis", Password = "dadas", Phone = "14521256", Role = 0, Username = "Captin Davis" }, - new { ID = 2, BoatID = 1, DOB = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), Email = "JoBob@G.Com", FirstName = "Jo", LastName = "Bob", Password = "dadas", Phone = "14521256", Role = 1, Username = "Enginer Jo" }, - new { ID = 3, BoatID = 1, DOB = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), Email = "PhillCrack@G.Com", FirstName = "Phill", LastName = "Crack", Password = "dadas", Phone = "14521256", Role = 3, Username = "Recover Phill" } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Event_Detail", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("Description") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("End_Date"); - - b.Property("EventType"); - - b.Property("LocationID"); - - b.Property("StartDate"); - - b.Property("WinningBoatId"); - - b.HasKey("ID"); - - b.HasIndex("LocationID"); - - b.ToTable("Events"); - - b.HasData( - new { ID = 1, Description = "SpeedBoats", End_Date = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), EventType = 0, LocationID = 1, StartDate = new DateTime(2019, 3, 22, 23, 41, 34, 824, DateTimeKind.Local), WinningBoatId = 1 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.EventPrizes", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("Event_DetailID"); - - b.Property("Note") - .IsRequired() - .HasMaxLength(100); - - b.Property("PrizeMoney"); - - b.Property("WinningPosition"); - - b.HasKey("ID"); - - b.HasIndex("Event_DetailID"); - - b.ToTable("EventPrizes"); - - b.HasData( - new { ID = 1, Note = "Event Note", PrizeMoney = 1000, WinningPosition = 0 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Location", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("City") - .IsRequired() - .HasMaxLength(100); - - b.Property("Country") - .IsRequired() - .HasMaxLength(100); - - b.Property("PostCode") - .IsRequired() - .HasMaxLength(100); - - b.HasKey("ID"); - - b.ToTable("Locations"); - - b.HasData( - new { ID = 1, City = "Coventry", Country = "England", PostCode = "cv19ll" } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Promotion", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("ContactNumber") - .IsRequired(); - - b.Property("Description") - .IsRequired() - .HasMaxLength(100) - .IsUnicode(false); - - b.Property("Event_DetailID"); - - b.Property("ImagePath"); - - b.Property("PromotionalManagerName") - .IsRequired(); - - b.HasKey("ID"); - - b.HasIndex("Event_DetailID"); - - b.ToTable("Promotions"); - - b.HasData( - new { ID = 1, ContactNumber = "54654654", Description = "Description", PromotionalManagerName = "Timmy" } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.SponsorShip", b => - { - b.Property("ID") - .ValueGeneratedOnAdd(); - - b.Property("CompanyName") - .IsRequired() - .HasMaxLength(100); - - b.Property("PromotionID"); - - b.Property("SponsorAmount"); - - b.HasKey("ID"); - - b.HasIndex("PromotionID"); - - b.ToTable("SponsorShips"); - - b.HasData( - new { ID = 1, CompanyName = "Description", SponsorAmount = 1000 } - ); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Boat", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Event_Detail") - .WithMany("RegisterdBoats") - .HasForeignKey("Event_DetailID"); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Crew_Member", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Boat", "Boat") - .WithMany("CrewMembers") - .HasForeignKey("BoatID") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Event_Detail", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Location", "Location") - .WithMany() - .HasForeignKey("LocationID") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.EventPrizes", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Event_Detail") - .WithMany("Prizes") - .HasForeignKey("Event_DetailID"); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.Promotion", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Event_Detail") - .WithMany("Promotions") - .HasForeignKey("Event_DetailID"); - }); - - modelBuilder.Entity("groupH_M32COM.Angular.Models.SponsorShip", b => - { - b.HasOne("groupH_M32COM.Angular.Models.Promotion") - .WithMany("Sponsorships") - .HasForeignKey("PromotionID"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/Code/groupH_M32COM.Angular/Models/Boat.cs b/Code/groupH_M32COM.Angular/Models/Boat.cs index 77dea76..f6d0b1e 100644 --- a/Code/groupH_M32COM.Angular/Models/Boat.cs +++ b/Code/groupH_M32COM.Angular/Models/Boat.cs @@ -17,12 +17,15 @@ namespace groupH_M32COM.Angular.Models { public Boat() { - CrewMembers = new Collection(); + CrewMembers = new HashSet(); + Events = new HashSet(); + } public int ID { get; set; } public string Description { get; set; } - public BoatModel Model { get; set; } - public ICollection CrewMembers { get; set; } + public BoatModel Model { get; set; } public string ImagePath { get; set; } + public virtual ICollection CrewMembers { get; set; } + public virtual ICollection Events { get; set; } } } diff --git a/Code/groupH_M32COM.Angular/Models/EventDetail.cs b/Code/groupH_M32COM.Angular/Models/Event.cs similarity index 51% rename from Code/groupH_M32COM.Angular/Models/EventDetail.cs rename to Code/groupH_M32COM.Angular/Models/Event.cs index 433590d..418d1f4 100644 --- a/Code/groupH_M32COM.Angular/Models/EventDetail.cs +++ b/Code/groupH_M32COM.Angular/Models/Event.cs @@ -4,8 +4,14 @@ using System.Collections.ObjectModel; namespace groupH_M32COM.Angular.Models { - public class EventDetail + public class Event { + public Event() + { + this.Prizes = new HashSet(); + this.Promotions = new HashSet(); + this.Boats = new HashSet(); + } public int ID { get; set; } public string Description { get; set; } public DateTime StartDate { get; set; } @@ -15,17 +21,8 @@ namespace groupH_M32COM.Angular.Models public BoatModel EventType { get; set; } public Boat WinningBoat { get; set; } public int WinningBoatId { get; set; } - public ICollection Prizes { get; set; } - public ICollection Promotions { get; set; } - public ICollection RegisterdBoats { get; set; } - public ICollection Sponsors { get; set; } - - public EventDetail() - { - this.Prizes = new Collection(); - this.Promotions = new Collection(); - this.RegisterdBoats = new Collection(); - this.Sponsors = new Collection(); - } + public virtual ICollection Prizes { get; set; } + public virtual ICollection Promotions { get; set; } + public virtual ICollection Boats { get; set; } } } diff --git a/Code/groupH_M32COM.Angular/Models/EventDetailBoat.cs b/Code/groupH_M32COM.Angular/Models/EventDetailBoat.cs new file mode 100644 index 0000000..133a628 --- /dev/null +++ b/Code/groupH_M32COM.Angular/Models/EventDetailBoat.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace groupH_M32COM.Angular.Models +{ + public class EventDetailBoat + { + public Event Event { get; set; } + public int EventId{ get; set; } + public Boat Boat { get; set; } + public int BoatId { get; set; } + } +} diff --git a/Code/groupH_M32COM.Angular/Models/EventDetailPrizes.cs b/Code/groupH_M32COM.Angular/Models/EventDetailPrizes.cs new file mode 100644 index 0000000..e460bce --- /dev/null +++ b/Code/groupH_M32COM.Angular/Models/EventDetailPrizes.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace groupH_M32COM.Angular.Models +{ + + public class EventDetailPrizes + { + public Event Event { get; set; } + public int EventId { get; set; } + public EventPrize Prize { get; set; } + public int PrizeId { get; set; } + } +} diff --git a/Code/groupH_M32COM.Angular/Models/EventDetailPromotion.cs b/Code/groupH_M32COM.Angular/Models/EventDetailPromotion.cs new file mode 100644 index 0000000..cc9b3af --- /dev/null +++ b/Code/groupH_M32COM.Angular/Models/EventDetailPromotion.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; + +namespace groupH_M32COM.Angular.Models +{ + public class EventDetailPromotion + { + public Event Event { get; set; } + public int EventId { get; set; } + public Promotion Promotion { get; set; } + public int PromotionId { get; set; } + } +} diff --git a/Code/groupH_M32COM.Angular/Models/EventPrizes.cs b/Code/groupH_M32COM.Angular/Models/EventPrizes.cs index fb7dfc5..3aa65d2 100644 --- a/Code/groupH_M32COM.Angular/Models/EventPrizes.cs +++ b/Code/groupH_M32COM.Angular/Models/EventPrizes.cs @@ -11,11 +11,17 @@ namespace groupH_M32COM.Angular.Models Second, Third } - public class EventPrizes + public class EventPrize { + public EventPrize() + { + this.Events = new HashSet(); + } public int ID { get; set; } public string Note { get; set; } public int PrizeMoney { get; set; } public WinningPositions WinningPosition { get; set; } + public virtual ICollection Events { get; set; } + } } diff --git a/Code/groupH_M32COM.Angular/Models/Promotion.cs b/Code/groupH_M32COM.Angular/Models/Promotion.cs index fd4c3e1..950f7b1 100644 --- a/Code/groupH_M32COM.Angular/Models/Promotion.cs +++ b/Code/groupH_M32COM.Angular/Models/Promotion.cs @@ -14,11 +14,17 @@ namespace groupH_M32COM.Angular.Models public class Promotion { + public Promotion() + { + this.Events = new HashSet(); + } public int ID { get; set; } public string Description { get; set; } public string PromotionalManagerName { get; set; } public string ContactNumber { get; set; } - public ICollection Sponsorships { get; set; } public string ImagePath { get; set; } + public SponsorShip Sponsor { get; set; } + public virtual ICollection Events { get; set; } + } } diff --git a/Code/groupH_M32COM.Angular/Startup.cs b/Code/groupH_M32COM.Angular/Startup.cs index e973ab0..52323f6 100644 --- a/Code/groupH_M32COM.Angular/Startup.cs +++ b/Code/groupH_M32COM.Angular/Startup.cs @@ -43,7 +43,7 @@ namespace groupH_M32COM.Angular options.UseSqlServer(Configuration.GetConnectionString("MyDbConnection"))); else services.AddDbContext(options => - options.UseSqlite("Data Source=localdatabase.db")); + options.UseSqlite("Data Source=localdatabase.db").EnableSensitiveDataLogging()); // Automatically perform database migration services.BuildServiceProvider().GetService().Database.Migrate(); diff --git a/Code/groupH_M32COM.Angular/localdatabase.db b/Code/groupH_M32COM.Angular/localdatabase.db index a652460..185eae8 100644 Binary files a/Code/groupH_M32COM.Angular/localdatabase.db and b/Code/groupH_M32COM.Angular/localdatabase.db differ diff --git a/DROPDBSTUFF.sql b/DROPDBSTUFF.sql new file mode 100644 index 0000000..c99ae50 --- /dev/null +++ b/DROPDBSTUFF.sql @@ -0,0 +1,9 @@ +-- Script Date: 23/03/2019 12:33 - ErikEJ.SqlCeScripting version 3.5.2.80 +DROP TABLE [__EFMigrationsHistory]; +DROP TABLE [Boats]; +DROP TABLE [CrewMembers]; +DROP TABLE [EventPrizes]; +DROP TABLE [Events]; +DROP TABLE [Promotions]; +DROP TABLE [Sponsorships]; +DROP TABLE [Locations];