From 32c00a42a66c7d3642c6c9306ebfc701371feb48 Mon Sep 17 00:00:00 2001 From: platoff aeeee Date: Tue, 30 Apr 2024 21:55:47 +0400 Subject: [PATCH] =?UTF-8?q?Revert=20"=D0=BC=D0=BE=D0=BB=D0=BE=D0=B4=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=B1=D0=B5=D0=BB=D1=8B=D0=B9"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 654f87f8886627ecf69d08668aeeaae17c55377f. --- .../Guarantor/PlaceSearchModel.cs | 4 +- .../SearchModels/Guarantor/TripSearchModel.cs | 6 +- .../Guarantor/IGuarantorStorage.cs | 8 +- .../StoragesModels/Guarantor/IGuideStorage.cs | 7 +- .../StoragesModels/Guarantor/IPlaceStorage.cs | 7 +- .../StoragesModels/Guarantor/ITripStorage.cs | 16 +-- .../GuarantorImplements/GuarantorStorage.cs | 100 +--------------- .../{ => ContractorModels}/Contractor.cs | 2 +- .../{ => ContractorModels}/Excursion.cs | 2 +- .../Models/ContractorModels/ExcursionGroup.cs | 109 +++++++++++++++++ .../ExcursionGroupTour.cs | 2 +- .../{ => ContractorModels}/ExcursionTour.cs | 2 +- .../Models/{ => ContractorModels}/Tour.cs | 2 +- .../Models/ExcursionGroup.cs | 110 ------------------ .../Models/{ => GuarantorModels}/Guarantor.cs | 2 +- .../Models/{ => GuarantorModels}/Guide.cs | 2 +- .../Models/{ => GuarantorModels}/Place.cs | 2 +- .../Models/{ => GuarantorModels}/Trip.cs | 2 +- .../TravelCompanyDatabase.cs | 4 +- 19 files changed, 136 insertions(+), 253 deletions(-) rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => ContractorModels}/Contractor.cs (97%) rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => ContractorModels}/Excursion.cs (96%) create mode 100644 TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroup.cs rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => ContractorModels}/ExcursionGroupTour.cs (88%) rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => ContractorModels}/ExcursionTour.cs (88%) rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => ContractorModels}/Tour.cs (96%) delete mode 100644 TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroup.cs rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => GuarantorModels}/Guarantor.cs (97%) rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => GuarantorModels}/Guide.cs (71%) rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => GuarantorModels}/Place.cs (71%) rename TravelCompany/TravelCompanyDatabaseImplement/Models/{ => GuarantorModels}/Trip.cs (71%) diff --git a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/PlaceSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/PlaceSearchModel.cs index 2d343e5..446762e 100644 --- a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/PlaceSearchModel.cs +++ b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/PlaceSearchModel.cs @@ -11,8 +11,8 @@ namespace TravelCompanyContracts.SearchModels.Guarantor { public int? Id { get; set; } - public string? NamePlace { get; set; } = string.Empty; + public string NamePlace { get; set; } = string.Empty; - public string? DescriptionPlace { get; set; } = string.Empty; + public string DescriptionPlace { get; set; } = string.Empty; } } diff --git a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/TripSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/TripSearchModel.cs index 0268ade..c819c9e 100644 --- a/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/TripSearchModel.cs +++ b/TravelCompany/TravelCompanyContracts/SearchModels/Guarantor/TripSearchModel.cs @@ -6,11 +6,7 @@ using System.Threading.Tasks; namespace TravelCompanyContracts.SearchModels.Guarantor { - public class TripSearchModel + internal class TripSearchModel { - public int? Id { get; set; } - public string? TripName { get; set; } = string.Empty; - public DateTime? TripDate { get; set; } - public int? GuarantorID { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuarantorStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuarantorStorage.cs index a1e89f8..20b3d63 100644 --- a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuarantorStorage.cs +++ b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuarantorStorage.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using TravelCompanyContracts.BindingModels.Guarantor; +using TravelCompanyContracts.BindingModels; using TravelCompanyContracts.SearchModels.Guarantor; using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; @@ -18,10 +18,10 @@ namespace TravelCompanyContracts.StoragesModels.Guarantor GuarantorViewModel? GetElement(GuarantorSearchModel model); - GuarantorViewModel? Insert(GuarantorBindingModel model); + GuarantorViewModel? Insert(GuarantorSearchModel model); - GuarantorViewModel? Update(GuarantorBindingModel model); + GuarantorViewModel? Update(GuarantorSearchModel model); - GuarantorViewModel? Delete(GuarantorBindingModel model); + GuarantorViewModel? Delete(GuarantorSearchModel model); } } diff --git a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuideStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuideStorage.cs index c961b05..711ba77 100644 --- a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuideStorage.cs +++ b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IGuideStorage.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using TravelCompanyContracts.BindingModels; -using TravelCompanyContracts.BindingModels.Guarantor; using TravelCompanyContracts.SearchModels.Guarantor; using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; @@ -19,10 +18,10 @@ namespace TravelCompanyContracts.StoragesModels.Guarantor GuideViewModel? GetElement(GuideSearchModel model); - GuideViewModel? Insert(GuideBindingModel model); + GuideViewModel? Insert(GuideSearchModel model); - GuideViewModel? Update(GuideBindingModel model); + GuideViewModel? Update(GuideSearchModel model); - GuideViewModel? Delete(GuideBindingModel model); + GuideViewModel? Delete(GuideSearchModel model); } } diff --git a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IPlaceStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IPlaceStorage.cs index 18894df..c950519 100644 --- a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IPlaceStorage.cs +++ b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/IPlaceStorage.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using TravelCompanyContracts.BindingModels.Guarantor; using TravelCompanyContracts.SearchModels.Guarantor; using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; @@ -18,10 +17,10 @@ namespace TravelCompanyContracts.StoragesModels.Guarantor PlaceViewModel? GetElement(PlaceSearchModel model); - PlaceViewModel? Insert(PlaceBindingModel model); + PlaceViewModel? Insert(PlaceSearchModel model); - PlaceViewModel? Update(PlaceBindingModel model); + PlaceViewModel? Update(PlaceSearchModel model); - PlaceViewModel? Delete(PlaceBindingModel model); + PlaceViewModel? Delete(PlaceSearchModel model); } } diff --git a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/ITripStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/ITripStorage.cs index cd42089..b83db3f 100644 --- a/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/ITripStorage.cs +++ b/TravelCompany/TravelCompanyContracts/StoragesModels/Guarantor/ITripStorage.cs @@ -3,24 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using TravelCompanyContracts.BindingModels.Guarantor; -using TravelCompanyContracts.SearchModels.Guarantor; -using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; namespace TravelCompanyContracts.StoragesModels.Guarantor { - public interface ITripStorage + internal class ITripStorage { - List GetFullList(); - - List GetFilteredList(TripSearchModel model); - - TripViewModel? GetElement(TripSearchModel model); - - TripViewModel? Insert(TripBindingModel model); - - TripViewModel? Update(TripBindingModel model); - - TripViewModel? Delete(TripBindingModel model); } } diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/GuarantorImplements/GuarantorStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/GuarantorImplements/GuarantorStorage.cs index 1b3e1d1..7f49d29 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Implements/GuarantorImplements/GuarantorStorage.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/GuarantorImplements/GuarantorStorage.cs @@ -3,108 +3,10 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using TravelCompanyContracts.BindingModels.Contractor; -using TravelCompanyContracts.BindingModels.Guarantor; -using TravelCompanyContracts.SearchModels.Contractor; -using TravelCompanyContracts.SearchModels.Guarantor; -using TravelCompanyContracts.StoragesModels.Guarantor; -using TravelCompanyContracts.ViewModels.Contractor.ViewModels; -using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; -using TravelCompanyDatabaseImplement.Models; -using TravelCompanyDatabaseImplement.Models.ContractorModels; namespace TravelCompanyDatabaseImplement.Implements.GuarantorImplements { - public class GuarantorStorage : IGuarantorStorage + internal class GuarantorStorage { - public List GetFullList() - { - using var context = new TravelCompanyDatabase(); - return context.Guarantors - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFilteredList(GuarantorSearchModel model) - { - if (string.IsNullOrEmpty(model.Surname)) - { - return new(); - } - using var context = new TravelCompanyDatabase(); - return context.Guarantors - .Where(x => x.Surname.Contains(model.Surname)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public GuarantorViewModel? GetElement(GuarantorSearchModel model) - { - using var context = new TravelCompanyDatabase(); - if (model.Id.HasValue) - { - return context.Guarantors - .FirstOrDefault(x => x.Id.Equals(model.Id)) - ?.GetViewModel; - } - if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) - { - return context.Guarantors - .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) - ?.GetViewModel; - } - if (!string.IsNullOrEmpty(model.Email)) - { - return context.Guarantors - .FirstOrDefault(x => x.Email.Equals(model.Email)) - ?.GetViewModel; - } - if (!string.IsNullOrEmpty(model.MobilePhone)) - { - return context.Guarantors - .FirstOrDefault(x => x.MobilePhone.Equals(model.MobilePhone)) - ?.GetViewModel; - } - return null; - } - - public GuarantorViewModel? Insert(GuarantorBindingModel model) - { - var newGuarantor = Guarantor.Create(model); - if (newGuarantor == null) - { - return null; - } - using var context = new TravelCompanyDatabase(); - context.Guarantors.Add(newGuarantor); - context.SaveChanges(); - return newGuarantor.GetViewModel; - } - - public GuarantorViewModel? Update(GuarantorBindingModel model) - { - using var context = new TravelCompanyDatabase(); - var guarantor = context.Guarantors.FirstOrDefault(x => x.Id == model.Id); - if (guarantor == null) - { - return null; - } - guarantor.Update(model); - context.SaveChanges(); - return guarantor.GetViewModel; - } - - public GuarantorViewModel? Delete(GuarantorBindingModel model) - { - using var context = new TravelCompanyDatabase(); - var element = context.Guarantors.FirstOrDefault(x => x.Id == model.Id); - if (element != null) - { - context.Guarantors.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } } } diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Contractor.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Contractor.cs similarity index 97% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/Contractor.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Contractor.cs index 968fc94..25471e7 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Contractor.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Contractor.cs @@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Contractor; using TravelCompanyContracts.ViewModels.Contractor.ViewModels; using TravelCompanyDataModels.Models.Contractor; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.ContractorModels { public class Contractor : IContractorModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Excursion.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Excursion.cs similarity index 96% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/Excursion.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Excursion.cs index 5749e3e..1fe9515 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Excursion.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Excursion.cs @@ -11,7 +11,7 @@ using TravelCompanyDataModels.Models.Contractor; using Microsoft.EntityFrameworkCore; using TravelCompanyDatabaseImplement.Models.GuarantorModels; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.ContractorModels { public class Excursion : IExcursionModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroup.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroup.cs new file mode 100644 index 0000000..485d4ca --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroup.cs @@ -0,0 +1,109 @@ +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/ExcursionGroupTour.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroupTour.cs similarity index 88% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroupTour.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroupTour.cs index 627038e..5246f43 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroupTour.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionGroupTour.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.ContractorModels { public class ExcursionGroupTour { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionTour.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionTour.cs similarity index 88% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionTour.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionTour.cs index 66f3f96..8122d7b 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionTour.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/ExcursionTour.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.ContractorModels { public class ExcursionTour { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Tour.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Tour.cs similarity index 96% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/Tour.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Tour.cs index 2be9f2b..b114b31 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Tour.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/ContractorModels/Tour.cs @@ -10,7 +10,7 @@ using TravelCompanyContracts.ViewModels.Contractor.ViewModels; using TravelCompanyDataModels.Models.Contractor; using Microsoft.EntityFrameworkCore; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.ContractorModels { public class Tour : ITourModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroup.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroup.cs deleted file mode 100644 index ce1cf20..0000000 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/ExcursionGroup.cs +++ /dev/null @@ -1,110 +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 -{ - 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/Guarantor.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs similarity index 97% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/Guarantor.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs index d9a4baf..2bf1f6a 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Guarantor.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guarantor.cs @@ -9,7 +9,7 @@ using TravelCompanyContracts.BindingModels.Guarantor; using TravelCompanyContracts.ViewModels.Guarantor.ViewModels; using TravelCompanyDataModels.Models.Guarantor; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.GuarantorModels { public class Guarantor : IGuarantorModel { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Guide.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guide.cs similarity index 71% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/Guide.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guide.cs index 725b66e..dfb0e4f 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Guide.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Guide.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.GuarantorModels { internal class Guide { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Place.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Place.cs similarity index 71% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/Place.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Place.cs index 579209a..afa15d6 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Place.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Place.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.GuarantorModels { internal class Place { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Trip.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Trip.cs similarity index 71% rename from TravelCompany/TravelCompanyDatabaseImplement/Models/Trip.cs rename to TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Trip.cs index 6fc44c7..32f27d8 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/Models/Trip.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/GuarantorModels/Trip.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelCompanyDatabaseImplement.Models +namespace TravelCompanyDatabaseImplement.Models.GuarantorModels { internal class Trip { diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs index 6f05b5e..3b297b2 100644 --- a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabase.cs @@ -3,9 +3,11 @@ 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 {