фикс связей

This commit is contained in:
russell 2024-04-29 21:56:45 +04:00
parent b4395026c7
commit cc9d05ccf5
6 changed files with 69 additions and 13 deletions

View File

@ -12,7 +12,7 @@ using TravelAgencyDatabaseImplement;
namespace TravelAgencyDatabaseImplement.Migrations namespace TravelAgencyDatabaseImplement.Migrations
{ {
[DbContext(typeof(TravelAgencyDatabase))] [DbContext(typeof(TravelAgencyDatabase))]
[Migration("20240429172546_InitialCreate")] [Migration("20240429175309_InitialCreate")]
partial class InitialCreate partial class InitialCreate
{ {
/// <inheritdoc /> /// <inheritdoc />
@ -293,7 +293,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User") b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany() .WithMany("Excursions")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
@ -304,13 +304,13 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroup", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroup", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide") b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide")
.WithMany() .WithMany("ExcursionGroups")
.HasForeignKey("GuideId") .HasForeignKey("GuideId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User") b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany() .WithMany("ExcursionGroups")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
@ -361,7 +361,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.Excursion", "Excursion") b.HasOne("TravelAgencyDatabaseImplement.Models.Excursion", "Excursion")
.WithMany() .WithMany("Places")
.HasForeignKey("ExcursionId") .HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -372,7 +372,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Tour", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Tour", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User") b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany() .WithMany("Tours")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
@ -383,7 +383,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Trip", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Trip", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide") b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide")
.WithMany() .WithMany("Trips")
.HasForeignKey("GuideId") .HasForeignKey("GuideId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -412,6 +412,8 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{ {
b.Navigation("Places");
b.Navigation("Tours"); b.Navigation("Tours");
}); });
@ -420,6 +422,13 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.Navigation("Tours"); b.Navigation("Tours");
}); });
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Guide", b =>
{
b.Navigation("ExcursionGroups");
b.Navigation("Trips");
});
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{ {
b.Navigation("Trips"); b.Navigation("Trips");
@ -436,6 +445,15 @@ namespace TravelAgencyDatabaseImplement.Migrations
{ {
b.Navigation("Places"); b.Navigation("Places");
}); });
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.User", b =>
{
b.Navigation("ExcursionGroups");
b.Navigation("Excursions");
b.Navigation("Tours");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

View File

@ -290,7 +290,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User") b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany() .WithMany("Excursions")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
@ -301,13 +301,13 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroup", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroup", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide") b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide")
.WithMany() .WithMany("ExcursionGroups")
.HasForeignKey("GuideId") .HasForeignKey("GuideId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User") b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany() .WithMany("ExcursionGroups")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
@ -358,7 +358,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.Excursion", "Excursion") b.HasOne("TravelAgencyDatabaseImplement.Models.Excursion", "Excursion")
.WithMany() .WithMany("Places")
.HasForeignKey("ExcursionId") .HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -369,7 +369,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Tour", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Tour", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User") b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany() .WithMany("Tours")
.HasForeignKey("UserId") .HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict) .OnDelete(DeleteBehavior.Restrict)
.IsRequired(); .IsRequired();
@ -380,7 +380,7 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Trip", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Trip", b =>
{ {
b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide") b.HasOne("TravelAgencyDatabaseImplement.Models.Guide", "Guide")
.WithMany() .WithMany("Trips")
.HasForeignKey("GuideId") .HasForeignKey("GuideId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
@ -409,6 +409,8 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{ {
b.Navigation("Places");
b.Navigation("Tours"); b.Navigation("Tours");
}); });
@ -417,6 +419,13 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.Navigation("Tours"); b.Navigation("Tours");
}); });
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Guide", b =>
{
b.Navigation("ExcursionGroups");
b.Navigation("Trips");
});
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b => modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{ {
b.Navigation("Trips"); b.Navigation("Trips");
@ -433,6 +442,15 @@ namespace TravelAgencyDatabaseImplement.Migrations
{ {
b.Navigation("Places"); b.Navigation("Places");
}); });
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.User", b =>
{
b.Navigation("ExcursionGroups");
b.Navigation("Excursions");
b.Navigation("Tours");
});
#pragma warning restore 612, 618 #pragma warning restore 612, 618
} }
} }

View File

@ -44,6 +44,9 @@ namespace TravelAgencyDatabaseImplement.Models
[ForeignKey("ExcursionId")] [ForeignKey("ExcursionId")]
public virtual List<ExcursionTour> Tours { get; set; } = new(); public virtual List<ExcursionTour> Tours { get; set; } = new();
[ForeignKey("ExcursionId")]
public virtual List<Place> Places { get; set; } = new();
public static Excursion? Create(TravelAgencyDatabase context, ExcursionBindingModel? model) public static Excursion? Create(TravelAgencyDatabase context, ExcursionBindingModel? model)
{ {
if (model == null) if (model == null)

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TravelAgencyContracts.BindingModels; using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.ViewModels; using TravelAgencyContracts.ViewModels;
using TravelAgencyDataModels.Models; using TravelAgencyDataModels.Models;
@ -18,6 +19,12 @@ namespace TravelAgencyDatabaseImplement.Models
[Required] [Required]
public string PhoneNumber { get; set; } = string.Empty; public string PhoneNumber { get; set; } = string.Empty;
[ForeignKey("GuideId")]
public virtual List<Trip> Trips { get; set; } = new();
[ForeignKey("GuideId")]
public virtual List<ExcursionGroup> ExcursionGroups { get; set; } = new();
public static Guide? Create(GuideBindingModel? model) public static Guide? Create(GuideBindingModel? model)
{ {
if (model == null) if (model == null)

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using TravelAgencyContracts.BindingModels; using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.ViewModels; using TravelAgencyContracts.ViewModels;
using TravelAgencyDataModels.Models; using TravelAgencyDataModels.Models;
@ -21,6 +22,15 @@ namespace TravelAgencyDatabaseImplement.Models
[Required] [Required]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[ForeignKey("UserId")]
public virtual List<Excursion> Excursions { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<ExcursionGroup> ExcursionGroups { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Tour> Tours { get; set; } = new();
public static User? Create(UserBindingModel? model) public static User? Create(UserBindingModel? model)
{ {
if (model == null) if (model == null)