diff --git a/TravelAgency/TravelAgency.sln b/TravelAgency/TravelAgency.sln deleted file mode 100644 index 556dc05..0000000 --- a/TravelAgency/TravelAgency.sln +++ /dev/null @@ -1,37 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.8.34322.80 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelAgencyView", "TravelAgencyView\TravelAgencyView.csproj", "{1C65EB1E-2405-44DD-84E3-6BEA3A5A0197}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelAgencyDataModels", "TravelAgencyDataModels\TravelAgencyDataModels.csproj", "{DF3667E3-B2C0-4303-BE54-D23B19D72667}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TravelAgencyCompanyContracts", "TravelAgencyCompanyContracts\TravelAgencyCompanyContracts.csproj", "{EEC43C70-1112-4652-B3DB-58A1515FC3AC}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1C65EB1E-2405-44DD-84E3-6BEA3A5A0197}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1C65EB1E-2405-44DD-84E3-6BEA3A5A0197}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1C65EB1E-2405-44DD-84E3-6BEA3A5A0197}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1C65EB1E-2405-44DD-84E3-6BEA3A5A0197}.Release|Any CPU.Build.0 = Release|Any CPU - {DF3667E3-B2C0-4303-BE54-D23B19D72667}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DF3667E3-B2C0-4303-BE54-D23B19D72667}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DF3667E3-B2C0-4303-BE54-D23B19D72667}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DF3667E3-B2C0-4303-BE54-D23B19D72667}.Release|Any CPU.Build.0 = Release|Any CPU - {EEC43C70-1112-4652-B3DB-58A1515FC3AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EEC43C70-1112-4652-B3DB-58A1515FC3AC}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EEC43C70-1112-4652-B3DB-58A1515FC3AC}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EEC43C70-1112-4652-B3DB-58A1515FC3AC}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {5DEAA9BB-3BF1-49E8-8AE9-133B5E2C9F0A} - EndGlobalSection -EndGlobal diff --git a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/CustomerBindingModel.cs b/TravelAgency/TravelAgencyCompanyContracts/BindingModels/CustomerBindingModel.cs deleted file mode 100644 index 52beab7..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/CustomerBindingModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.BindingModels -{ - public class CustomerBindingModel: ICustomerModel - { - public int Id { get; set; } - public string Fio { get; set; } = string.Empty; - public string PhoneNumber { get; set; } = string.Empty; - - public string Email { get; set; } = string.Empty; - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/HotelBindingModel.cs b/TravelAgency/TravelAgencyCompanyContracts/BindingModels/HotelBindingModel.cs deleted file mode 100644 index 8f92293..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/HotelBindingModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.BindingModels -{ - public class HotelBindingModel : IHotelModel - { - public int Id { get; set; } - public string Name { get; set; } = string.Empty; - public string Address { get; set; } = string.Empty; - public int NumberStars { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/MedicalInsuranceBindingModel.cs b/TravelAgency/TravelAgencyCompanyContracts/BindingModels/MedicalInsuranceBindingModel.cs deleted file mode 100644 index 3daea98..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/MedicalInsuranceBindingModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.BindingModels -{ - public class MedicalInsuranceBindingModel: IMedicalInsuranceModel - { - public int Id { get; set; } - public string Type { get; set; } = string.Empty; - public int Sum { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/ReportBindingModel.cs b/TravelAgency/TravelAgencyCompanyContracts/BindingModels/ReportBindingModel.cs deleted file mode 100644 index e606901..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/ReportBindingModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TravelAgencyCompanyContracts.BindingModels -{ - public class ReportBindingModel - { - public string FileName { get; set; } = string.Empty; - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } - - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/TourBindingModel.cs b/TravelAgency/TravelAgencyCompanyContracts/BindingModels/TourBindingModel.cs deleted file mode 100644 index 0077a15..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/TourBindingModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Enums; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.BindingModels -{ - public class TourBindingModel:ITourModel - { - public int Id { get; set; } - public int CustomerId { get; set; } - public int HotelId { get; set; } - public int TransportId { get; set; } - public int InsuranceId { get; set; } - public string ToPlace { get; set; } = string.Empty; - public string FromPlace { get; set; } = string.Empty; - public int CountNight { get; set; } - public StructureStatus Status { get; set; } = StructureStatus.Неизвестен; - public DateTime DepartureDate { get; set; } = DateTime.Now; - public DateTime? ArrivalDate { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/TransportBindingModel.cs b/TravelAgency/TravelAgencyCompanyContracts/BindingModels/TransportBindingModel.cs deleted file mode 100644 index d786e4e..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BindingModels/TransportBindingModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.BindingModels -{ - public class TransportBindingModel:ITransportModel - { - public int Id { get; set; } - public string Type { get; set; } = string.Empty; - public string Number { get; set; } = string.Empty; - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ICustomerLogic.cs b/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ICustomerLogic.cs deleted file mode 100644 index ac2db05..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ICustomerLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.BusinessLogicsContracts -{ - public interface ICustomerLogic - { - List? ReadList(CustomerSearchModel? model); - CustomerViewModel? ReadElement(CustomerSearchModel model); - bool Create(CustomerBindingModel model); - bool Update(CustomerBindingModel model); - bool Delete(CustomerBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IHotelLogic.cs b/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IHotelLogic.cs deleted file mode 100644 index 9327f06..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IHotelLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.BusinessLogicsContracts -{ - public interface IHotelLogic - { - List? ReadList(HotelSearchModel? model); - HotelViewModel? ReadElement(HotelSearchModel model); - bool Create(HotelBindingModel model); - bool Update(HotelBindingModel model); - bool Delete(HotelBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IMedicalInsuranceLogic.cs b/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IMedicalInsuranceLogic.cs deleted file mode 100644 index 75a7e5c..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IMedicalInsuranceLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.BusinessLogicsContracts -{ - public interface IMedicalInsuranceLogic - { - List? ReadList(MedicalInsuranceSearchModel? model); - MedicalInsuranceViewModel? ReadElement(MedicalInsuranceSearchModel model); - bool Create(MedicalInsuranceBindingModel model); - bool Update(MedicalInsuranceBindingModel model); - bool Delete(MedicalInsuranceBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IReportLogic.cs b/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IReportLogic.cs deleted file mode 100644 index 0da7018..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/IReportLogic.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; - -namespace TravelAgencyCompanyContracts.BusinessLogicsContracts -{ - public interface IReportLogic - { - List GetStructures(ReportBindingModel model); - void SaveStructuresToWordFile(ReportBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ITourLogic.cs b/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ITourLogic.cs deleted file mode 100644 index ba8293d..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ITourLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.BusinessLogicsContracts -{ - public interface ITourLogic - { - List? ReadList(TourSearchModel? model); - TourViewModel? ReadElement(TourSearchModel model); - bool Create(TourBindingModel model); - bool Update(TourBindingModel model); - bool Delete(TourBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ITransportLogic.cs b/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ITransportLogic.cs deleted file mode 100644 index 5e9646d..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/BusinessLogicsContracts/ITransportLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.BusinessLogicsContracts -{ - public interface ITransportLogic - { - List? ReadList(TransportSearchModel? model); - TransportViewModel? ReadElement(TransportSearchModel model); - bool Create(TransportBindingModel model); - bool Update(TransportBindingModel model); - bool Delete(TransportBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/CustomerSearchModel.cs b/TravelAgency/TravelAgencyCompanyContracts/SearchModel/CustomerSearchModel.cs deleted file mode 100644 index 67220dd..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/CustomerSearchModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TravelAgencyCompanyContracts.SearchModel -{ - public class CustomerSearchModel - { - public int? Id { get; set; } - public string? Fio { get; set; } - public string? PhoneNumber { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/TourSearchModel.cs b/TravelAgency/TravelAgencyCompanyContracts/SearchModel/TourSearchModel.cs deleted file mode 100644 index e39a295..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/TourSearchModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TravelAgencyCompanyContracts.SearchModel -{ - public class TourSearchModel - { - public int? Id { get; set; } - public DateTime? DateFrom { get; set; } - public DateTime? DateTo { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ICustomerStorage.cs b/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ICustomerStorage.cs deleted file mode 100644 index 031b41d..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ICustomerStorage.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.StoragesContracts -{ - public interface ICustomerStorage - { - List GetFullList(); - List GetFilteredList(CustomerSearchModel model); - CustomerViewModel? GetElement(CustomerSearchModel model); - CustomerViewModel? Insert(CustomerBindingModel model); - CustomerViewModel? Update(CustomerBindingModel model); - CustomerViewModel? Delete(CustomerBindingModel model); - - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/IHotelStorage.cs b/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/IHotelStorage.cs deleted file mode 100644 index eb21332..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/IHotelStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.StoragesContracts -{ - public interface IHotelStorage - { - List GetFullList(); - List GetFilteredList(HotelSearchModel model); - HotelViewModel? GetElement(HotelSearchModel model); - HotelViewModel? Insert(HotelBindingModel model); - HotelViewModel? Update(HotelBindingModel model); - HotelViewModel? Delete(HotelBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/IMedicalInsuranceStorage.cs b/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/IMedicalInsuranceStorage.cs deleted file mode 100644 index 0d09a5a..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/IMedicalInsuranceStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.StoragesContracts -{ - public interface IMedicalInsuranceStorage - { - List GetFullList(); - List GetFilteredList(MedicalInsuranceSearchModel model); - MedicalInsuranceViewModel? GetElement(MedicalInsuranceSearchModel model); - MedicalInsuranceViewModel? Insert(MedicalInsuranceBindingModel model); - MedicalInsuranceViewModel? Update(MedicalInsuranceBindingModel model); - MedicalInsuranceViewModel? Delete(MedicalInsuranceBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ITourStorage.cs b/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ITourStorage.cs deleted file mode 100644 index fa1aae5..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ITourStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.StoragesContracts -{ - public interface ITourStorage - { - List GetFullList(); - List GetFilteredList(TourSearchModel model); - TourViewModel? GetElement(TourSearchModel model); - TourViewModel? Insert(TourBindingModel model); - TourViewModel? Update(TourBindingModel model); - TourViewModel? Delete(TourBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ITransportStorage.cs b/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ITransportStorage.cs deleted file mode 100644 index cdd7832..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/StoragesContracts/ITransportStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyCompanyContracts.BindingModels; -using TravelAgencyCompanyContracts.SearchModel; -using TravelAgencyCompanyContracts.ViewModel; - -namespace TravelAgencyCompanyContracts.StoragesContracts -{ - public interface ITransportStorage - { - List GetFullList(); - List GetFilteredList(TransportSearchModel model); - TransportViewModel? GetElement(TransportSearchModel model); - TransportViewModel? Insert(TransportBindingModel model); - TransportViewModel? Update(TransportBindingModel model); - TransportViewModel? Delete(TransportBindingModel model); - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/CustomerViewModel.cs b/TravelAgency/TravelAgencyCompanyContracts/ViewModel/CustomerViewModel.cs deleted file mode 100644 index 9505315..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/CustomerViewModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.ViewModel -{ - public class CustomerViewModel:ICustomerModel - { - public int Id { get; set; } - - [DisplayName("ФИО")] - public string Fio { get; set; } = string.Empty; - - [DisplayName("Номер телефона")] - public string PhoneNumber { get; set; } = string.Empty; - - [DisplayName("Электронная почта")] - public string Email { get; set; } = string.Empty; - - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/HotelViewModel.cs b/TravelAgency/TravelAgencyCompanyContracts/ViewModel/HotelViewModel.cs deleted file mode 100644 index e23e11d..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/HotelViewModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.ViewModel -{ - public class HotelViewModel:IHotelModel - - { - public int Id { get; set; } - - [DisplayName("Название отеля")] - public string Name { get; set; } = string.Empty; - [DisplayName("Адрес")] - public string Address { get; set; } = string.Empty; - - [DisplayName("Количество звёзд")] - public int NumberStars { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/MedicalInsuranceViewModel.cs b/TravelAgency/TravelAgencyCompanyContracts/ViewModel/MedicalInsuranceViewModel.cs deleted file mode 100644 index 42a6249..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/MedicalInsuranceViewModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.ViewModel -{ - public class MedicalInsuranceViewModel:IMedicalInsuranceModel - { - public int Id { get; set; } - - [DisplayName("Тип страховки")] - public string Type { get; set; } = string.Empty; - [DisplayName("Стоимость страховки")] - public int Sum { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/ReportTourViewModel.cs b/TravelAgency/TravelAgencyCompanyContracts/ViewModel/ReportTourViewModel.cs deleted file mode 100644 index 30735fa..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/ReportTourViewModel.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Enums; - -namespace TravelAgencyCompanyContracts.ViewModel -{ - public class ReportTourViewModel - { - public int Id { get; set; } - public DateTime DateCreate { get; set; } - public int CustomerId { get; set; } - public int HotelId { get; set; } - public int TransportId { get; set; } - public int InsuranceId { get; set; } - - [DisplayName("Пункт отправления")] - public string FromPlace { get; set; } = string.Empty; - - [DisplayName("Пункт прибытия")] - public string ToPlace { get; set; } = string.Empty; - - [DisplayName("Количество ночей")] - public int CountNight { get; set; } - [DisplayName("Статус")] - public StructureStatus Status { get; set; } = StructureStatus.Неизвестен; - - [DisplayName("Дата начала работ")] - public DateTime DepartureDate { get; set; } = DateTime.Now; - - [DisplayName("Дата окончания работ")] - public DateTime? ArrivalDate { get; set; } - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/TourViewModel.cs b/TravelAgency/TravelAgencyCompanyContracts/ViewModel/TourViewModel.cs deleted file mode 100644 index e2a5860..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/TourViewModel.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Enums; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.ViewModel -{ - public class TourViewModel:ITourModel - { - public int Id { get; set; } - public int CustomerId { get; set; } - public int HotelId { get; set; } - public int TransportId { get; set; } - public int InsuranceId { get; set; } - - [DisplayName("Пункт отправления")] - public string FromPlace { get; set; } = string.Empty; - - [DisplayName("Пункт прибытия")] - public string ToPlace { get; set; } = string.Empty; - - [DisplayName("Количество ночей")] - public int CountNight { get; set; } - [DisplayName("Статус")] - public StructureStatus Status { get; set; } = StructureStatus.Неизвестен; - - [DisplayName("Дата начала работ")] - public DateTime DepartureDate { get; set; } = DateTime.Now; - - [DisplayName("Дата окончания работ")] - public DateTime? ArrivalDate { get; set; } - - } -} diff --git a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/TransportViewModel.cs b/TravelAgency/TravelAgencyCompanyContracts/ViewModel/TransportViewModel.cs deleted file mode 100644 index 2c8bee5..0000000 --- a/TravelAgency/TravelAgencyCompanyContracts/ViewModel/TransportViewModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Models; - -namespace TravelAgencyCompanyContracts.ViewModel -{ - public class TransportViewModel:ITransportModel - { - public int Id { get; set; } - [DisplayName("Вид транспорта")] - public string Type { get; set; } = string.Empty; - [DisplayName("Номер транспорта")] - public string Number { get; set; } = string.Empty; - } -} diff --git a/TravelAgency/TravelAgencyDataModels/Enums/StructureStatus.cs b/TravelAgency/TravelAgencyDataModels/Enums/StructureStatus.cs deleted file mode 100644 index acf12f3..0000000 --- a/TravelAgency/TravelAgencyDataModels/Enums/StructureStatus.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace TravelAgencyDataModels.Enums -{ - public enum StructureStatus - { - Неизвестен = -1, - - Принят = 0, - - В_работе = 1, - - Завершён = 2, - - Сдан = 3 - } -} - diff --git a/TravelAgency/TravelAgencyDataModels/IId.cs b/TravelAgency/TravelAgencyDataModels/IId.cs deleted file mode 100644 index 9d74b3f..0000000 --- a/TravelAgency/TravelAgencyDataModels/IId.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace TravelAgencyDataModels -{ - public interface IId - { - int Id { get; } - } -} - diff --git a/TravelAgency/TravelAgencyDataModels/Models/ICustomerModel.cs b/TravelAgency/TravelAgencyDataModels/Models/ICustomerModel.cs deleted file mode 100644 index 5269f6e..0000000 --- a/TravelAgency/TravelAgencyDataModels/Models/ICustomerModel.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TravelAgencyDataModels.Models -{ - public interface ICustomerModel : IId - { - string Fio { get; } - string PhoneNumber { get; } - string Email { get; } - } -} - diff --git a/TravelAgency/TravelAgencyDataModels/Models/IHotelModel.cs b/TravelAgency/TravelAgencyDataModels/Models/IHotelModel.cs deleted file mode 100644 index 7e5e027..0000000 --- a/TravelAgency/TravelAgencyDataModels/Models/IHotelModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TravelAgencyDataModels.Models -{ - public interface IHotelModel:IId - { - string Name { get; } - string Address { get; } - int NumberStars { get; } - } -} diff --git a/TravelAgency/TravelAgencyDataModels/Models/IMedicalInsuranceModel.cs b/TravelAgency/TravelAgencyDataModels/Models/IMedicalInsuranceModel.cs deleted file mode 100644 index bdbd621..0000000 --- a/TravelAgency/TravelAgencyDataModels/Models/IMedicalInsuranceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TravelAgencyDataModels.Models -{ - public interface IMedicalInsuranceModel : IId - { - string Type { get; } - int Sum { get; } - } -} diff --git a/TravelAgency/TravelAgencyDataModels/Models/ITourModel.cs b/TravelAgency/TravelAgencyDataModels/Models/ITourModel.cs deleted file mode 100644 index 9e7b21d..0000000 --- a/TravelAgency/TravelAgencyDataModels/Models/ITourModel.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using TravelAgencyDataModels.Enums; - -namespace TravelAgencyDataModels.Models -{ - public interface ITourModel:IId - { - int CustomerId { get; } - int HotelId { get; } - int TransportId { get; } - int InsuranceId { get; } - string FromPlace { get; } - string ToPlace { get; } - int CountNight { get; } - StructureStatus Status { get; } - DateTime DepartureDate { get; } - DateTime? ArrivalDate { get; } - } -} diff --git a/TravelAgency/TravelAgencyDataModels/Models/ITransportModel.cs b/TravelAgency/TravelAgencyDataModels/Models/ITransportModel.cs deleted file mode 100644 index 6cba9b7..0000000 --- a/TravelAgency/TravelAgencyDataModels/Models/ITransportModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace TravelAgencyDataModels.Models -{ - public interface ITransportModel: IId - { - string Type { get; } - string Number { get; } - } -} diff --git a/TravelAgency/TravelAgencyDataModels/TravelAgencyDataModels.csproj b/TravelAgency/TravelAgencyDataModels/TravelAgencyDataModels.csproj deleted file mode 100644 index a80106c..0000000 --- a/TravelAgency/TravelAgencyDataModels/TravelAgencyDataModels.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - net6.0 - enable - enable - - - - - - - diff --git a/TravelAgency/TravelAgencyView/Form1.Designer.cs b/TravelAgency/TravelAgencyView/Form1.Designer.cs deleted file mode 100644 index 0400d52..0000000 --- a/TravelAgency/TravelAgencyView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace TravelAgencyView -{ - partial class Form1 - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/TravelAgency/TravelAgencyView/Form1.cs b/TravelAgency/TravelAgencyView/Form1.cs deleted file mode 100644 index d935c2d..0000000 --- a/TravelAgency/TravelAgencyView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace TravelAgencyView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/TravelAgency/TravelAgencyView/Program.cs b/TravelAgency/TravelAgencyView/Program.cs deleted file mode 100644 index 82c83d8..0000000 --- a/TravelAgency/TravelAgencyView/Program.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace TravelAgencyView -{ - internal static class Program - { - /// - /// The main entry point for the application. - /// - [STAThread] - static void Main() - { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); - } - } -} \ No newline at end of file diff --git a/TravelAgency/TravelAgencyView/TravelAgencyView.csproj b/TravelAgency/TravelAgencyView/TravelAgencyView.csproj deleted file mode 100644 index b57c89e..0000000 --- a/TravelAgency/TravelAgencyView/TravelAgencyView.csproj +++ /dev/null @@ -1,11 +0,0 @@ - - - - WinExe - net6.0-windows - enable - true - enable - - - \ No newline at end of file diff --git a/TravelCompany/TracelCompanyFileImplement/DataFileSingleton.cs b/TravelCompany/TracelCompanyFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..1bb27c6 --- /dev/null +++ b/TravelCompany/TracelCompanyFileImplement/DataFileSingleton.cs @@ -0,0 +1,54 @@ +using TravelCompanyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace TravelCompanyFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string TravelFileName = "Travel.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Travels { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SaveTravels() => SaveData(Travels, TravelFileName, "Travels", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Travels = LoadData(TravelFileName, "Travel", x => Travel.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return + XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/TravelCompany/TracelCompanyFileImplement/Implements/ComponentStorage.cs b/TravelCompany/TracelCompanyFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..ea25b28 --- /dev/null +++ b/TravelCompany/TracelCompanyFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,78 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Components.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + + } +} diff --git a/TravelCompany/TracelCompanyFileImplement/Implements/OrderStorage.cs b/TravelCompany/TracelCompanyFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..a6ed4b8 --- /dev/null +++ b/TravelCompany/TracelCompanyFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,90 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => GetViewModel(x)).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return GetViewModel(newOrder); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return GetViewModel(order); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return GetViewModel(order); + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + var travel = source.Travels.FirstOrDefault(x => x.Id == order.TravelId); + viewModel.TravelName = travel?.TravelName; + return viewModel; + } + } +} diff --git a/TravelCompany/TracelCompanyFileImplement/Implements/TravelStorage.cs b/TravelCompany/TracelCompanyFileImplement/Implements/TravelStorage.cs new file mode 100644 index 0000000..0d9ad82 --- /dev/null +++ b/TravelCompany/TracelCompanyFileImplement/Implements/TravelStorage.cs @@ -0,0 +1,82 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyFileImplement.Implements +{ + public class TravelStorage : ITravelStorage + { + private readonly DataFileSingleton source; + + public TravelStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public TravelViewModel? GetElement(TravelSearchModel model) + { + if (string.IsNullOrEmpty(model.TravelName) && !model.Id.HasValue) + { + return null; + } + return source.Travels.FirstOrDefault(x => (!string.IsNullOrEmpty(model.TravelName) && x.TravelName == model.TravelName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(TravelSearchModel model) + { + if (string.IsNullOrEmpty(model.TravelName)) + { + return new(); + } + return source.Travels.Where(x => x.TravelName.Contains(model.TravelName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Travels.Select(x => x.GetViewModel).ToList(); + } + + public TravelViewModel? Insert(TravelBindingModel model) + { + model.Id = source.Travels.Count > 0 ? source.Travels.Max(x => x.Id) + 1 : 1; + var newDoc = Travel.Create(model); + if (newDoc == null) + { + return null; + } + source.Travels.Add(newDoc); + source.SaveTravels(); + return newDoc.GetViewModel; + } + + public TravelViewModel? Update(TravelBindingModel model) + { + var document = source.Travels.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveTravels(); + return document.GetViewModel; + } + public TravelViewModel? Delete(TravelBindingModel model) + { + var document = source.Travels.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SaveTravels(); + return document.GetViewModel; + } + } +} diff --git a/TravelCompany/TracelCompanyFileImplement/Models/Component.cs b/TravelCompany/TracelCompanyFileImplement/Models/Component.cs new file mode 100644 index 0000000..0a39648 --- /dev/null +++ b/TravelCompany/TracelCompanyFileImplement/Models/Component.cs @@ -0,0 +1,64 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace TravelCompanyFileImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/TravelCompany/TracelCompanyFileImplement/Models/Order.cs b/TravelCompany/TracelCompanyFileImplement/Models/Order.cs new file mode 100644 index 0000000..d73b728 --- /dev/null +++ b/TravelCompany/TracelCompanyFileImplement/Models/Order.cs @@ -0,0 +1,104 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Enums; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace TravelCompanyFileImplement.Models +{ + public class Order : IOrderModel + { + public int TravelId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + TravelId = model.TravelId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + TravelId = Convert.ToInt32(element.Element("TravelId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + }; + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + + order.DateImplement = dateImpl; + + if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) + { + return null; + } + order.Status = status; + return order; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + TravelId = TravelId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("TravelId", TravelId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/TravelCompany/TracelCompanyFileImplement/Models/Travel.cs b/TravelCompany/TracelCompanyFileImplement/Models/Travel.cs new file mode 100644 index 0000000..a493ee4 --- /dev/null +++ b/TravelCompany/TracelCompanyFileImplement/Models/Travel.cs @@ -0,0 +1,95 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace TravelCompanyFileImplement.Models +{ + public class Travel : ITravelModel + { + public int Id { get; private set; } + public string TravelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _TravelComponents = null; + public Dictionary TravelComponents + { + get + { + if (_TravelComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _TravelComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _TravelComponents; + } + } + public static Travel? Create(TravelBindingModel model) + { + if (model == null) + { + return null; + } + return new Travel() + { + Id = model.Id, + TravelName = model.TravelName, + Price = model.Price, + Components = model.TravelComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + public static Travel? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Travel() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + TravelName = element.Element("TravelName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = + element.Element("TravelComponents")!.Elements("TravelComponent") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(TravelBindingModel model) + { + if (model == null) + { + return; + } + TravelName = model.TravelName; + Price = model.Price; + Components = model.TravelComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _TravelComponents = null; + } + public TravelViewModel GetViewModel => new() + { + Id = Id, + TravelName = TravelName, + Price = Price, + TravelComponents = TravelComponents + }; + public XElement GetXElement => new("Travel", + new XAttribute("Id", Id), + new XElement("TravelName", TravelName), + new XElement("Price", Price.ToString()), + new XElement("TravelComponents", Components.Select(x => new XElement("TravelComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))) + + .ToArray())); + + } +} diff --git a/TravelAgency/TravelAgencyCompanyContracts/TravelAgencyCompanyContracts.csproj b/TravelCompany/TracelCompanyFileImplement/TravelCompanyFileImplement.csproj similarity index 56% rename from TravelAgency/TravelAgencyCompanyContracts/TravelAgencyCompanyContracts.csproj rename to TravelCompany/TracelCompanyFileImplement/TravelCompanyFileImplement.csproj index e1f34a5..2cf28e6 100644 --- a/TravelAgency/TravelAgencyCompanyContracts/TravelAgencyCompanyContracts.csproj +++ b/TravelCompany/TracelCompanyFileImplement/TravelCompanyFileImplement.csproj @@ -7,7 +7,8 @@ - + + diff --git a/TravelCompany/TravelCompany.sln b/TravelCompany/TravelCompany.sln new file mode 100644 index 0000000..331475b --- /dev/null +++ b/TravelCompany/TravelCompany.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34024.191 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyView", "TravelCompany\TravelCompanyView.csproj", "{79A26973-2BA2-4D07-9217-3564BC783C40}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyDataModels", "TravelCompanyDataModels\TravelCompanyDataModels.csproj", "{1D4AB34B-67FC-47D8-AF5F-D049519B42A9}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyContracts", "TravelCompanyContracts\TravelCompanyContracts.csproj", "{F5360FD0-02FD-4549-956C-87BE43698D5B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyBusinessLogic", "TravelCompanyBusinessLogic\TravelCompanyBusinessLogic.csproj", "{DC7EB4DD-9023-416F-A718-A8596B80A587}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TravelCompanyDatabaseImplement", "TravelCompanyDatabaseImplement\TravelCompanyDatabaseImplement.csproj", "{CAFAE45A-519C-41A6-89EE-B62682DFDECF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {79A26973-2BA2-4D07-9217-3564BC783C40}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {79A26973-2BA2-4D07-9217-3564BC783C40}.Debug|Any CPU.Build.0 = Debug|Any CPU + {79A26973-2BA2-4D07-9217-3564BC783C40}.Release|Any CPU.ActiveCfg = Release|Any CPU + {79A26973-2BA2-4D07-9217-3564BC783C40}.Release|Any CPU.Build.0 = Release|Any CPU + {1D4AB34B-67FC-47D8-AF5F-D049519B42A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1D4AB34B-67FC-47D8-AF5F-D049519B42A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1D4AB34B-67FC-47D8-AF5F-D049519B42A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1D4AB34B-67FC-47D8-AF5F-D049519B42A9}.Release|Any CPU.Build.0 = Release|Any CPU + {F5360FD0-02FD-4549-956C-87BE43698D5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5360FD0-02FD-4549-956C-87BE43698D5B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5360FD0-02FD-4549-956C-87BE43698D5B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5360FD0-02FD-4549-956C-87BE43698D5B}.Release|Any CPU.Build.0 = Release|Any CPU + {DC7EB4DD-9023-416F-A718-A8596B80A587}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DC7EB4DD-9023-416F-A718-A8596B80A587}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DC7EB4DD-9023-416F-A718-A8596B80A587}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DC7EB4DD-9023-416F-A718-A8596B80A587}.Release|Any CPU.Build.0 = Release|Any CPU + {CAFAE45A-519C-41A6-89EE-B62682DFDECF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CAFAE45A-519C-41A6-89EE-B62682DFDECF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CAFAE45A-519C-41A6-89EE-B62682DFDECF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CAFAE45A-519C-41A6-89EE-B62682DFDECF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {C40092B7-794A-4F1D-8295-2B1D11C7EEC0} + EndGlobalSection +EndGlobal diff --git a/TravelCompany/TravelCompany/FormComponent.Designer.cs b/TravelCompany/TravelCompany/FormComponent.Designer.cs new file mode 100644 index 0000000..a67e2dd --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponent.Designer.cs @@ -0,0 +1,117 @@ +namespace TravelCompanyView +{ + partial class FormComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(170, 138); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(105, 29); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(296, 138); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(105, 29); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(19, 19); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 2; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(19, 86); + label2.Name = "label2"; + label2.Size = new Size(48, 20); + label2.TabIndex = 3; + label2.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(114, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 4; + // + // textBoxCost + // + textBoxCost.Location = new Point(114, 79); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(287, 27); + textBoxCost.TabIndex = 5; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(432, 180); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxCost; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormComponent.cs b/TravelCompany/TravelCompany/FormComponent.cs new file mode 100644 index 0000000..50489ad --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponent.cs @@ -0,0 +1,84 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace TravelCompanyView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TravelCompany/TravelCompany/FormComponent.resx b/TravelCompany/TravelCompany/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormComponents.Designer.cs b/TravelCompany/TravelCompany/FormComponents.Designer.cs new file mode 100644 index 0000000..0c3c4a2 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponents.Designer.cs @@ -0,0 +1,115 @@ +namespace TravelCompanyView +{ + partial class FormComponents + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(-2, -5); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(626, 460); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(651, 37); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(125, 44); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonRef + // + buttonRef.Location = new Point(651, 188); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(125, 44); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(651, 138); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(125, 44); + buttonDel.TabIndex = 4; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(651, 88); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(125, 44); + buttonUpd.TabIndex = 5; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonRef); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Список компонентов"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormComponents.cs b/TravelCompany/TravelCompany/FormComponents.cs new file mode 100644 index 0000000..8a7c957 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponents.cs @@ -0,0 +1,106 @@ +using Microsoft.Extensions.Logging; +using TravelCompanyContracts.BusinessLogicsContracts; +using Microsoft.VisualBasic.Logging; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.BindingModels; +using System.Windows.Forms; +using TravelCompany; + +namespace TravelCompanyView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormComponents_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); + try + { + if (!_logic.Delete(new ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/TravelCompany/TravelCompany/FormComponents.resx b/TravelCompany/TravelCompany/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/FormComponents.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs b/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..dfda113 --- /dev/null +++ b/TravelCompany/TravelCompany/FormCreateOrder.Designer.cs @@ -0,0 +1,143 @@ +namespace TravelCompanyView +{ + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + comboBoxTravel = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(11, 13); + label1.Name = "label1"; + label1.Size = new Size(170, 20); + label1.TabIndex = 0; + label1.Text = "Туристическая путевка:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(88, 52); + label2.Name = "label2"; + label2.Size = new Size(93, 20); + label2.TabIndex = 1; + label2.Text = "Количество:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(123, 99); + label3.Name = "label3"; + label3.Size = new Size(58, 20); + label3.TabIndex = 2; + label3.Text = "Сумма:"; + // + // comboBoxTravel + // + comboBoxTravel.FormattingEnabled = true; + comboBoxTravel.Location = new Point(191, 5); + comboBoxTravel.Name = "comboBoxTravel"; + comboBoxTravel.Size = new Size(278, 28); + comboBoxTravel.TabIndex = 3; + comboBoxTravel.SelectedIndexChanged += ComboBoxTravel_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(191, 49); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(278, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += textBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(191, 92); + textBoxSum.Name = "textBoxSum"; + textBoxSum.Size = new Size(278, 27); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(247, 148); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(375, 148); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(496, 200); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxTravel); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormCreateOrder"; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private ComboBox comboBoxTravel; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormCreateOrder.cs b/TravelCompany/TravelCompany/FormCreateOrder.cs new file mode 100644 index 0000000..04ecdc5 --- /dev/null +++ b/TravelCompany/TravelCompany/FormCreateOrder.cs @@ -0,0 +1,122 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; + +namespace TravelCompanyView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ITravelLogic _logicP; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ITravelLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + try + { + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxTravel.DisplayMember = "TravelName"; + comboBoxTravel.ValueMember = "Id"; + comboBoxTravel.DataSource = list; + comboBoxTravel.SelectedItem = null; + _logger.LogInformation("Загрузка изделий для заказа"); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + } + } + private void CalcSum() + { + if (comboBoxTravel.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxTravel.SelectedValue); + var Travel = _logicP.ReadElement(new TravelSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Travel?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void textBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void ComboBoxTravel_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxTravel.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + TravelId = Convert.ToInt32(comboBoxTravel.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TravelCompany/TravelCompany/FormCreateOrder.resx b/TravelCompany/TravelCompany/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/FormCreateOrder.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormMain.Designer.cs b/TravelCompany/TravelCompany/FormMain.Designer.cs new file mode 100644 index 0000000..631a5ac --- /dev/null +++ b/TravelCompany/TravelCompany/FormMain.Designer.cs @@ -0,0 +1,177 @@ +namespace TravelCompanyView +{ + partial class FormMain + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); + dataGridView = new DataGridView(); + toolStrip1 = new ToolStrip(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + туристическиеПутевкиToolStripMenuItem = new ToolStripMenuItem(); + buttonCreateeOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + toolStrip1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, 41); + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(937, 569); + dataGridView.TabIndex = 0; + // + // toolStrip1 + // + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(1197, 27); + toolStrip1.TabIndex = 1; + toolStrip1.Text = "toolStrip1"; + // + // toolStripDropDownButton1 + // + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, туристическиеПутевкиToolStripMenuItem }); + toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(108, 24); + toolStripDropDownButton1.Text = "Справочник"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(252, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + // + // туристическиеПутевкиToolStripMenuItem + // + туристическиеПутевкиToolStripMenuItem.Name = "туристическиеПутевкиToolStripMenuItem"; + туристическиеПутевкиToolStripMenuItem.Size = new Size(252, 26); + туристическиеПутевкиToolStripMenuItem.Text = "Туристические путевки"; + туристическиеПутевкиToolStripMenuItem.Click += путевкиToolStripMenuItem_Click; + // + // buttonCreateeOrder + // + buttonCreateeOrder.Location = new Point(993, 91); + buttonCreateeOrder.Name = "buttonCreateeOrder"; + buttonCreateeOrder.Size = new Size(155, 39); + buttonCreateeOrder.TabIndex = 2; + buttonCreateeOrder.Text = "Создать заказ"; + buttonCreateeOrder.UseVisualStyleBackColor = true; + buttonCreateeOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(993, 136); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(155, 53); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(993, 195); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(155, 39); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(993, 240); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(155, 39); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(993, 285); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(155, 39); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1197, 611); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateeOrder); + Controls.Add(toolStrip1); + Controls.Add(dataGridView); + Name = "FormMain"; + Text = "Туристическая фирма"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DataGridView dataGridView; + private ToolStrip toolStrip1; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem туристическиеПутевкиToolStripMenuItem; + private Button buttonCreateeOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormMain.cs b/TravelCompany/TravelCompany/FormMain.cs new file mode 100644 index 0000000..914dcf4 --- /dev/null +++ b/TravelCompany/TravelCompany/FormMain.cs @@ -0,0 +1,157 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TravelCompany; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; + +namespace TravelCompanyView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) + { + InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + LoadData(); + } + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["TravelId"].Visible = false; + dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + + _logger.LogInformation("Загрузка заказов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + } + } + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + private void путевкиToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravels)); + + if (service is FormTravels form) + { + form.ShowDialog(); + } + } + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel + { + Id = id, + }); + if (!operationResult) + { + throw new Exception("Ошибка передачи заказа в работу"); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка отметки о готовности заказа"); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel + { + Id = id + }); + if (!operationResult) + { + throw new Exception("Ошибка отметки о выдачи заказа"); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/TravelCompany/TravelCompany/FormMain.resx b/TravelCompany/TravelCompany/FormMain.resx new file mode 100644 index 0000000..dbd8207 --- /dev/null +++ b/TravelCompany/TravelCompany/FormMain.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + + + + iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAEKSURBVEhL3ZG9DsFQHMXvczDZvIOtXsHObuhqkViI3Quw + 6CYmNoMYJJ0NBiFFIoIytOuf0+TeXP3yde+iyS+3OcP53Z4y3/dJJ4HAsiwyTVMp6BQCBIZhKAWdEcHV + vSlBmeB82NFy1KLluEWOPRC5MoHdMWhazwi4RJlALgf4EuT6BI+5kCsTrGddUY658E+QvyXYHq9UnRyC + U87f4aUApcXhnrI9Jzg/laQKFntXlHM+lSQK5psL5fvbp/JvJLGCQqmSWM5JkiCT84igXGtSrruKLQ0T + luAdmZxHBG37FFuWBC/j5XKOmX8WAH7rcI6ZMffPgjQwN2bXJgDo/COBTpjneQ2dML0PY3cISreGe8HM + qgAAAABJRU5ErkJggg== + + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravel.Designer.cs b/TravelCompany/TravelCompany/FormTravel.Designer.cs new file mode 100644 index 0000000..bf1a6b9 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravel.Designer.cs @@ -0,0 +1,234 @@ +using System.Windows.Forms; + +namespace TravelCompanyView +{ + partial class FormTravel + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + textBoxPrice = new TextBox(); + textBoxName = new TextBox(); + label2 = new Label(); + label1 = new Label(); + groupBox1 = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + Number = new DataGridViewTextBoxColumn(); + Component = new DataGridViewTextBoxColumn(); + Count = new DataGridViewTextBoxColumn(); + buttonCancel = new Button(); + buttonSave = new Button(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // textBoxPrice + // + textBoxPrice.Location = new Point(123, 45); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(169, 27); + textBoxPrice.TabIndex = 9; + // + // textBoxName + // + textBoxName.Location = new Point(123, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 8; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(27, 52); + label2.Name = "label2"; + label2.Size = new Size(86, 20); + label2.TabIndex = 7; + label2.Text = "Стоимость:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(27, 19); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 6; + label1.Text = "Название:"; + // + // groupBox1 + // + groupBox1.Controls.Add(buttonRef); + groupBox1.Controls.Add(buttonDel); + groupBox1.Controls.Add(buttonUpd); + groupBox1.Controls.Add(buttonAdd); + groupBox1.Controls.Add(dataGridView); + groupBox1.Location = new Point(11, 93); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(743, 433); + groupBox1.TabIndex = 10; + groupBox1.TabStop = false; + groupBox1.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(615, 224); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(111, 37); + buttonRef.TabIndex = 7; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(615, 172); + buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(111, 37); + buttonDel.TabIndex = 6; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(615, 113); + buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(111, 37); + buttonUpd.TabIndex = 5; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(615, 52); + buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(111, 37); + buttonAdd.TabIndex = 4; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { Number, Component, Count }); + dataGridView.Location = new Point(0, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(598, 407); + dataGridView.TabIndex = 0; + // + // Number + // + Number.HeaderText = "Номер"; + Number.MinimumWidth = 6; + Number.Name = "Number"; + Number.Width = 60; + // + // Component + // + Component.HeaderText = "Компонент"; + Component.MinimumWidth = 6; + Component.Name = "Component"; + Component.Width = 125; + // + // Count + // + Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + Count.HeaderText = "Количество"; + Count.MinimumWidth = 6; + Count.Name = "Count"; + // + // buttonCancel + // + buttonCancel.Location = new Point(617, 563); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(130, 37); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(462, 563); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(130, 37); + buttonSave.TabIndex = 12; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormTravel + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(759, 612); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBox1); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormTravel"; + Text = "Туристическая путевка"; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxPrice; + private TextBox textBoxName; + private Label label2; + private Label label1; + private GroupBox groupBox1; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonCancel; + private Button buttonSave; + private DataGridViewTextBoxColumn Number; + private DataGridViewTextBoxColumn Component; + private DataGridViewTextBoxColumn Count; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravel.cs b/TravelCompany/TravelCompany/FormTravel.cs new file mode 100644 index 0000000..2bd7c7d --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravel.cs @@ -0,0 +1,206 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TravelCompany; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyDataModels.Models; + +namespace TravelCompanyView +{ + public partial class FormTravel : Form + { + private readonly ILogger _logger; + private readonly ITravelLogic _logic; + private int? _id; + private Dictionary _productComponents; + public int Id { set { _id = value; } } + public FormTravel(ILogger logger, ITravelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _productComponents = new Dictionary(); + } + private void FormTravel_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new TravelSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.TravelName; + textBoxPrice.Text = view.Price.ToString(); + _productComponents = view.TravelComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_productComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _productComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); + if (service is FormTravelComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + if (_productComponents.ContainsKey(form.Id)) + { + _productComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); + } + LoadData(); + } + } + } + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravelComponent)); + if (service is FormTravelComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _productComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _productComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_productComponents == null || _productComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new TravelBindingModel + { + Id = _id ?? 0, + TravelName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + TravelComponents = _productComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _productComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/TravelCompany/TravelCompany/FormTravel.resx b/TravelCompany/TravelCompany/FormTravel.resx new file mode 100644 index 0000000..5052aba --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravel.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravelComponent.Designer.cs b/TravelCompany/TravelCompany/FormTravelComponent.Designer.cs new file mode 100644 index 0000000..7fc690b --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravelComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace TravelCompanyView +{ + partial class FormTravelComponent + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonSave = new Button(); + buttonCancel = new Button(); + label2 = new Label(); + label1 = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(198, 104); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(298, 104); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(12, 61); + label2.Name = "label2"; + label2.Size = new Size(93, 20); + label2.TabIndex = 5; + label2.Text = "Количество:"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 21); + label1.Name = "label1"; + label1.Size = new Size(91, 20); + label1.TabIndex = 4; + label1.Text = "Компонент:"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(120, 13); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(272, 28); + comboBoxComponent.TabIndex = 6; + // + // textBoxCount + // + textBoxCount.Location = new Point(120, 54); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(272, 27); + textBoxCount.TabIndex = 7; + // + // FormTravelComponentcs + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 146); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormTravelComponentcs"; + Text = "Компонент туристической путевки"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label label2; + private Label label1; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravelComponent.cs b/TravelCompany/TravelCompany/FormTravelComponent.cs new file mode 100644 index 0000000..9abfe02 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravelComponent.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; + +namespace TravelCompanyView +{ + public partial class FormTravelComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } + + public FormTravelComponent(IComponentLogic logic) + { + InitializeComponent(); + + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TravelCompany/TravelCompany/FormTravelComponent.resx b/TravelCompany/TravelCompany/FormTravelComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravelComponent.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravels.Designer.cs b/TravelCompany/TravelCompany/FormTravels.Designer.cs new file mode 100644 index 0000000..78d7579 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravels.Designer.cs @@ -0,0 +1,113 @@ +namespace TravelCompanyView +{ + partial class FormTravels + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(740, 566); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(766, 72); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(156, 35); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(766, 113); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(156, 35); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(766, 154); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(156, 35); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(766, 195); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(156, 35); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormTravels + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(947, 567); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormTravels"; + Text = "Список туристических путевок"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/FormTravels.cs b/TravelCompany/TravelCompany/FormTravels.cs new file mode 100644 index 0000000..889cb0d --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravels.cs @@ -0,0 +1,116 @@ +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TravelCompany; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; + +namespace TravelCompanyView +{ + public partial class FormTravels : Form + { + private readonly ILogger _logger; + private readonly ITravelLogic _logic; + public FormTravels(ILogger logger, ITravelLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + LoadData(); + } + + private void FormTravels_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["TravelComponents"].Visible = false; + dataGridView.Columns["TravelName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка путёвок"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); + if (service is FormTravel form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTravel)); + if (service is FormTravel form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление путёвок"); + try + { + if (!_logic.Delete(new TravelBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления путевки"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/TravelCompany/TravelCompany/FormTravels.resx b/TravelCompany/TravelCompany/FormTravels.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TravelCompany/TravelCompany/FormTravels.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/Program.cs b/TravelCompany/TravelCompany/Program.cs new file mode 100644 index 0000000..385ddd8 --- /dev/null +++ b/TravelCompany/TravelCompany/Program.cs @@ -0,0 +1,53 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using TravelCompanyBusinessLogic.BusinessLogic; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyDatabaseImplement.Implements; +using TravelCompanyView; + +namespace TravelCompany +{ + internal static class Program + { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompany/Properties/Resources.Designer.cs b/TravelCompany/TravelCompany/Properties/Resources.Designer.cs new file mode 100644 index 0000000..14dbbc1 --- /dev/null +++ b/TravelCompany/TravelCompany/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace TravelCompanyView.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TravelCompanyView.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/TravelAgency/TravelAgencyView/Form1.resx b/TravelCompany/TravelCompany/Properties/Resources.resx similarity index 100% rename from TravelAgency/TravelAgencyView/Form1.resx rename to TravelCompany/TravelCompany/Properties/Resources.resx diff --git a/TravelCompany/TravelCompany/TravelCompanyView.csproj b/TravelCompany/TravelCompany/TravelCompanyView.csproj new file mode 100644 index 0000000..25d2c3a --- /dev/null +++ b/TravelCompany/TravelCompany/TravelCompanyView.csproj @@ -0,0 +1,47 @@ + + + + WinExe + net6.0-windows + enable + true + enable + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/TravelCompany/TravelCompany/nlog.config b/TravelCompany/TravelCompany/nlog.config new file mode 100644 index 0000000..af70d20 --- /dev/null +++ b/TravelCompany/TravelCompany/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ComponentLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ComponentLogic.cs new file mode 100644 index 0000000..c3112f3 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -0,0 +1,113 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + public class ComponentLogic : IComponentLogic + { + private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; + public ComponentLogic(ILogger logger, IComponentStorage + componentStorage) + { + _logger = logger; + _componentStorage = componentStorage; + } + public List? ReadList(ComponentSearchModel? model) + { + _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{Id}", model?.ComponentName, model?.Id); + var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public ComponentViewModel? ReadElement(ComponentSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{Id}", model.ComponentName, model.Id); + var element = _componentStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ComponentBindingModel model) + { + CheckModel(model); + if (_componentStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ComponentBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_componentStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(ComponentBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ComponentName)) + { + throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName)); + } + if (model.Cost <= 0) + { + throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); + } + _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{Cost}. Id: {Id}", model.ComponentName, model.Cost, model.Id); + var element = _componentStorage.GetElement(new ComponentSearchModel + { + ComponentName = model.ComponentName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Компонент с таким названием уже есть"); + } + } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs new file mode 100644 index 0000000..e7c1295 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/OrderLogic.cs @@ -0,0 +1,141 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Enums; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + public class OrderLogic : IOrderLogic + { + //Класс с логикой для заказов будет отвечать за получение списка заказов, + //создания заказа и смены его статусов. Следует учитывать, что у заказа можно + //менять статус на новый, если его текущий статус предшествует новому + + private readonly ILogger _logger; + private readonly IOrderStorage _orderStorage; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage) + { + _logger = logger; + _orderStorage = orderStorage; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + + if (model.Status != OrderStatus.Неизвестен) + return false; + model.Status = OrderStatus.Принят; + + if (_orderStorage.Insert(model) == null) + { + model.Status = OrderStatus.Неизвестен; + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ToNextStatus(model, OrderStatus.Выдан); + } + + public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) + { + CheckModel(model, false); + var element = _orderStorage.GetElement(new OrderSearchModel() + { + Id = model.Id + }); + if (element == null) + { + throw new ArgumentNullException(nameof(element)); + } + + model.TravelId = element.TravelId; + model.DateCreate = element.DateCreate; + model.DateImplement = element.DateImplement; + model.Status = element.Status; + model.Count = element.Count; + model.Sum = element.Sum; + + if (model.Status != orderStatus - 1) + { + _logger.LogWarning("Status update to " + orderStatus + " operation failed"); + return false; + } + model.Status = orderStatus; + + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + + if (_orderStorage.Update(model) == null) + { + model.Status--; + _logger.LogWarning("Changing status operation faled"); + return false; + } + return true; + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); + } + if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) + { + throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} должна быть позже даты его создания {model.DateCreate}"); + } + _logger.LogInformation("Travel. TravelId:{TravelId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.TravelId, model.Count, model.Sum, model.Id); + } + } +} diff --git a/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs new file mode 100644 index 0000000..1e5348b --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/BusinessLogic/TravelLogic.cs @@ -0,0 +1,118 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.BusinessLogicsContracts; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyBusinessLogic.BusinessLogic +{ + public class TravelLogic : TravelCompanyContracts.BusinessLogicsContracts.ITravelLogic + { + private readonly ILogger _logger; + private readonly ITravelStorage _TravelStorage; + public TravelLogic(ILogger logger, ITravelStorage + TravelStorage) + { + _logger = logger; + _TravelStorage = TravelStorage; + } + public List? ReadList(TravelSearchModel? model) + { + _logger.LogInformation("ReadList. TravelName:{TravelName}.Id:{Id}", model?.TravelName, model?.Id); + var list = model == null ? _TravelStorage.GetFullList() : _TravelStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count:{Count}", list.Count); + return list; + } + + public TravelViewModel? ReadElement(TravelSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. TravelName:{TravelName}.Id:{Id}", model.TravelName, model.Id); + var element = _TravelStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } + + public bool Create(TravelBindingModel model) + { + CheckModel(model); + if (_TravelStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(TravelBindingModel model) + { + CheckModel(model); + if (_TravelStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(TravelBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id:{Id}", model.Id); + if (_TravelStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + private void CheckModel(TravelBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.TravelName)) + { + throw new ArgumentNullException("Нет названия изделия", nameof(model.TravelName)); + } + if (model.Price <= 0) + { + throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + } + _logger.LogInformation("Travel. TravelName:{TravelName}.Price:{Cost}. Id: {Id}", model.TravelName, model.Price, model.Id); + var element = _TravelStorage.GetElement(new TravelSearchModel + { + TravelName = model.TravelName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Изделие с таким названием уже есть"); + } + } + } +} diff --git a/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj b/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj new file mode 100644 index 0000000..347e330 --- /dev/null +++ b/TravelCompany/TravelCompanyBusinessLogic/TravelCompanyBusinessLogic.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/ComponentBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/ComponentBindingModel.cs new file mode 100644 index 0000000..ee3837f --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/ComponentBindingModel.cs @@ -0,0 +1,16 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BindingModels +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs new file mode 100644 index 0000000..20802d2 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/OrderBindingModel.cs @@ -0,0 +1,21 @@ +using TravelCompanyDataModels.Enums; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BindingModels +{ + public class OrderBindingModel : IOrderModel + { + public int Id { get; set; } + public int TravelId { get; set; } + public int Count { get; set; } + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs b/TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs new file mode 100644 index 0000000..49993f0 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BindingModels/TravelBindingModel.cs @@ -0,0 +1,17 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BindingModels +{ + public class TravelBindingModel : ITravelModel + { + public int Id { get; set; } + public string TravelName { get; set; } = string.Empty; + public double Price { get; set; } + public Dictionary TravelComponents { get; set; } = new(); + } +} diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/IComponentLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/IComponentLogic.cs new file mode 100644 index 0000000..f7af27c --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/IComponentLogic.cs @@ -0,0 +1,21 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BusinessLogicsContracts +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/IOrderLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/IOrderLogic.cs new file mode 100644 index 0000000..03a4beb --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/IOrderLogic.cs @@ -0,0 +1,30 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BusinessLogicsContracts +{ + public interface IOrderLogic + { + List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); + /// + /// Готов + /// + /// + /// + bool FinishOrder(OrderBindingModel model); + /// + /// Доставлен + /// + /// + /// + bool DeliveryOrder(OrderBindingModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/ITravelLogic.cs b/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/ITravelLogic.cs new file mode 100644 index 0000000..d499914 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/BusinessLogicContracts/ITravelLogic.cs @@ -0,0 +1,20 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.BusinessLogicsContracts +{ + public interface ITravelLogic + { + List? ReadList(TravelSearchModel? model); + TravelViewModel? ReadElement(TravelSearchModel model); + bool Create(TravelBindingModel model); + bool Update(TravelBindingModel model); + bool Delete(TravelBindingModel model); + } +} diff --git a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/MedicalInsuranceSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/ComponentSearchModel.cs similarity index 55% rename from TravelAgency/TravelAgencyCompanyContracts/SearchModel/MedicalInsuranceSearchModel.cs rename to TravelCompany/TravelCompanyContracts/SearchModels/ComponentSearchModel.cs index 05ca636..9d6102f 100644 --- a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/MedicalInsuranceSearchModel.cs +++ b/TravelCompany/TravelCompanyContracts/SearchModels/ComponentSearchModel.cs @@ -4,11 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelAgencyCompanyContracts.SearchModel +namespace TravelCompanyContracts.SearchModels { - public class MedicalInsuranceSearchModel + public class ComponentSearchModel { public int? Id { get; set; } - public string? Type { get; set; } + public string? ComponentName { get; set; } } } diff --git a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/TransportSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/OrderSearchModel.cs similarity index 56% rename from TravelAgency/TravelAgencyCompanyContracts/SearchModel/TransportSearchModel.cs rename to TravelCompany/TravelCompanyContracts/SearchModels/OrderSearchModel.cs index e79e865..d2c7549 100644 --- a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/TransportSearchModel.cs +++ b/TravelCompany/TravelCompanyContracts/SearchModels/OrderSearchModel.cs @@ -4,11 +4,10 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelAgencyCompanyContracts.SearchModel +namespace TravelCompanyContracts.SearchModels { - public class TransportSearchModel + public class OrderSearchModel { public int? Id { get; set; } - public string? Type { get; set; } } } diff --git a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/HotelSearchModel.cs b/TravelCompany/TravelCompanyContracts/SearchModels/TravelSearchModel.cs similarity index 50% rename from TravelAgency/TravelAgencyCompanyContracts/SearchModel/HotelSearchModel.cs rename to TravelCompany/TravelCompanyContracts/SearchModels/TravelSearchModel.cs index eb2789b..6b13d69 100644 --- a/TravelAgency/TravelAgencyCompanyContracts/SearchModel/HotelSearchModel.cs +++ b/TravelCompany/TravelCompanyContracts/SearchModels/TravelSearchModel.cs @@ -4,12 +4,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace TravelAgencyCompanyContracts.SearchModel +namespace TravelCompanyContracts.SearchModels { - public class HotelSearchModel + public class TravelSearchModel { public int? Id { get; set; } - public string? Name { get;set; } - public int? NumberStars { get; set; } + public string? TravelName { get; set; } } } diff --git a/TravelCompany/TravelCompanyContracts/StoragesContracts/IComponentStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IComponentStorage.cs new file mode 100644 index 0000000..617243a --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IComponentStorage.cs @@ -0,0 +1,22 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.StoragesContracts +{ + public interface IComponentStorage + { + List GetFullList(); + List GetFilteredList(ComponentSearchModel model); + ComponentViewModel? GetElement(ComponentSearchModel model); + ComponentViewModel? Insert(ComponentBindingModel model); + ComponentViewModel? Update(ComponentBindingModel model); + ComponentViewModel? Delete(ComponentBindingModel model); + + } +} diff --git a/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs new file mode 100644 index 0000000..b4d8462 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/IOrderStorage.cs @@ -0,0 +1,21 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.StoragesContracts +{ + public interface IOrderStorage + { + List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs b/TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs new file mode 100644 index 0000000..b85d24b --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/StoragesContracts/ITravelStorage.cs @@ -0,0 +1,21 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.StoragesContracts +{ + public interface ITravelStorage + { + List GetFullList(); + List GetFilteredList(TravelSearchModel model); + TravelViewModel? GetElement(TravelSearchModel model); + TravelViewModel? Insert(TravelBindingModel model); + TravelViewModel? Update(TravelBindingModel model); + TravelViewModel? Delete(TravelBindingModel model); + } +} diff --git a/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj new file mode 100644 index 0000000..b3bbb9d --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/TravelCompanyContracts.csproj @@ -0,0 +1,24 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs new file mode 100644 index 0000000..f865958 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/ViewModels/ComponentViewModel.cs @@ -0,0 +1,19 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.ViewModels +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs new file mode 100644 index 0000000..022bc49 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/ViewModels/OrderViewModel.cs @@ -0,0 +1,29 @@ +using TravelCompanyDataModels.Enums; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.ViewModels +{ + public class OrderViewModel + { + [DisplayName("Номер")] + public int Id { get; set; } + public int TravelId { get; set; } + [DisplayName("Изделие")] + public string TravelName { get; set; } = string.Empty; + [DisplayName("Количество")] + public int Count { get; set; } + [DisplayName("Сумма")] + public double Sum { get; set; } + [DisplayName("Статус")] + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] + public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] + public DateTime? DateImplement { get; set; } + } +} diff --git a/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs new file mode 100644 index 0000000..d8c1e55 --- /dev/null +++ b/TravelCompany/TravelCompanyContracts/ViewModels/TravelViewModel.cs @@ -0,0 +1,21 @@ +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyContracts.ViewModels +{ + public class TravelViewModel : ITravelModel + { + public int Id { get; set; } + [DisplayName("Название изделия")] + public string TravelName { get; set; } + [DisplayName("Цена")] + public double Price { get; set; } + public Dictionary TravelComponents { get; set; } = new(); + + } +} diff --git a/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs b/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs new file mode 100644 index 0000000..0e8a2ca --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Enums/OrderStatus.cs @@ -0,0 +1,11 @@ +namespace TravelCompanyDataModels.Enums +{ + public enum OrderStatus + { + Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, + Выдан = 3, + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/IId.cs b/TravelCompany/TravelCompanyDataModels/IId.cs new file mode 100644 index 0000000..cdccdc8 --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/TravelCompany/TravelCompanyDataModels/Models/IComponentModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IComponentModel.cs new file mode 100644 index 0000000..946afa3 --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Models/IComponentModel.cs @@ -0,0 +1,8 @@ +namespace TravelCompanyDataModels.Models +{ + public interface IComponentModel : IId + { + string ComponentName { get; } + double Cost { get; } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs b/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs new file mode 100644 index 0000000..22a55af --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Models/IOrderModel.cs @@ -0,0 +1,14 @@ +using TravelCompanyDataModels.Enums; + +namespace TravelCompanyDataModels.Models +{ + public interface IOrderModel : IId + { + int TravelId { get; } + int Count { get; } + double Sum { get; } + OrderStatus Status { get; } + DateTime DateCreate { get; } + DateTime? DateImplement { get; } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs b/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs new file mode 100644 index 0000000..101f593 --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/Models/ITravelModel.cs @@ -0,0 +1,9 @@ +namespace TravelCompanyDataModels.Models +{ + public interface ITravelModel : IId + { + string TravelName { get; } + double Price { get; } + Dictionary TravelComponents { get; } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj new file mode 100644 index 0000000..37b0ba4 --- /dev/null +++ b/TravelCompany/TravelCompanyDataModels/TravelCompanyDataModels.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/ComponentStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..91e3725 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/ComponentStorage.cs @@ -0,0 +1,91 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDatabaseImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + public List GetFullList() + { + using var context = new TravelCompanyDataBase(); + return context.Components + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(ComponentSearchModel + model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + using var context = new TravelCompanyDataBase(); + return context.Components + .Where(x => x.ComponentName.Contains(model.ComponentName)) + .Select(x => x.GetViewModel) + .ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + using var context = new TravelCompanyDataBase(); + return context.Components + .FirstOrDefault(x => + (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == + model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + using var context = new TravelCompanyDataBase(); + context.Components.Add(newComponent); + context.SaveChanges(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + using var context = new TravelCompanyDataBase(); + var component = context.Components.FirstOrDefault(x => x.Id == + model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + using var context = new TravelCompanyDataBase(); + var element = context.Components.FirstOrDefault(rec => rec.Id == + model.Id); + if (element != null) + { + context.Components.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } + + +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/OrderStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..78cc735 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/OrderStorage.cs @@ -0,0 +1,104 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace TravelCompanyDatabaseImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + + using var context = new TravelCompanyDataBase(); + + return context.Orders.Include(x => x.Travel). + FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id) + ?.GetViewModel; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + + using var context = new TravelCompanyDataBase(); + + return context.Orders + .Include(x => x.Travel) + .Where(x => x.Id == model.Id) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new TravelCompanyDataBase(); + + return context.Orders.Include(x => x.Travel) + .Select(x => x.GetViewModel).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + var newOrder = Order.Create(model); + + if (newOrder == null) + { + return null; + } + + using var context = new TravelCompanyDataBase(); + context.Orders.Add(newOrder); + context.SaveChanges(); + + return context.Orders.Include(x => x.Travel) + .FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new TravelCompanyDataBase(); + var order = context.Orders.FirstOrDefault(x => x.Id == model.Id); + + if (order == null) + { + return null; + } + + order.Update(model); + context.SaveChanges(); + + return context.Orders.Include(x => x.Travel).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new TravelCompanyDataBase(); + var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id); + + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + + return element.GetViewModel; + } + + return null; + } + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Implements/TravelStorage.cs b/TravelCompany/TravelCompanyDatabaseImplement/Implements/TravelStorage.cs new file mode 100644 index 0000000..20dd6d5 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Implements/TravelStorage.cs @@ -0,0 +1,110 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDatabaseImplement.Implements +{ + public class TravelStorage : ITravelStorage + { + public List GetFullList() + { + using var context = new TravelCompanyDataBase(); + return context.Travels + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(TravelSearchModel model) + { + if (string.IsNullOrEmpty(model.TravelName)) + { + return new(); + } + using var context = new TravelCompanyDataBase(); + return context.Travels.Include(x => x.Components) + .ThenInclude(x => x.Component) + .Where(x => x.TravelName.Contains(model.TravelName)) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public TravelViewModel? GetElement(TravelSearchModel model) + { + if (string.IsNullOrEmpty(model.TravelName) && + !model.Id.HasValue) + { + return null; + } + using var context = new TravelCompanyDataBase(); + return context.Travels + .Include(x => x.Components) + .ThenInclude(x => x.Component) + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.TravelName) && + x.TravelName == model.TravelName) || + (model.Id.HasValue && x.Id == + model.Id)) + ?.GetViewModel; + } + public TravelViewModel? Insert(TravelBindingModel model) + { + using var context = new TravelCompanyDataBase(); + var newTravel = Travel.Create(context, model); + if (newTravel == null) + { + return null; + } + context.Travels.Add(newTravel); + context.SaveChanges(); + return newTravel.GetViewModel; + } + public TravelViewModel? Update(TravelBindingModel model) + { + using var context = new TravelCompanyDataBase(); + using var transaction = context.Database.BeginTransaction(); + try + { + var Travel = context.Travels.FirstOrDefault(rec => + rec.Id == model.Id); + if (Travel == null) + { + return null; + } + Travel.Update(model); + context.SaveChanges(); + Travel.UpdateComponents(context, model); + transaction.Commit(); + return Travel.GetViewModel; + } + catch + { + transaction.Rollback(); + throw; + } + } + public TravelViewModel? Delete(TravelBindingModel model) + { + using var context = new TravelCompanyDataBase(); + var element = context.Travels + .Include(x => x.Components) + .FirstOrDefault(rec => rec.Id == model.Id); + if (element != null) + { + context.Travels.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + } +} + diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503102918_InitialCreate.Designer.cs b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503102918_InitialCreate.Designer.cs new file mode 100644 index 0000000..90bdac6 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503102918_InitialCreate.Designer.cs @@ -0,0 +1,171 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TravelCompanyDatabaseImplement; + +#nullable disable + +namespace TravelCompanyDatabaseImplement.Migrations +{ + [DbContext(typeof(TravelCompanyDataBase))] + [Migration("20240503102918_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("TravelId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TravelId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Travel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("TravelName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Travels"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TravelComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("TravelId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("TravelId"); + + b.ToTable("TravelComponents"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Order", b => + { + b.HasOne("TravelCompanyDatabaseImplement.Models.Travel", "Travel") + .WithMany("Orders") + .HasForeignKey("TravelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Travel"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TravelComponent", b => + { + b.HasOne("TravelCompanyDatabaseImplement.Models.Component", "Component") + .WithMany("TravelComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("TravelCompanyDatabaseImplement.Models.Travel", "Travel") + .WithMany("Components") + .HasForeignKey("TravelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Travel"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Component", b => + { + b.Navigation("TravelComponents"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Travel", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503102918_InitialCreate.cs b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503102918_InitialCreate.cs new file mode 100644 index 0000000..9b1d5c0 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/20240503102918_InitialCreate.cs @@ -0,0 +1,125 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace TravelCompanyDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Components", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ComponentName = table.Column(type: "nvarchar(max)", nullable: false), + Cost = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Components", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Travels", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TravelName = table.Column(type: "nvarchar(max)", nullable: false), + Price = table.Column(type: "float", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Travels", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Orders", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Count = table.Column(type: "int", nullable: false), + Sum = table.Column(type: "float", nullable: false), + Status = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateImplement = table.Column(type: "datetime2", nullable: true), + TravelId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Orders", x => x.Id); + table.ForeignKey( + name: "FK_Orders_Travels_TravelId", + column: x => x.TravelId, + principalTable: "Travels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "TravelComponents", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + TravelId = table.Column(type: "int", nullable: false), + ComponentId = table.Column(type: "int", nullable: false), + Count = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_TravelComponents", x => x.Id); + table.ForeignKey( + name: "FK_TravelComponents_Components_ComponentId", + column: x => x.ComponentId, + principalTable: "Components", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_TravelComponents_Travels_TravelId", + column: x => x.TravelId, + principalTable: "Travels", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Orders_TravelId", + table: "Orders", + column: "TravelId"); + + migrationBuilder.CreateIndex( + name: "IX_TravelComponents_ComponentId", + table: "TravelComponents", + column: "ComponentId"); + + migrationBuilder.CreateIndex( + name: "IX_TravelComponents_TravelId", + table: "TravelComponents", + column: "TravelId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Orders"); + + migrationBuilder.DropTable( + name: "TravelComponents"); + + migrationBuilder.DropTable( + name: "Components"); + + migrationBuilder.DropTable( + name: "Travels"); + } + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Migrations/TravelCompanyDataBaseModelSnapshot.cs b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/TravelCompanyDataBaseModelSnapshot.cs new file mode 100644 index 0000000..4f7139e --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Migrations/TravelCompanyDataBaseModelSnapshot.cs @@ -0,0 +1,168 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using TravelCompanyDatabaseImplement; + +#nullable disable + +namespace TravelCompanyDatabaseImplement.Migrations +{ + [DbContext(typeof(TravelCompanyDataBase))] + partial class TravelCompanyDataBaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.17") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.Property("TravelId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("TravelId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Travel", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("Price") + .HasColumnType("float"); + + b.Property("TravelName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Travels"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TravelComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("TravelId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("TravelId"); + + b.ToTable("TravelComponents"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Order", b => + { + b.HasOne("TravelCompanyDatabaseImplement.Models.Travel", "Travel") + .WithMany("Orders") + .HasForeignKey("TravelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Travel"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.TravelComponent", b => + { + b.HasOne("TravelCompanyDatabaseImplement.Models.Component", "Component") + .WithMany("TravelComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("TravelCompanyDatabaseImplement.Models.Travel", "Travel") + .WithMany("Components") + .HasForeignKey("TravelId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Travel"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Component", b => + { + b.Navigation("TravelComponents"); + }); + + modelBuilder.Entity("TravelCompanyDatabaseImplement.Models.Travel", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Component.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Component.cs new file mode 100644 index 0000000..81fc7a6 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Component.cs @@ -0,0 +1,63 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDatabaseImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + [Required] + public string ComponentName { get; private set; } = string.Empty; + [Required] + public double Cost { get; set; } + [ForeignKey("ComponentId")] + public virtual List TravelComponents { get; set; } = + new(); + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component Create(ComponentViewModel model) + { + return new Component + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} + diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs new file mode 100644 index 0000000..7683d9d --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Order.cs @@ -0,0 +1,71 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Enums; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDatabaseImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + [Required] + public int Count { get; private set; } + [Required] + public double Sum { get; private set; } + [Required] + public OrderStatus Status { get; private set; } + [Required] + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + [Required] + public int TravelId { get; private set; } + public virtual Travel Travel { get; set; } + + public static Order? Create(OrderBindingModel model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + TravelId = model.TravelId, + }; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + TravelId = TravelId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + Id = Id, + TravelName = Travel.TravelName + }; + + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs new file mode 100644 index 0000000..88ffaa3 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/Travel.cs @@ -0,0 +1,103 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDatabaseImplement.Models +{ + public class Travel : ITravelModel + { + public int Id { get; set; } + [Required] + public string TravelName { get; set; } = string.Empty; + [Required] + public double Price { get; set; } + private Dictionary? _TravelComponents = + null; + [NotMapped] + public Dictionary TravelComponents + { + get + { + if (_TravelComponents == null) + { + _TravelComponents = Components + .ToDictionary(recPC => recPC.ComponentId, recPC => + (recPC.Component as IComponentModel, recPC.Count)); + } + return _TravelComponents; + } + } + [ForeignKey("TravelId")] + public virtual List Components { get; set; } = new(); + [ForeignKey("TravelId")] + public virtual List Orders { get; set; } = new(); + public static Travel Create(TravelCompanyDataBase context, + TravelBindingModel model) + { + return new Travel() + { + Id = model.Id, + TravelName = model.TravelName, + Price = model.Price, + Components = model.TravelComponents.Select(x => new + TravelComponent + { + Component = context.Components.First(y => y.Id == x.Key), + Count = x.Value.Item2 + }).ToList() + }; + } + public void Update(TravelBindingModel model) + { + TravelName = model.TravelName; + Price = model.Price; + } + public TravelViewModel GetViewModel => new() + { + Id = Id, + TravelName = TravelName, + Price = Price, + TravelComponents = TravelComponents + }; + public void UpdateComponents(TravelCompanyDataBase context, + TravelBindingModel model) + { + var TravelComponents = context.TravelComponents.Where(rec => + rec.TravelId == model.Id).ToList(); + if (TravelComponents != null && TravelComponents.Count > 0) + { + context.TravelComponents.RemoveRange(TravelComponents.Where(rec +=> !model.TravelComponents.ContainsKey(rec.ComponentId))); + + context.SaveChanges(); + foreach (var updateComponent in TravelComponents) + { + updateComponent.Count = + model.TravelComponents[updateComponent.ComponentId].Item2; + model.TravelComponents.Remove(updateComponent.ComponentId); + } + context.SaveChanges(); + } + var Travel = context.Travels.First(x => x.Id == Id); + foreach (var pc in model.TravelComponents) + { + context.TravelComponents.Add(new TravelComponent + { + Travel = Travel, + Component = context.Components.First(x => x.Id == pc.Key), + Count = pc.Value.Item2 + }); + context.SaveChanges(); + } + _TravelComponents = null; + } + } +} + diff --git a/TravelCompany/TravelCompanyDatabaseImplement/Models/TravelComponent.cs b/TravelCompany/TravelCompanyDatabaseImplement/Models/TravelComponent.cs new file mode 100644 index 0000000..c84efb4 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/Models/TravelComponent.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyDatabaseImplement.Models +{ + public class TravelComponent + { + public int Id { get; set; } + [Required] + public int TravelId { get; set; } + [Required] + public int ComponentId { get; set; } + [Required] + public int Count { get; set; } + public virtual Component Component { get; set; } = new(); + public virtual Travel Travel { get; set; } = new(); + } +} diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDataBase.cs b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDataBase.cs new file mode 100644 index 0000000..87d5976 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDataBase.cs @@ -0,0 +1,22 @@ +using TravelCompanyDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; + +namespace TravelCompanyDatabaseImplement +{ + public class TravelCompanyDataBase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder +optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=TravelCompanyDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Components { set; get; } + public virtual DbSet Travels { set; get; } + public virtual DbSet TravelComponents { set; get; } + public virtual DbSet Orders { set; get; } + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj new file mode 100644 index 0000000..e657335 --- /dev/null +++ b/TravelCompany/TravelCompanyDatabaseImplement/TravelCompanyDatabaseImplement.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + diff --git a/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs new file mode 100644 index 0000000..01817fb --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/DataListSingleton.cs @@ -0,0 +1,31 @@ +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Travels { get; set; } + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Travels = new List(); + } + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + return _instance; + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/ComponentStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..dddef2b --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/ComponentStorage.cs @@ -0,0 +1,106 @@ +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataListSingleton _source; + public ComponentStorage() + { + _source = DataListSingleton.GetInstance(); + } + public List GetFullList() + { + var result = new List(); + foreach (var component in _source.Components) + { + result.Add(component.GetViewModel); + } + return result; + } + public List GetFilteredList(ComponentSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ComponentName)) + { + return result; + } + foreach (var component in _source.Components) + { + if (component.ComponentName.Contains(model.ComponentName)) + { + result.Add(component.GetViewModel); + } + } + return result; + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + foreach (var component in _source.Components) + { + if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || + (model.Id.HasValue && component.Id == model.Id)) + { + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = 1; + foreach (var component in _source.Components) + { + if (model.Id <= component.Id) + { + model.Id = component.Id + 1; + } + } + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + _source.Components.Add(newComponent); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + foreach (var component in _source.Components) + { + if (component.Id == model.Id) + { + component.Update(model); + return component.GetViewModel; + } + } + return null; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + for (int i = 0; i < _source.Components.Count; ++i) + { + if (_source.Components[i].Id == model.Id) + { + var element = _source.Components[i]; + _source.Components.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..0676fe2 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/OrderStorage.cs @@ -0,0 +1,125 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataListSingleton _source; + + public OrderStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var order in _source.Orders) + { + result.Add(AttachTravelName(order.GetViewModel)); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + var result = new List(); + if (model == null || !model.Id.HasValue) + { + return result; + } + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + result.Add(AttachTravelName(order.GetViewModel)); + } + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + foreach (var order in _source.Orders) + { + if (model.Id.HasValue && order.Id == model.Id) + { + return AttachTravelName(order.GetViewModel); + } + } + return null; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = 1; + foreach (var order in _source.Orders) + { + if (model.Id <= order.Id) + { + model.Id = order.Id + 1; + } + } + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + _source.Orders.Add(newOrder); + return AttachTravelName(newOrder.GetViewModel); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + foreach (var order in _source.Orders) + { + if (order.Id == model.Id) + { + order.Update(model); + return AttachTravelName(order.GetViewModel); + } + } + return null; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + for (int i = 0; i < _source.Orders.Count; ++i) + { + if (_source.Orders[i].Id == model.Id) + { + var element = _source.Orders[i]; + _source.Orders.RemoveAt(i); + return AttachTravelName(element.GetViewModel); + } + } + return null; + } + + private OrderViewModel AttachTravelName(OrderViewModel model) + { + foreach (var Travel in _source.Travels) + { + if (Travel.Id == model.TravelId) + { + model.TravelName = Travel.TravelName; + return model; + } + } + return model; + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs b/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs new file mode 100644 index 0000000..7673715 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Implements/TravelStorage.cs @@ -0,0 +1,112 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.SearchModels; +using TravelCompanyContracts.StoragesContracts; +using TravelCompanyContracts.ViewModels; +using TravelCompanyListImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Implements +{ + public class TravelStorage : ITravelStorage + { + private readonly DataListSingleton _source; + public TravelStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public TravelViewModel? Delete(TravelBindingModel model) + { + for (int i = 0; i < _source.Travels.Count; ++i) + { + if (_source.Travels[i].Id == model.Id) + { + var element = _source.Travels[i]; + _source.Travels.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public TravelViewModel? GetElement(TravelSearchModel model) + { + if (string.IsNullOrEmpty(model.TravelName) && !model.Id.HasValue) + { + return null; + } + foreach (var Travel in _source.Travels) + { + if ((!string.IsNullOrEmpty(model.TravelName) && Travel.TravelName == model.TravelName) || + (model.Id.HasValue && Travel.Id == model.Id)) + { + return Travel.GetViewModel; + } + } + return null; + } + + public List GetFilteredList(TravelSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.TravelName)) + { + return result; + } + foreach (var Travel in _source.Travels) + { + if (Travel.TravelName.Contains(model.TravelName)) + { + result.Add(Travel.GetViewModel); + } + } + return result; + } + + public List GetFullList() + { + var result = new List(); + foreach (var Travel in _source.Travels) + { + result.Add(Travel.GetViewModel); + } + return result; + } + + public TravelViewModel? Insert(TravelBindingModel model) + { + model.Id = 1; + foreach (var Travel in _source.Travels) + { + if (model.Id <= Travel.Id) + { + model.Id = Travel.Id + 1; + } + } + var newTravel = Travel.Create(model); + if (newTravel == null) + { + return null; + } + _source.Travels.Add(newTravel); + return newTravel.GetViewModel; + } + + public TravelViewModel? Update(TravelBindingModel model) + { + foreach (var Travel in _source.Travels) + { + if (Travel.Id == model.Id) + { + Travel.Update(model); + return Travel.GetViewModel; + } + } + return null; + } + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Models/Component.cs b/TravelCompany/TravelCompanyListImplement/Models/Component.cs new file mode 100644 index 0000000..1c9f49a --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Models/Component.cs @@ -0,0 +1,41 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; + +namespace TravelCompanyListImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel? model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public void Update(ComponentBindingModel? model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + } +} \ No newline at end of file diff --git a/TravelCompany/TravelCompanyListImplement/Models/Order.cs b/TravelCompany/TravelCompanyListImplement/Models/Order.cs new file mode 100644 index 0000000..e9e9705 --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Models/Order.cs @@ -0,0 +1,60 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Enums; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Models +{ + public class Order : IOrderModel + { + public int Id { get; private set; } + public int TravelId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } + public OrderStatus Status { get; private set; } + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + TravelId = model.TravelId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement, + }; + } + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + public OrderViewModel GetViewModel => new() + { + Id = Id, + TravelId = TravelId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement, + }; + } +} diff --git a/TravelCompany/TravelCompanyListImplement/Models/Travel.cs b/TravelCompany/TravelCompanyListImplement/Models/Travel.cs new file mode 100644 index 0000000..32ff4bc --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/Models/Travel.cs @@ -0,0 +1,55 @@ +using TravelCompanyContracts.BindingModels; +using TravelCompanyContracts.ViewModels; +using TravelCompanyDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TravelCompanyListImplement.Models +{ + internal class Travel : ITravelModel + { + public int Id { get; private set; } + public string TravelName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary TravelComponents + { + get; + private set; + } = new Dictionary(); + public static Travel? Create(TravelBindingModel? model) + { + if (model == null) + { + return null; + } + return new Travel() + { + Id = model.Id, + TravelName = model.TravelName, + Price = model.Price, + TravelComponents = model.TravelComponents + }; + } + public void Update(TravelBindingModel? model) + { + if (model == null) + { + return; + } + TravelName = model.TravelName; + Price = model.Price; + TravelComponents = model.TravelComponents; + } + public TravelViewModel GetViewModel => new() + { + Id = Id, + TravelName = TravelName, + Price = Price, + TravelComponents = TravelComponents + }; + + } +} diff --git a/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj new file mode 100644 index 0000000..801025b --- /dev/null +++ b/TravelCompany/TravelCompanyListImplement/TravelCompanyListImplement.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + + + + + +