diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ContractorStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ContractorStorage.cs index 0bfa624..f151551 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ContractorStorage.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ContractorStorage.cs @@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Contractor; using TravelCompanyContracts.SearchModels.Contractor; using TravelCompanyContracts.StoragesModels.Contractor; using TravelCompanyContracts.ViewModels.Contractor.ViewModels; -using TravelCompanyDatabaseImplement.Models.ContractorModels; +using TravelCompanyDatabaseImplement.Models; namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionGroupStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionGroupStorage.cs index a998f34..1326082 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionGroupStorage.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionGroupStorage.cs @@ -8,7 +8,7 @@ using TravelCompanyContracts.BindingModels.Contractor; using TravelCompanyContracts.SearchModels.Contractor; using TravelCompanyContracts.StoragesModels.Contractor; using TravelCompanyContracts.ViewModels.Contractor.ViewModels; -using TravelCompanyDatabaseImplement.Models.ContractorModels; +using TravelCompanyDatabaseImplement.Models; namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionStorage.cs index f9efeb4..b9b25ec 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionStorage.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/ExcursionStorage.cs @@ -8,7 +8,7 @@ using TravelCompanyContracts.BindingModels.Contractor; using TravelCompanyContracts.SearchModels.Contractor; using TravelCompanyContracts.StoragesModels.Contractor; using TravelCompanyContracts.ViewModels.Contractor.ViewModels; -using TravelCompanyDatabaseImplement.Models.ContractorModels; +using TravelCompanyDatabaseImplement.Models; namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/TourStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/TourStorage.cs index 8ab9bd5..691cd51 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/TourStorage.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ContractorImplements/TourStorage.cs @@ -8,7 +8,7 @@ using TravelCompanyContracts.BindingModels.Contractor; using TravelCompanyContracts.SearchModels.Contractor; using TravelCompanyContracts.StoragesModels.Contractor; using TravelCompanyContracts.ViewModels.Contractor.ViewModels; -using TravelCompanyDatabaseImplement.Models.ContractorModels; +using TravelCompanyDatabaseImplement.Models; namespace TravelCompanyDatabaseImplement.Implements.ContractorImplements { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Contractor.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Contractor.cs similarity index 97% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Contractor.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/Contractor.cs index 25471e7..968fc94 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Contractor.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Contractor.cs @@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Contractor; using TravelCompanyContracts.ViewModels.Contractor.ViewModels; using TravelCompanyDataModels.Models.Contractor; -namespace TravelCompanyDatabaseImplement.Models.ContractorModels +namespace TravelCompanyDatabaseImplement.Models { public class Contractor : IContractorModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroup.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroup.cs deleted file mode 100644 index 485d4ca..0000000 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroup.cs +++ /dev/null @@ -1,109 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using TravelCompanyContracts.BindingModels.Contractor; -using TravelCompanyContracts.ViewModels.Contractor.ViewModels; -using TravelCompanyDataModels.Models.Contractor; -using Microsoft.EntityFrameworkCore; -using TravelCompanyDatabaseImplement.Models.GuarantorModels; - -namespace TravelCompanyDatabaseImplement.Models.ContractorModels -{ - public class ExcursionGroup : IExcursionGroupModel - { - public int Id { get; set; } - - [Required] - public string ExcursionGroupName { get; set; } = string.Empty; - - [Required] - public int PeopleAmount { get; set; } - - [Required] - public int ContractorID { get; set; } - - [DeleteBehavior(DeleteBehavior.Restrict)] - public virtual Contractor Contractor { get; set; }} - - private Dictionary? _excursionGroupTours = null; - - [NotMapped] - public Dictionary ExcursionGroupTours - { - get - { - if (_excursionGroupTours == null) - { - _excursionGroupTours = Tours - .ToDictionary(recPC => recPC.TourId, recPC => recPC.Tour as ITourModel); - } - return _excursionGroupTours; - } - } - - [ForeignKey("ExcursionGroupId")] - public virtual List Tours { get; set; } = new(); - - public static ExcursionGroup? Create(TravelCompanyDatabase context, ExcursionGroupBindingModel? model) - { - if (model == null) - { - return null; - } - return new ExcursionGroup() - { - Id = model.Id, - ExcursionGroupName = model.ExcursionGroupName, - PeopleAmount = model.PeopleAmount, - ContractorID = model.ContractorID, - Tours = model.ExcursionGroupTours.Select(x => new ExcursionGroupTour - { - Tour = context.Tours.First(y => y.Id == x.Key) - }).ToList() - }; - } - public void Update(ExcursionGroupBindingModel? model) - { - if (model == null) - { - return; - } - ExcursionGroupName = model.ExcursionGroupName; - PeopleAmount = model.PeopleAmount; - } - - public ExcursionGroupViewModel GetViewModel => new() - { - Id = Id, - ExcursionGroupName = ExcursionGroupName, - PeopleAmount = PeopleAmount, - ContractorID = ContractorID, - ExcursionGroupTours = ExcursionGroupTours - }; - - public void UpdateTours(TravelCompanyDatabase context, ExcursionGroupBindingModel model) - { - var excursionGroupTours = context.ExcursionGroupTours.Where(rec => rec.ExcursionGroupId == model.Id).ToList(); - if (excursionGroupTours != null && excursionGroupTours.Count > 0) - { - context.ExcursionGroupTours.RemoveRange(excursionGroupTours.Where(rec => !model.ExcursionGroupTours.ContainsKey(rec.TourId))); - context.SaveChanges(); - } - var excursionGroup = context.ExcursionGroups.First(x => x.Id == Id); - foreach (var et in model.ExcursionGroupTours) - { - context.ExcursionGroupTours.Add(new ExcursionGroupTour - { - ExcursionGroup = excursionGroup, - Tour = context.Tours.First(x => x.Id == et.Key) - }); - context.SaveChanges(); - } - _excursionGroupTours = null; - } - } -} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Excursion.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Excursion.cs similarity index 96% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Excursion.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/Excursion.cs index 1fe9515..5749e3e 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Excursion.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Excursion.cs @@ -11,7 +11,7 @@ using TravelCompanyDataModels.Models.Contractor; using Microsoft.EntityFrameworkCore; using TravelCompanyDatabaseImplement.Models.GuarantorModels; -namespace TravelCompanyDatabaseImplement.Models.ContractorModels +namespace TravelCompanyDatabaseImplement.Models { public class Excursion : IExcursionModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroup.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroup.cs new file mode 100644 index 0000000..ce1cf20 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroup.cs @@ -0,0 +1,110 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using TravelCompanyContracts.BindingModels.Contractor; +using TravelCompanyContracts.ViewModels.Contractor.ViewModels; +using TravelCompanyDataModels.Models.Contractor; +using Microsoft.EntityFrameworkCore; +using TravelCompanyDatabaseImplement.Models.GuarantorModels; + +namespace TravelCompanyDatabaseImplement.Models +{ + public class ExcursionGroup : IExcursionGroupModel + { + public int Id { get; set; } + + [Required] + public string ExcursionGroupName { get; set; } = string.Empty; + + [Required] + public int PeopleAmount { get; set; } + + [Required] + public int ContractorID { get; set; } + + [DeleteBehavior(DeleteBehavior.Restrict)] + public virtual Contractor Contractor { get; set; } + } + + private Dictionary? _excursionGroupTours = null; + + [NotMapped] + public Dictionary ExcursionGroupTours + { + get + { + if (_excursionGroupTours == null) + { + _excursionGroupTours = Tours + .ToDictionary(recPC => recPC.TourId, recPC => recPC.Tour as ITourModel); + } + return _excursionGroupTours; + } + } + + [ForeignKey("ExcursionGroupId")] + public virtual List Tours { get; set; } = new(); + + public static ExcursionGroup? Create(TravelCompanyDatabase context, ExcursionGroupBindingModel? model) + { + if (model == null) + { + return null; + } + return new ExcursionGroup() + { + Id = model.Id, + ExcursionGroupName = model.ExcursionGroupName, + PeopleAmount = model.PeopleAmount, + ContractorID = model.ContractorID, + Tours = model.ExcursionGroupTours.Select(x => new ExcursionGroupTour + { + Tour = context.Tours.First(y => y.Id == x.Key) + }).ToList() + }; + } + public void Update(ExcursionGroupBindingModel? model) + { + if (model == null) + { + return; + } + ExcursionGroupName = model.ExcursionGroupName; + PeopleAmount = model.PeopleAmount; + } + + public ExcursionGroupViewModel GetViewModel => new() + { + Id = Id, + ExcursionGroupName = ExcursionGroupName, + PeopleAmount = PeopleAmount, + ContractorID = ContractorID, + ExcursionGroupTours = ExcursionGroupTours + }; + + public void UpdateTours(TravelCompanyDatabase context, ExcursionGroupBindingModel model) + { + var excursionGroupTours = context.ExcursionGroupTours.Where(rec => rec.ExcursionGroupId == model.Id).ToList(); + if (excursionGroupTours != null && excursionGroupTours.Count > 0) + { + context.ExcursionGroupTours.RemoveRange(excursionGroupTours.Where(rec => !model.ExcursionGroupTours.ContainsKey(rec.TourId))); + context.SaveChanges(); + } + var excursionGroup = context.ExcursionGroups.First(x => x.Id == Id); + foreach (var et in model.ExcursionGroupTours) + { + context.ExcursionGroupTours.Add(new ExcursionGroupTour + { + ExcursionGroup = excursionGroup, + Tour = context.Tours.First(x => x.Id == et.Key) + }); + context.SaveChanges(); + } + _excursionGroupTours = null; + } +} +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroupTour.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroupTour.cs similarity index 88% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroupTour.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroupTour.cs index 5246f43..627038e 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroupTour.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroupTour.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; -namespace TravelCompanyDatabaseImplement.Models.ContractorModels +namespace TravelCompanyDatabaseImplement.Models { public class ExcursionGroupTour { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionTour.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionTour.cs similarity index 88% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionTour.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionTour.cs index 8122d7b..66f3f96 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionTour.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionTour.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; -namespace TravelCompanyDatabaseImplement.Models.ContractorModels +namespace TravelCompanyDatabaseImplement.Models { public class ExcursionTour { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Guarantor.cs similarity index 97% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/Guarantor.cs index 2bf1f6a..d9a4baf 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Guarantor.cs @@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Guarantor; using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; using TravelCompanyDataModels.Models.Guarantor; -namespace TravelCompanyDatabaseImplement.Models.GuarantorModels +namespace TravelCompanyDatabaseImplement.Models { public class Guarantor : IGuarantorModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guide.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Guide.cs similarity index 71% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guide.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/Guide.cs index dfb0e4f..725b66e 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guide.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Guide.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyDatabaseImplement.Models.GuarantorModels +namespace TravelCompanyDatabaseImplement.Models { internal class Guide { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Place.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Place.cs similarity index 71% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Place.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/Place.cs index afa15d6..579209a 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Place.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Place.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyDatabaseImplement.Models.GuarantorModels +namespace TravelCompanyDatabaseImplement.Models { internal class Place { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Tour.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Tour.cs similarity index 96% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Tour.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/Tour.cs index b114b31..2be9f2b 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Tour.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Tour.cs @@ -10,7 +10,7 @@ using TravelCompanyContracts.ViewModels.Contractor.ViewModels; using TravelCompanyDataModels.Models.Contractor; using Microsoft.EntityFrameworkCore; -namespace TravelCompanyDatabaseImplement.Models.ContractorModels +namespace TravelCompanyDatabaseImplement.Models { public class Tour : ITourModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Trip.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Trip.cs similarity index 71% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Trip.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/Trip.cs index 32f27d8..6fc44c7 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Trip.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Trip.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyDatabaseImplement.Models.GuarantorModels +namespace TravelCompanyDatabaseImplement.Models { internal class Trip { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs index 3b297b2..6f05b5e 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs @@ -3,11 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using TravelCompanyDatabaseImplement.Models.ContractorModels; -using TravelCompanyDatabaseImplement.Models.GuarantorModels; using Microsoft.EntityFrameworkCore; using System.Security.Principal; - +using TravelCompanyDatabaseImplement.Models; namespace TravelCompanyDatabaseImplement { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj index 091d082..168b2fd 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj @@ -20,4 +20,9 @@ + + + + +