diff --git a/SportCompetitions/SportCompetitions.sln b/SportCompetitions/SportCompetitions.sln new file mode 100644 index 0000000..1db8a7f --- /dev/null +++ b/SportCompetitions/SportCompetitions.sln @@ -0,0 +1,49 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32825.248 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SportCompetitionsBusinessLogic", "SportCompetitionsBusinessLogic\SportCompetitionsBusinessLogic.csproj", "{FFB7B35D-30CA-46AB-86E9-6BE64CC49E07}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SportCompetitionsContracts", "SportCompetitionsContracts\SportCompetitionsContracts.csproj", "{AEB7A4E0-5078-45DA-8E5D-6B07C176EA69}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SportCompetitionsDataModels", "SportCompetitionsDataModels\SportCompetitionsDataModels.csproj", "{43BB3C79-C5E4-487C-BFBB-A35A6E87951B}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SportCompetitionsDatabaseImplement", "SportCompetitionsDatabaseImplement\SportCompetitionsDatabaseImplement.csproj", "{09B7CD5C-0160-4ACD-951B-D740A036A26D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SportCompetitionsView", "SportCompetitionsView\SportCompetitionsView.csproj", "{5D947E6B-6987-4A08-90FC-3B554CE676E3}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FFB7B35D-30CA-46AB-86E9-6BE64CC49E07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFB7B35D-30CA-46AB-86E9-6BE64CC49E07}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFB7B35D-30CA-46AB-86E9-6BE64CC49E07}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFB7B35D-30CA-46AB-86E9-6BE64CC49E07}.Release|Any CPU.Build.0 = Release|Any CPU + {AEB7A4E0-5078-45DA-8E5D-6B07C176EA69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AEB7A4E0-5078-45DA-8E5D-6B07C176EA69}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AEB7A4E0-5078-45DA-8E5D-6B07C176EA69}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AEB7A4E0-5078-45DA-8E5D-6B07C176EA69}.Release|Any CPU.Build.0 = Release|Any CPU + {43BB3C79-C5E4-487C-BFBB-A35A6E87951B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {43BB3C79-C5E4-487C-BFBB-A35A6E87951B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {43BB3C79-C5E4-487C-BFBB-A35A6E87951B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {43BB3C79-C5E4-487C-BFBB-A35A6E87951B}.Release|Any CPU.Build.0 = Release|Any CPU + {09B7CD5C-0160-4ACD-951B-D740A036A26D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {09B7CD5C-0160-4ACD-951B-D740A036A26D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {09B7CD5C-0160-4ACD-951B-D740A036A26D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {09B7CD5C-0160-4ACD-951B-D740A036A26D}.Release|Any CPU.Build.0 = Release|Any CPU + {5D947E6B-6987-4A08-90FC-3B554CE676E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5D947E6B-6987-4A08-90FC-3B554CE676E3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5D947E6B-6987-4A08-90FC-3B554CE676E3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5D947E6B-6987-4A08-90FC-3B554CE676E3}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {12AF8F8B-CB1C-49C6-ACB2-E7AD7E4A12CE} + EndGlobalSection +EndGlobal diff --git a/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/CoachLogic.cs b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/CoachLogic.cs new file mode 100644 index 0000000..2e7524d --- /dev/null +++ b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/CoachLogic.cs @@ -0,0 +1,93 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsBusinessLogic.BusinessLogics +{ + public class CoachLogic : ICoachLogic + { + private readonly ICoachStorage _coachStorage; + + public CoachLogic(ICoachStorage coachStorage) + { + _coachStorage = coachStorage; + } + public CoachViewModel? ReadElement(CoachSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _coachStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(CoachSearchModel? model) + { + var list = model == null ? _coachStorage.GetFullList() : _coachStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(CoachBindingModel model) + { + CheckModel(model); + if (_coachStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(CoachBindingModel model) + { + CheckModel(model, false); + if (_coachStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(CoachBindingModel model) + { + CheckModel(model); + if (_coachStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(CoachBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.CoachName)) + { + throw new ArgumentNullException("Нет ФИО", nameof(model.CoachName)); + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/CompetitionLogic.cs b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/CompetitionLogic.cs new file mode 100644 index 0000000..2924d09 --- /dev/null +++ b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/CompetitionLogic.cs @@ -0,0 +1,93 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsBusinessLogic.BusinessLogics +{ + public class CompetitionLogic : ICompetitionLogic + { + private readonly ICompetitionStorage _competitionStorage; + + public CompetitionLogic(ICompetitionStorage competitionStorage) + { + _competitionStorage = competitionStorage; + } + public CompetitionViewModel? ReadElement(CompetitionSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _competitionStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(CompetitionSearchModel? model) + { + var list = model == null ? _competitionStorage.GetFullList() : _competitionStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(CompetitionBindingModel model) + { + CheckModel(model); + if (_competitionStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(CompetitionBindingModel model) + { + CheckModel(model, false); + if (_competitionStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(CompetitionBindingModel model) + { + CheckModel(model); + if (_competitionStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(CompetitionBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.CompetitionName)) + { + throw new ArgumentNullException("Нет названия", nameof(model.CompetitionName)); + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/ParticipantLogic.cs b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/ParticipantLogic.cs new file mode 100644 index 0000000..5882998 --- /dev/null +++ b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/ParticipantLogic.cs @@ -0,0 +1,93 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsBusinessLogic.BusinessLogics +{ + public class ParticipantLogic : IParticipantLogic + { + private readonly IParticipantStorage _participantStorage; + + public ParticipantLogic(IParticipantStorage participantStorage) + { + _participantStorage = participantStorage; + } + public ParticipantViewModel? ReadElement(ParticipantSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _participantStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(ParticipantSearchModel? model) + { + var list = model == null ? _participantStorage.GetFullList() : _participantStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(ParticipantBindingModel model) + { + CheckModel(model); + if (_participantStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(ParticipantBindingModel model) + { + CheckModel(model, false); + if (_participantStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(ParticipantBindingModel model) + { + CheckModel(model); + if (_participantStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(ParticipantBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ParticipantName)) + { + throw new ArgumentNullException("Нет ФИО", nameof(model.ParticipantName)); + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/SportClubLogic.cs b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/SportClubLogic.cs new file mode 100644 index 0000000..39b06bd --- /dev/null +++ b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/SportClubLogic.cs @@ -0,0 +1,93 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsBusinessLogic.BusinessLogics +{ + public class SportClubLogic : ISportClubLogic + { + private readonly ISportClubStorage _sportClubStorage; + + public SportClubLogic(ISportClubStorage sportClubStorage) + { + _sportClubStorage = sportClubStorage; + } + public SportClubViewModel? ReadElement(SportClubSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _sportClubStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(SportClubSearchModel? model) + { + var list = model == null ? _sportClubStorage.GetFullList() : _sportClubStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(SportClubBindingModel model) + { + CheckModel(model); + if (_sportClubStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(SportClubBindingModel model) + { + CheckModel(model, false); + if (_sportClubStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(SportClubBindingModel model) + { + CheckModel(model); + if (_sportClubStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(SportClubBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SportClubName)) + { + throw new ArgumentNullException("Нет названия", nameof(model.SportClubName)); + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/SportTypeLogic.cs b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/SportTypeLogic.cs new file mode 100644 index 0000000..d655a8f --- /dev/null +++ b/SportCompetitions/SportCompetitionsBusinessLogic/BusinessLogics/SportTypeLogic.cs @@ -0,0 +1,93 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsBusinessLogic.BusinessLogics +{ + public class SportTypeLogic : ISportTypeLogic + { + private readonly ISportTypeStorage _sportTypeStorage; + + public SportTypeLogic(ISportTypeStorage sportTypeStorage) + { + _sportTypeStorage = sportTypeStorage; + } + public SportTypeViewModel? ReadElement(SportTypeSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + + var element = _sportTypeStorage.GetElement(model); + if (element == null) + { + return null; + } + return element; + } + + public List? ReadList(SportTypeSearchModel? model) + { + var list = model == null ? _sportTypeStorage.GetFullList() : _sportTypeStorage.GetFilteredList(model); + if (list == null) + { + return null; + } + return list; + } + + public bool Create(SportTypeBindingModel model) + { + CheckModel(model); + if (_sportTypeStorage.Insert(model) == null) + { + return false; + } + return true; + } + + public bool Delete(SportTypeBindingModel model) + { + CheckModel(model, false); + if (_sportTypeStorage.Delete(model) == null) + { + return false; + } + return true; + } + + public bool Update(SportTypeBindingModel model) + { + CheckModel(model); + if (_sportTypeStorage.Update(model) == null) + { + return false; + } + return true; + } + + private void CheckModel(SportTypeBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.SportTypeName)) + { + throw new ArgumentNullException("Нет названия", nameof(model.SportTypeName)); + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsBusinessLogic/SportCompetitionsBusinessLogic.csproj b/SportCompetitions/SportCompetitionsBusinessLogic/SportCompetitionsBusinessLogic.csproj new file mode 100644 index 0000000..efa6fd2 --- /dev/null +++ b/SportCompetitions/SportCompetitionsBusinessLogic/SportCompetitionsBusinessLogic.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/SportCompetitions/SportCompetitionsContracts/BindingModels/CoachBindingModel.cs b/SportCompetitions/SportCompetitionsContracts/BindingModels/CoachBindingModel.cs new file mode 100644 index 0000000..a6e30f6 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BindingModels/CoachBindingModel.cs @@ -0,0 +1,19 @@ +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BindingModels +{ + public class CoachBindingModel : ICoachModel + { + public int Id { get; set; } + public string? CoachName { get; set; } + public int BirthYear { get; set; } + public string? Country { get; set; } + public int SportClubId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BindingModels/CompetitionBindingModel.cs b/SportCompetitions/SportCompetitionsContracts/BindingModels/CompetitionBindingModel.cs new file mode 100644 index 0000000..fa5a0ec --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BindingModels/CompetitionBindingModel.cs @@ -0,0 +1,20 @@ +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BindingModels +{ + public class CompetitionBindingModel : ICompetitionModel + { + public int Id { get; set; } + public string? CompetitionName { get; set; } + public DateTime StartDate { get; set; } + public DateTime EndDate { get; set; } + public string? Location { get; set; } + public int SportTypeId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BindingModels/ParticipantBindingModel.cs b/SportCompetitions/SportCompetitionsContracts/BindingModels/ParticipantBindingModel.cs new file mode 100644 index 0000000..7501388 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BindingModels/ParticipantBindingModel.cs @@ -0,0 +1,21 @@ +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BindingModels +{ + public class ParticipantBindingModel : IParticipantModel + { + public int Id { get; set; } + public string? ParticipantName { get; set; } + public int BirthYear { get; set; } + public string? Country { get; set; } + public string? Gender { get; set; } + public int CoachId { get; set; } + public int CompetitionId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BindingModels/SportClubBindingModel.cs b/SportCompetitions/SportCompetitionsContracts/BindingModels/SportClubBindingModel.cs new file mode 100644 index 0000000..a4b0639 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BindingModels/SportClubBindingModel.cs @@ -0,0 +1,19 @@ +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BindingModels +{ + public class SportClubBindingModel : ISportClubModel + { + public int Id { get; set; } + public string? SportClubName { get; set; } + public string? SportClubAddress { get; set; } + public string? SportClubPhone { get; set; } + public string? SportClubEmail { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BindingModels/SportTypeBindingModel.cs b/SportCompetitions/SportCompetitionsContracts/BindingModels/SportTypeBindingModel.cs new file mode 100644 index 0000000..b9ed09a --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BindingModels/SportTypeBindingModel.cs @@ -0,0 +1,15 @@ +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BindingModels +{ + public class SportTypeBindingModel : ISportTypeModel + { + public int Id { get; set; } + public string? SportTypeName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ICoachLogic.cs b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ICoachLogic.cs new file mode 100644 index 0000000..16d5ec9 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ICoachLogic.cs @@ -0,0 +1,21 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BusinessLogicsContracts +{ + public interface ICoachLogic + { + List? ReadList(CoachSearchModel? model); + CoachViewModel? ReadElement(CoachSearchModel model); + + bool Create(CoachBindingModel model); + bool Update(CoachBindingModel model); + bool Delete(CoachBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ICompetitionLogic.cs b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ICompetitionLogic.cs new file mode 100644 index 0000000..c8c27ab --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ICompetitionLogic.cs @@ -0,0 +1,21 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BusinessLogicsContracts +{ + public interface ICompetitionLogic + { + List? ReadList(CompetitionSearchModel? model); + CompetitionViewModel? ReadElement(CompetitionSearchModel model); + + bool Create(CompetitionBindingModel model); + bool Update(CompetitionBindingModel model); + bool Delete(CompetitionBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/IParticipantLogic.cs b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/IParticipantLogic.cs new file mode 100644 index 0000000..21415b2 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/IParticipantLogic.cs @@ -0,0 +1,21 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BusinessLogicsContracts +{ + public interface IParticipantLogic + { + List? ReadList(ParticipantSearchModel? model); + ParticipantViewModel? ReadElement(ParticipantSearchModel model); + + bool Create(ParticipantBindingModel model); + bool Update(ParticipantBindingModel model); + bool Delete(ParticipantBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ISportClubLogic.cs b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ISportClubLogic.cs new file mode 100644 index 0000000..bc583ba --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ISportClubLogic.cs @@ -0,0 +1,21 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BusinessLogicsContracts +{ + public interface ISportClubLogic + { + List? ReadList(SportClubSearchModel? model); + SportClubViewModel? ReadElement(SportClubSearchModel model); + + bool Create(SportClubBindingModel model); + bool Update(SportClubBindingModel model); + bool Delete(SportClubBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ISportTypeLogic.cs b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ISportTypeLogic.cs new file mode 100644 index 0000000..8496b27 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/BusinessLogicsContracts/ISportTypeLogic.cs @@ -0,0 +1,21 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsContracts.SearchModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.BusinessLogicsContracts +{ + public interface ISportTypeLogic + { + List? ReadList(SportTypeSearchModel? model); + SportTypeViewModel? ReadElement(SportTypeSearchModel model); + + bool Create(SportTypeBindingModel model); + bool Update(SportTypeBindingModel model); + bool Delete(SportTypeBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/SearchModels/CoachSearchModel.cs b/SportCompetitions/SportCompetitionsContracts/SearchModels/CoachSearchModel.cs new file mode 100644 index 0000000..94f8607 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/SearchModels/CoachSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.SearchModels +{ + public class CoachSearchModel + { + public int? Id { get; set; } + public string? CoachName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/SearchModels/CompetitionSearchModel.cs b/SportCompetitions/SportCompetitionsContracts/SearchModels/CompetitionSearchModel.cs new file mode 100644 index 0000000..a1bf1b2 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/SearchModels/CompetitionSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.SearchModels +{ + public class CompetitionSearchModel + { + public int? Id { get; set; } + public string? CompetitionName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/SearchModels/ParticipantSearchModel.cs b/SportCompetitions/SportCompetitionsContracts/SearchModels/ParticipantSearchModel.cs new file mode 100644 index 0000000..310e3ac --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/SearchModels/ParticipantSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.SearchModels +{ + public class ParticipantSearchModel + { + public int? Id { get; set; } + public string? ParticipantName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/SearchModels/SportClubSearchModel.cs b/SportCompetitions/SportCompetitionsContracts/SearchModels/SportClubSearchModel.cs new file mode 100644 index 0000000..6372c90 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/SearchModels/SportClubSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.SearchModels +{ + public class SportClubSearchModel + { + public int? Id { get; set; } + public string? SportClubName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/SearchModels/SportTypeSearchModel.cs b/SportCompetitions/SportCompetitionsContracts/SearchModels/SportTypeSearchModel.cs new file mode 100644 index 0000000..32a8ec4 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/SearchModels/SportTypeSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.SearchModels +{ + public class SportTypeSearchModel + { + public int? Id { get; set; } + public string? SportTypeName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/SportCompetitionsContracts.csproj b/SportCompetitions/SportCompetitionsContracts/SportCompetitionsContracts.csproj new file mode 100644 index 0000000..e9e2640 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/SportCompetitionsContracts.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ICoachStorage.cs b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ICoachStorage.cs new file mode 100644 index 0000000..9a60b09 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ICoachStorage.cs @@ -0,0 +1,22 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.StoragesContracts +{ + public interface ICoachStorage + { + List GetFullList(); + List GetFilteredList(CoachSearchModel model); + + CoachViewModel? GetElement(CoachSearchModel model); + CoachViewModel? Insert(CoachBindingModel model); + CoachViewModel? Update(CoachBindingModel model); + CoachViewModel? Delete(CoachBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ICompetitionStorage.cs b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ICompetitionStorage.cs new file mode 100644 index 0000000..72865b8 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ICompetitionStorage.cs @@ -0,0 +1,22 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.StoragesContracts +{ + public interface ICompetitionStorage + { + List GetFullList(); + List GetFilteredList(CompetitionSearchModel model); + + CompetitionViewModel? GetElement(CompetitionSearchModel model); + CompetitionViewModel? Insert(CompetitionBindingModel model); + CompetitionViewModel? Update(CompetitionBindingModel model); + CompetitionViewModel? Delete(CompetitionBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/StoragesContracts/IParticipantStorage.cs b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/IParticipantStorage.cs new file mode 100644 index 0000000..2004cc0 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/IParticipantStorage.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.ViewModels; + +namespace SportCompetitionsContracts.StoragesContracts +{ + public interface IParticipantStorage + { + List GetFullList(); + List GetFilteredList(ParticipantSearchModel model); + + ParticipantViewModel? GetElement(ParticipantSearchModel model); + ParticipantViewModel? Insert(ParticipantBindingModel model); + ParticipantViewModel? Update(ParticipantBindingModel model); + ParticipantViewModel? Delete(ParticipantBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ISportClubStorage.cs b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ISportClubStorage.cs new file mode 100644 index 0000000..0fa4da7 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ISportClubStorage.cs @@ -0,0 +1,22 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.StoragesContracts +{ + public interface ISportClubStorage + { + List GetFullList(); + List GetFilteredList(SportClubSearchModel model); + + SportClubViewModel? GetElement(SportClubSearchModel model); + SportClubViewModel? Insert(SportClubBindingModel model); + SportClubViewModel? Update(SportClubBindingModel model); + SportClubViewModel? Delete(SportClubBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ISportTypeStorage.cs b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ISportTypeStorage.cs new file mode 100644 index 0000000..3f630c3 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/StoragesContracts/ISportTypeStorage.cs @@ -0,0 +1,22 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsContracts.StoragesContracts +{ + public interface ISportTypeStorage + { + List GetFullList(); + List GetFilteredList(SportTypeSearchModel model); + + SportTypeViewModel? GetElement(SportTypeSearchModel model); + SportTypeViewModel? Insert(SportTypeBindingModel model); + SportTypeViewModel? Update(SportTypeBindingModel model); + SportTypeViewModel? Delete(SportTypeBindingModel model); + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/ViewModels/CoachViewModel.cs b/SportCompetitions/SportCompetitionsContracts/ViewModels/CoachViewModel.cs new file mode 100644 index 0000000..ad0d13a --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/ViewModels/CoachViewModel.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SportCompetitionsDataModels.Models; + +namespace SportCompetitionsContracts.ViewModels +{ + public class CoachViewModel : ICoachModel + { + public int Id { get; set; } + [DisplayName("ФИО тренера")] + public string? CoachName { get; set; } + [DisplayName("Год рождения")] + public int BirthYear { get; set; } + [DisplayName("Страна")] + public string? Country { get; set; } + public int SportClubId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/ViewModels/CompetitionViewModel.cs b/SportCompetitions/SportCompetitionsContracts/ViewModels/CompetitionViewModel.cs new file mode 100644 index 0000000..065b6d2 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/ViewModels/CompetitionViewModel.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SportCompetitionsDataModels.Models; + +namespace SportCompetitionsContracts.ViewModels +{ + public class CompetitionViewModel : ICompetitionModel + { + public int Id { get; set; } + [DisplayName("Название соревнования")] + public string? CompetitionName { get; set; } + [DisplayName("Начало соревнований")] + public DateTime StartDate { get; set; } + [DisplayName("Конец соревнований")] + public DateTime EndDate { get; set; } + [DisplayName("Локация")] + public string? Location { get; set; } + public int SportTypeId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/ViewModels/ParticipantViewModel.cs b/SportCompetitions/SportCompetitionsContracts/ViewModels/ParticipantViewModel.cs new file mode 100644 index 0000000..f548ae9 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/ViewModels/ParticipantViewModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SportCompetitionsDataModels.Models; + +namespace SportCompetitionsContracts.ViewModels +{ + public class ParticipantViewModel : IParticipantModel + { + public int Id { get; set; } + [DisplayName("ФИО участника")] + public string? ParticipantName { get; set; } + [DisplayName("Год рождения")] + public int BirthYear { get; set; } + [DisplayName("Страна")] + public string? Country { get; set; } + [DisplayName("Пол")] + public string? Gender { get; set; } + public int CoachId { get; set; } + public int CompetitionId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/ViewModels/SportClubViewModel.cs b/SportCompetitions/SportCompetitionsContracts/ViewModels/SportClubViewModel.cs new file mode 100644 index 0000000..45ca5a7 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/ViewModels/SportClubViewModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SportCompetitionsDataModels.Models; + +namespace SportCompetitionsContracts.ViewModels +{ + public class SportClubViewModel : ISportClubModel + { + public int Id { get; set; } + [DisplayName("Название спортивного клуба")] + public string? SportClubName { get; set; } + [DisplayName("Адрес спортивного клуба")] + public string? SportClubAddress { get; set; } + [DisplayName("Телефон спортивного клуба")] + public string? SportClubPhone { get; set; } + [DisplayName("Почта спортивного клуба")] + public string? SportClubEmail { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsContracts/ViewModels/SportTypeViewModel.cs b/SportCompetitions/SportCompetitionsContracts/ViewModels/SportTypeViewModel.cs new file mode 100644 index 0000000..c1c7041 --- /dev/null +++ b/SportCompetitions/SportCompetitionsContracts/ViewModels/SportTypeViewModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SportCompetitionsDataModels.Models; + +namespace SportCompetitionsContracts.ViewModels +{ + public class SportTypeViewModel : ISportTypeModel + { + public int Id { get; set; } + [DisplayName("Название вида спорта")] + public string? SportTypeName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsDataModels/IId.cs b/SportCompetitions/SportCompetitionsDataModels/IId.cs new file mode 100644 index 0000000..28535e4 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDataModels/IId.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDataModels +{ + public interface IId + { + int Id { get; } + } +} diff --git a/SportCompetitions/SportCompetitionsDataModels/Models/ICoachModel.cs b/SportCompetitions/SportCompetitionsDataModels/Models/ICoachModel.cs new file mode 100644 index 0000000..277cd73 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDataModels/Models/ICoachModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDataModels.Models +{ + public interface ICoachModel : IId + { + string CoachName { get; set; } + int BirthYear { get; set; } + string Country { get; set; } + int SportClubId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsDataModels/Models/ICompetitionModel.cs b/SportCompetitions/SportCompetitionsDataModels/Models/ICompetitionModel.cs new file mode 100644 index 0000000..29fbae0 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDataModels/Models/ICompetitionModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDataModels.Models +{ + public interface ICompetitionModel : IId + { + string CompetitionName { get; set; } + DateTime StartDate { get; } + DateTime EndDate { get; } + string Location { get; set; } + int SportTypeId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsDataModels/Models/IParticipantModel.cs b/SportCompetitions/SportCompetitionsDataModels/Models/IParticipantModel.cs new file mode 100644 index 0000000..318ec72 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDataModels/Models/IParticipantModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDataModels.Models +{ + public interface IParticipantModel : IId + { + string ParticipantName { get; set; } + int BirthYear { get; set; } + string Country { get; set; } + string Gender { get; set; } + int CoachId { get; set; } + int CompetitionId { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsDataModels/Models/ISportClubModel.cs b/SportCompetitions/SportCompetitionsDataModels/Models/ISportClubModel.cs new file mode 100644 index 0000000..8c052ab --- /dev/null +++ b/SportCompetitions/SportCompetitionsDataModels/Models/ISportClubModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDataModels.Models +{ + public interface ISportClubModel : IId + { + string SportClubName { get; set; } + string SportClubAddress { get; set; } + string SportClubPhone { get; set; } + string? SportClubEmail { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsDataModels/Models/ISportTypeModel.cs b/SportCompetitions/SportCompetitionsDataModels/Models/ISportTypeModel.cs new file mode 100644 index 0000000..03a4745 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDataModels/Models/ISportTypeModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDataModels.Models +{ + public interface ISportTypeModel : IId + { + string SportTypeName { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsDataModels/SportCompetitionsDataModels.csproj b/SportCompetitions/SportCompetitionsDataModels/SportCompetitionsDataModels.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/SportCompetitions/SportCompetitionsDataModels/SportCompetitionsDataModels.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/CoachStorage.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/CoachStorage.cs new file mode 100644 index 0000000..622c03a --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/CoachStorage.cs @@ -0,0 +1,77 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Implements +{ + public class CoachStorage : ICoachStorage + { + public List GetFilteredList(CoachSearchModel model) + { + if (string.IsNullOrEmpty(model.CoachName)) + { + return new(); + } + using var context = new SportCompetitionsDatabase(); + return context.Coaches.Where(x => x.CoachName.Contains(model.CoachName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new SportCompetitionsDatabase(); + return context.Coaches.Select(x => x.GetViewModel).ToList(); + } + + public CoachViewModel? Delete(CoachBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var element = context.Coaches.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Coaches.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public CoachViewModel? GetElement(CoachSearchModel model) + { + using var context = new SportCompetitionsDatabase(); + return context.Coaches.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CoachName)) && x.CoachName == model.CoachName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public CoachViewModel? Insert(CoachBindingModel model) + { + var newCoach = Coach.Create(model); + if (newCoach == null) + { + return null; + } + using var context = new SportCompetitionsDatabase(); + context.Coaches.Add(newCoach); + context.SaveChanges(); + return newCoach.GetViewModel; + } + + public CoachViewModel? Update(CoachBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var component = context.Coaches.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/CompetitionStorage.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/CompetitionStorage.cs new file mode 100644 index 0000000..d4663d5 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/CompetitionStorage.cs @@ -0,0 +1,77 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Implements +{ + public class CompetitionStorage : ICompetitionStorage + { + public List GetFilteredList(CompetitionSearchModel model) + { + if (string.IsNullOrEmpty(model.CompetitionName)) + { + return new(); + } + using var context = new SportCompetitionsDatabase(); + return context.Competitions.Where(x => x.CompetitionName.Contains(model.CompetitionName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new SportCompetitionsDatabase(); + return context.Competitions.Select(x => x.GetViewModel).ToList(); + } + + public CompetitionViewModel? Delete(CompetitionBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var element = context.Competitions.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Competitions.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public CompetitionViewModel? GetElement(CompetitionSearchModel model) + { + using var context = new SportCompetitionsDatabase(); + return context.Competitions.FirstOrDefault(x => (!string.IsNullOrEmpty(model.CompetitionName)) && x.CompetitionName == model.CompetitionName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public CompetitionViewModel? Insert(CompetitionBindingModel model) + { + var newCompetition = Competition.Create(model); + if (newCompetition == null) + { + return null; + } + using var context = new SportCompetitionsDatabase(); + context.Competitions.Add(newCompetition); + context.SaveChanges(); + return newCompetition.GetViewModel; + } + + public CompetitionViewModel? Update(CompetitionBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var component = context.Competitions.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/ParticipantStorage.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/ParticipantStorage.cs new file mode 100644 index 0000000..69bc454 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/ParticipantStorage.cs @@ -0,0 +1,78 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Implements +{ + public class ParticipantStorage : IParticipantStorage + { + public List GetFilteredList(ParticipantSearchModel model) + { + if (string.IsNullOrEmpty(model.ParticipantName)) + { + return new(); + } + using var context = new SportCompetitionsDatabase(); + return context.Participants.Where(x => x.ParticipantName.Contains(model.ParticipantName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new SportCompetitionsDatabase(); + return context.Participants.Select(x => x.GetViewModel).ToList(); + } + + public ParticipantViewModel? Delete(ParticipantBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var element = context.Participants.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Participants.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public ParticipantViewModel? GetElement(ParticipantSearchModel model) + { + using var context = new SportCompetitionsDatabase(); + return context.Participants.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ParticipantName)) && x.ParticipantName == model.ParticipantName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public ParticipantViewModel? Insert(ParticipantBindingModel model) + { + var newParticipant = Participant.Create(model); + if (newParticipant == null) + { + return null; + } + using var context = new SportCompetitionsDatabase(); + context.Participants.Add(newParticipant); + context.SaveChanges(); + return newParticipant.GetViewModel; + } + + public ParticipantViewModel? Update(ParticipantBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var component = context.Participants.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/SportClubStorage.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/SportClubStorage.cs new file mode 100644 index 0000000..5a67bb9 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/SportClubStorage.cs @@ -0,0 +1,77 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Implements +{ + public class SportClubStorage : ISportClubStorage + { + public List GetFilteredList(SportClubSearchModel model) + { + if (string.IsNullOrEmpty(model.SportClubName)) + { + return new(); + } + using var context = new SportCompetitionsDatabase(); + return context.SportClubs.Where(x => x.SportClubName.Contains(model.SportClubName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new SportCompetitionsDatabase(); + return context.SportClubs.Select(x => x.GetViewModel).ToList(); + } + + public SportClubViewModel? Delete(SportClubBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var element = context.SportClubs.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.SportClubs.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public SportClubViewModel? GetElement(SportClubSearchModel model) + { + using var context = new SportCompetitionsDatabase(); + return context.SportClubs.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SportClubName)) && x.SportClubName == model.SportClubName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public SportClubViewModel? Insert(SportClubBindingModel model) + { + var newSportClub = SportClub.Create(model); + if (newSportClub == null) + { + return null; + } + using var context = new SportCompetitionsDatabase(); + context.SportClubs.Add(newSportClub); + context.SaveChanges(); + return newSportClub.GetViewModel; + } + + public SportClubViewModel? Update(SportClubBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var component = context.SportClubs.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/SportTypeStorage.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/SportTypeStorage.cs new file mode 100644 index 0000000..1e6e61e --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Implements/SportTypeStorage.cs @@ -0,0 +1,77 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.SearchModels; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Implements +{ + public class SportTypeStorage : ISportTypeStorage + { + public List GetFilteredList(SportTypeSearchModel model) + { + if (string.IsNullOrEmpty(model.SportTypeName)) + { + return new(); + } + using var context = new SportCompetitionsDatabase(); + return context.SportTypes.Where(x => x.SportTypeName.Contains(model.SportTypeName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + using var context = new SportCompetitionsDatabase(); + return context.SportTypes.Select(x => x.GetViewModel).ToList(); + } + + public SportTypeViewModel? Delete(SportTypeBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var element = context.SportTypes.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.SportTypes.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } + + public SportTypeViewModel? GetElement(SportTypeSearchModel model) + { + using var context = new SportCompetitionsDatabase(); + return context.SportTypes.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SportTypeName)) && x.SportTypeName == model.SportTypeName || model.Id.HasValue && x.Id == model.Id)?.GetViewModel; + } + + public SportTypeViewModel? Insert(SportTypeBindingModel model) + { + var newSportType = SportType.Create(model); + if (newSportType == null) + { + return null; + } + using var context = new SportCompetitionsDatabase(); + context.SportTypes.Add(newSportType); + context.SaveChanges(); + return newSportType.GetViewModel; + } + + public SportTypeViewModel? Update(SportTypeBindingModel model) + { + using var context = new SportCompetitionsDatabase(); + var component = context.SportTypes.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + context.SaveChanges(); + return component.GetViewModel; + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/20240521190730_InitialCreate.Designer.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/20240521190730_InitialCreate.Designer.cs new file mode 100644 index 0000000..2492bca --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/20240521190730_InitialCreate.Designer.cs @@ -0,0 +1,167 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SportCompetitionsDatabaseImplement; + +#nullable disable + +namespace SportCompetitionsDatabaseImplement.Migrations +{ + [DbContext(typeof(SportCompetitionsDatabase))] + [Migration("20240521190730_InitialCreate")] + partial class InitialCreate + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.Coach", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BirthYear") + .HasColumnType("int"); + + b.Property("CoachName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Coaches"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.Competition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CompetitionName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("EndDate") + .HasColumnType("datetime2"); + + b.Property("Location") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportTypeId") + .HasColumnType("int"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Competitions"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.Participant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BirthYear") + .HasColumnType("int"); + + b.Property("CoachId") + .HasColumnType("int"); + + b.Property("CompetitionId") + .HasColumnType("int"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ParticipantName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Participants"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.SportClub", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("SportClubAddress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubEmail") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubPhone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("SportClubs"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.SportType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("SportTypeName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("SportTypes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/20240521190730_InitialCreate.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/20240521190730_InitialCreate.cs new file mode 100644 index 0000000..ee389fa --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/20240521190730_InitialCreate.cs @@ -0,0 +1,114 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace SportCompetitionsDatabaseImplement.Migrations +{ + /// + public partial class InitialCreate : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Coaches", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CoachName = table.Column(type: "nvarchar(max)", nullable: false), + BirthYear = table.Column(type: "int", nullable: false), + Country = table.Column(type: "nvarchar(max)", nullable: false), + SportClubId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Coaches", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Competitions", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CompetitionName = table.Column(type: "nvarchar(max)", nullable: false), + StartDate = table.Column(type: "datetime2", nullable: false), + EndDate = table.Column(type: "datetime2", nullable: false), + Location = table.Column(type: "nvarchar(max)", nullable: false), + SportTypeId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Competitions", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Participants", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ParticipantName = table.Column(type: "nvarchar(max)", nullable: false), + BirthYear = table.Column(type: "int", nullable: false), + Gender = table.Column(type: "nvarchar(max)", nullable: false), + Country = table.Column(type: "nvarchar(max)", nullable: false), + CoachId = table.Column(type: "int", nullable: false), + CompetitionId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Participants", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SportClubs", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SportClubName = table.Column(type: "nvarchar(max)", nullable: false), + SportClubAddress = table.Column(type: "nvarchar(max)", nullable: false), + SportClubEmail = table.Column(type: "nvarchar(max)", nullable: false), + SportClubPhone = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SportClubs", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "SportTypes", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + SportTypeName = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SportTypes", x => x.Id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Coaches"); + + migrationBuilder.DropTable( + name: "Competitions"); + + migrationBuilder.DropTable( + name: "Participants"); + + migrationBuilder.DropTable( + name: "SportClubs"); + + migrationBuilder.DropTable( + name: "SportTypes"); + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/SportCompetitionsDatabaseModelSnapshot.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/SportCompetitionsDatabaseModelSnapshot.cs new file mode 100644 index 0000000..b4a6fc4 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Migrations/SportCompetitionsDatabaseModelSnapshot.cs @@ -0,0 +1,164 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using SportCompetitionsDatabaseImplement; + +#nullable disable + +namespace SportCompetitionsDatabaseImplement.Migrations +{ + [DbContext(typeof(SportCompetitionsDatabase))] + partial class SportCompetitionsDatabaseModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.18") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.Coach", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BirthYear") + .HasColumnType("int"); + + b.Property("CoachName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Coaches"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.Competition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CompetitionName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("EndDate") + .HasColumnType("datetime2"); + + b.Property("Location") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportTypeId") + .HasColumnType("int"); + + b.Property("StartDate") + .HasColumnType("datetime2"); + + b.HasKey("Id"); + + b.ToTable("Competitions"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.Participant", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("BirthYear") + .HasColumnType("int"); + + b.Property("CoachId") + .HasColumnType("int"); + + b.Property("CompetitionId") + .HasColumnType("int"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ParticipantName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Participants"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.SportClub", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("SportClubAddress") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubEmail") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("SportClubPhone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("SportClubs"); + }); + + modelBuilder.Entity("SportCompetitionsDatabaseImplement.Models.SportType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("SportTypeName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("SportTypes"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Coach.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Coach.cs new file mode 100644 index 0000000..4685caa --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Coach.cs @@ -0,0 +1,55 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Models +{ + public class Coach : ICoachModel + { + public int Id { get; set; } + [Required] + public string? CoachName { get; set; } = string.Empty; + [Required] + public int BirthYear { get; set; } + [Required] + public string? Country { get; set; } = string.Empty; + [Required] + public int SportClubId { get; set; } + public static Coach? Create(CoachBindingModel model) + { + if (model == null) return null; + return new Coach() + { + Id = model.Id, + CoachName = model.CoachName, + BirthYear = model.BirthYear, + Country = model.Country, + SportClubId = model.SportClubId, + }; + } + + public void Update(CoachBindingModel model) + { + if (model == null) return; + CoachName = model.CoachName; + BirthYear = model.BirthYear; + Country = model.Country; + SportClubId = model.SportClubId; + } + + public CoachViewModel GetViewModel => new() + { + Id = Id, + CoachName = CoachName, + BirthYear = BirthYear, + Country = Country, + SportClubId = SportClubId, + }; + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Competition.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Competition.cs new file mode 100644 index 0000000..0850bd9 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Competition.cs @@ -0,0 +1,60 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Models +{ + public class Competition : ICompetitionModel + { + public int Id { get; set; } + [Required] + public string? CompetitionName { get; set; } = string.Empty; + [Required] + public DateTime StartDate { get; set; } + [Required] + public DateTime EndDate { get; set; } + [Required] + public string? Location { get; set; } = string.Empty; + [Required] + public int SportTypeId { get; set; } + public static Competition? Create(CompetitionBindingModel model) + { + if (model == null) return null; + return new Competition() + { + Id = model.Id, + CompetitionName = model.CompetitionName, + StartDate = model.StartDate, + EndDate = model.EndDate, + Location = model.Location, + SportTypeId = model.SportTypeId, + }; + } + + public void Update(CompetitionBindingModel model) + { + if (model == null) return; + CompetitionName = model.CompetitionName; + StartDate = model.StartDate; + EndDate = model.EndDate; + Location = model.Location; + SportTypeId = model.SportTypeId; + } + + public CompetitionViewModel GetViewModel => new() + { + Id = Id, + CompetitionName = CompetitionName, + StartDate = StartDate, + EndDate = EndDate, + Location = Location, + SportTypeId = SportTypeId, + }; + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Participant.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Participant.cs new file mode 100644 index 0000000..de9eea8 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/Participant.cs @@ -0,0 +1,66 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.Metrics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Models +{ + public class Participant : IParticipantModel + { + public int Id { get; set; } + [Required] + public string? ParticipantName { get; set; } = string.Empty; + [Required] + public int BirthYear { get; set; } + [Required] + public string? Gender { get; set; } = string.Empty; + [Required] + public string? Country { get; set; } = string.Empty; + [Required] + public int CoachId { get; set; } + [Required] + public int CompetitionId { get; set; } + public static Participant? Create(ParticipantBindingModel model) + { + if (model == null) return null; + return new Participant() + { + Id = model.Id, + ParticipantName = model.ParticipantName, + BirthYear = model.BirthYear, + Gender = model.Gender, + Country = model.Country, + CoachId = model.CoachId, + CompetitionId = model.CompetitionId, + }; + } + + public void Update(ParticipantBindingModel model) + { + if (model == null) return; + ParticipantName = model.ParticipantName; + BirthYear = model.BirthYear; + Gender = model.Gender; + Country = model.Country; + CoachId = model.CoachId; + CompetitionId = model.CompetitionId; + } + + public ParticipantViewModel GetViewModel => new() + { + Id = Id, + ParticipantName = ParticipantName, + BirthYear = BirthYear, + Gender = Gender, + Country = Country, + CoachId = CoachId, + CompetitionId = CompetitionId, + }; + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Models/SportClub.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/SportClub.cs new file mode 100644 index 0000000..36a6371 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/SportClub.cs @@ -0,0 +1,57 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Models +{ + public class SportClub : ISportClubModel + { + public int Id { get; set; } + [Required] + public string? SportClubName { get; set; } = string.Empty; + [Required] + public string? SportClubAddress { get; set; } = string.Empty; + [Required] + public string? SportClubEmail { get; set; } = string.Empty; + [Required] + public string? SportClubPhone { get; set; } = string.Empty; + + public static SportClub? Create(SportClubBindingModel model) + { + if (model == null) return null; + return new SportClub() + { + Id = model.Id, + SportClubName = model.SportClubName, + SportClubAddress = model.SportClubAddress, + SportClubEmail = model.SportClubEmail, + SportClubPhone = model.SportClubPhone, + }; + } + + public void Update(SportClubBindingModel model) + { + if (model == null) return; + SportClubName = model.SportClubName; + SportClubAddress = model.SportClubAddress; + SportClubEmail = model.SportClubEmail; + SportClubPhone = model.SportClubPhone; + } + + public SportClubViewModel GetViewModel => new() + { + Id = Id, + SportClubName = SportClubName, + SportClubAddress = SportClubAddress, + SportClubEmail = SportClubEmail, + SportClubPhone = SportClubPhone, + + }; + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/Models/SportType.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/SportType.cs new file mode 100644 index 0000000..8535de9 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/Models/SportType.cs @@ -0,0 +1,40 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.ViewModels; +using SportCompetitionsDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement.Models +{ + public class SportType : ISportTypeModel + { + public int Id { get; set; } + [Required] + public string? SportTypeName { get; set; } = string.Empty; + public static SportType? Create(SportTypeBindingModel model) + { + if (model == null) return null; + return new SportType() + { + Id = model.Id, + SportTypeName = model.SportTypeName, + }; + } + + public void Update(SportTypeBindingModel model) + { + if (model == null) return; + SportTypeName = model.SportTypeName; + } + + public SportTypeViewModel GetViewModel => new() + { + Id = Id, + SportTypeName = SportTypeName, + }; + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/SportCompetitionDatabase.cs b/SportCompetitions/SportCompetitionsDatabaseImplement/SportCompetitionDatabase.cs new file mode 100644 index 0000000..8a22db6 --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/SportCompetitionDatabase.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore; +using SportCompetitionsDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SportCompetitionsDatabaseImplement +{ + public class SportCompetitionsDatabase : DbContext + { + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (optionsBuilder.IsConfigured == false) + { + optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-1DE5E8N\SQLEXPRESS;Initial Catalog=SportCompetitions; + Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); + } + base.OnConfiguring(optionsBuilder); + } + public virtual DbSet Competitions { get; set; } + public virtual DbSet Coaches { get; set; } + public virtual DbSet Participants { get; set; } + public virtual DbSet SportTypes { get; set; } + public virtual DbSet SportClubs { get; set; } + } +} diff --git a/SportCompetitions/SportCompetitionsDatabaseImplement/SportCompetitionsDatabaseImplement.csproj b/SportCompetitions/SportCompetitionsDatabaseImplement/SportCompetitionsDatabaseImplement.csproj new file mode 100644 index 0000000..218c0af --- /dev/null +++ b/SportCompetitions/SportCompetitionsDatabaseImplement/SportCompetitionsDatabaseImplement.csproj @@ -0,0 +1,25 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + diff --git a/SportCompetitions/SportCompetitionsView/FormCoach.Designer.cs b/SportCompetitions/SportCompetitionsView/FormCoach.Designer.cs new file mode 100644 index 0000000..1bbc394 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCoach.Designer.cs @@ -0,0 +1,165 @@ +namespace SportCompetitionsView +{ + partial class FormCoach + { + /// + /// 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.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.textBoxCountry = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxBirthYear = new System.Windows.Forms.TextBox(); + this.comboBoxSportClub = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(8, 36); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(45, 20); + this.label1.TabIndex = 0; + this.label1.Text = "ФИО:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(8, 90); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(111, 20); + this.label2.TabIndex = 1; + this.label2.Text = "Год рождения:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(8, 142); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(61, 20); + this.label3.TabIndex = 2; + this.label3.Text = "Страна:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(8, 196); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(135, 20); + this.label4.TabIndex = 3; + this.label4.Text = "Спортивный клуб:"; + // + // button1 + // + this.button1.Location = new System.Drawing.Point(197, 237); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(94, 29); + this.button1.TabIndex = 4; + this.button1.Text = "Сохранить"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.buttonSave_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(319, 237); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(94, 29); + this.button2.TabIndex = 5; + this.button2.Text = "Отмена"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.buttonCancel_Click); + // + // textBoxCountry + // + this.textBoxCountry.Location = new System.Drawing.Point(153, 135); + this.textBoxCountry.Name = "textBoxCountry"; + this.textBoxCountry.Size = new System.Drawing.Size(260, 27); + this.textBoxCountry.TabIndex = 6; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(153, 36); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(260, 27); + this.textBoxName.TabIndex = 7; + // + // textBoxBirthYear + // + this.textBoxBirthYear.Location = new System.Drawing.Point(153, 83); + this.textBoxBirthYear.Name = "textBoxBirthYear"; + this.textBoxBirthYear.Size = new System.Drawing.Size(260, 27); + this.textBoxBirthYear.TabIndex = 8; + // + // comboBoxSportClub + // + this.comboBoxSportClub.FormattingEnabled = true; + this.comboBoxSportClub.Location = new System.Drawing.Point(153, 188); + this.comboBoxSportClub.Name = "comboBoxSportClub"; + this.comboBoxSportClub.Size = new System.Drawing.Size(260, 28); + this.comboBoxSportClub.TabIndex = 9; + // + // FormCoach + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(455, 289); + this.Controls.Add(this.comboBoxSportClub); + this.Controls.Add(this.textBoxBirthYear); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.textBoxCountry); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Name = "FormCoach"; + this.Text = "Тренер"; + this.Load += new System.EventHandler(this.FormCoach_Load); + this.Click += new System.EventHandler(this.FormCoach_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Button button1; + private Button button2; + private TextBox textBoxCountry; + private TextBox textBoxName; + private TextBox textBoxBirthYear; + private ComboBox comboBoxSportClub; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormCoach.cs b/SportCompetitions/SportCompetitionsView/FormCoach.cs new file mode 100644 index 0000000..e4030f9 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCoach.cs @@ -0,0 +1,83 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.ViewModels; +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; + +namespace SportCompetitionsView +{ + public partial class FormCoach : Form + { + private readonly ICoachLogic _logic; + private readonly ISportTypeLogic _logicST; + private readonly List? _list; + private int? _id; + + public int Id + { + set { _id = value; } + } + public FormCoach(ICoachLogic logic, ISportTypeLogic logicST) + { + InitializeComponent(); + _logic = logic; + _logicST = logicST; + } + private void FormCoach_Load(object sender, EventArgs e) + { + var _list = _logicST.ReadList(null); + if (_list != null) + { + comboBoxSportClub.DisplayMember = "SportClubName"; + comboBoxSportClub.ValueMember = "Id"; + comboBoxSportClub.DataSource = _list; + comboBoxSportClub.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните Имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + try + { + var model = new CoachBindingModel + { + Id = _id ?? 0, + CoachName = textBoxName.Text, + BirthYear = Convert.ToInt32(textBoxBirthYear.Text), + Country = textBoxCountry.Text, + SportClubId = comboBoxSportClub.SelectedIndex + 1, + }; + 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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormCoach.resx b/SportCompetitions/SportCompetitionsView/FormCoach.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCoach.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormCoaches.Designer.cs b/SportCompetitions/SportCompetitionsView/FormCoaches.Designer.cs new file mode 100644 index 0000000..3895013 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCoaches.Designer.cs @@ -0,0 +1,107 @@ +namespace SportCompetitionsView +{ + partial class FormCoaches + { + /// + /// 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.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(1, 0); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(628, 481); + this.dataGridView1.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(660, 22); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 36); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(660, 79); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 36); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(660, 138); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 36); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // FormCoaches + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(786, 484); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCoaches"; + this.Text = "Тренеры"; + this.Click += new System.EventHandler(this.FormCoaches_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormCoaches.cs b/SportCompetitions/SportCompetitionsView/FormCoaches.cs new file mode 100644 index 0000000..4a5e72e --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCoaches.cs @@ -0,0 +1,99 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +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; + +namespace SportCompetitionsView +{ + public partial class FormCoaches : Form + { + private readonly ICoachLogic _logic; + + public FormCoaches(ICoachLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormCoaches_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["CoachName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCoach)); + if (service is FormCoach form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCoach)); + if (service is FormCoach form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new CoachBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах"); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormCoaches.resx b/SportCompetitions/SportCompetitionsView/FormCoaches.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCoaches.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormCompetition.Designer.cs b/SportCompetitions/SportCompetitionsView/FormCompetition.Designer.cs new file mode 100644 index 0000000..610147e --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCompetition.Designer.cs @@ -0,0 +1,185 @@ +namespace SportCompetitionsView +{ + partial class FormCompetition + { + /// + /// 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.dateTimePicker2 = new System.Windows.Forms.DateTimePicker(); + this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker(); + this.labelName = new System.Windows.Forms.Label(); + this.labelStart = new System.Windows.Forms.Label(); + this.labelEnd = new System.Windows.Forms.Label(); + this.labelLocation = new System.Windows.Forms.Label(); + this.textBoxLocation = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.comboBoxSportType = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // dateTimePicker2 + // + this.dateTimePicker2.Location = new System.Drawing.Point(183, 132); + this.dateTimePicker2.Name = "dateTimePicker2"; + this.dateTimePicker2.Size = new System.Drawing.Size(325, 27); + this.dateTimePicker2.TabIndex = 0; + // + // dateTimePicker1 + // + this.dateTimePicker1.Location = new System.Drawing.Point(183, 73); + this.dateTimePicker1.Name = "dateTimePicker1"; + this.dateTimePicker1.Size = new System.Drawing.Size(325, 27); + this.dateTimePicker1.TabIndex = 1; + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(16, 24); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 2; + this.labelName.Text = "Название:"; + // + // labelStart + // + this.labelStart.AutoSize = true; + this.labelStart.Location = new System.Drawing.Point(16, 80); + this.labelStart.Name = "labelStart"; + this.labelStart.Size = new System.Drawing.Size(97, 20); + this.labelStart.TabIndex = 3; + this.labelStart.Text = "Дата начала:"; + // + // labelEnd + // + this.labelEnd.AutoSize = true; + this.labelEnd.Location = new System.Drawing.Point(16, 139); + this.labelEnd.Name = "labelEnd"; + this.labelEnd.Size = new System.Drawing.Size(124, 20); + this.labelEnd.TabIndex = 4; + this.labelEnd.Text = "Дата окончания:"; + // + // labelLocation + // + this.labelLocation.AutoSize = true; + this.labelLocation.Location = new System.Drawing.Point(16, 196); + this.labelLocation.Name = "labelLocation"; + this.labelLocation.Size = new System.Drawing.Size(72, 20); + this.labelLocation.TabIndex = 5; + this.labelLocation.Text = "Локация:"; + // + // textBoxLocation + // + this.textBoxLocation.Location = new System.Drawing.Point(183, 189); + this.textBoxLocation.Name = "textBoxLocation"; + this.textBoxLocation.Size = new System.Drawing.Size(325, 27); + this.textBoxLocation.TabIndex = 6; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(183, 17); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(325, 27); + this.textBoxName.TabIndex = 7; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(290, 275); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(126, 29); + this.buttonSave.TabIndex = 8; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(433, 275); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(126, 29); + this.buttonCancel.TabIndex = 9; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(12, 246); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(90, 20); + this.label1.TabIndex = 10; + this.label1.Text = "Вид спорта:"; + // + // comboBoxSportType + // + this.comboBoxSportType.FormattingEnabled = true; + this.comboBoxSportType.Location = new System.Drawing.Point(183, 238); + this.comboBoxSportType.Name = "comboBoxSportType"; + this.comboBoxSportType.Size = new System.Drawing.Size(325, 28); + this.comboBoxSportType.TabIndex = 11; + // + // FormCompetition + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(571, 312); + this.Controls.Add(this.comboBoxSportType); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.textBoxLocation); + this.Controls.Add(this.labelLocation); + this.Controls.Add(this.labelEnd); + this.Controls.Add(this.labelStart); + this.Controls.Add(this.labelName); + this.Controls.Add(this.dateTimePicker1); + this.Controls.Add(this.dateTimePicker2); + this.Name = "FormCompetition"; + this.Text = "Соревнование"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DateTimePicker dateTimePicker2; + private DateTimePicker dateTimePicker1; + private Label labelName; + private Label labelStart; + private Label labelEnd; + private Label labelLocation; + private TextBox textBoxLocation; + private TextBox textBoxName; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private ComboBox comboBoxSportType; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormCompetition.cs b/SportCompetitions/SportCompetitionsView/FormCompetition.cs new file mode 100644 index 0000000..f5209d0 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCompetition.cs @@ -0,0 +1,83 @@ +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 SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; + +namespace SportCompetitionsView +{ + public partial class FormCompetition : Form + { + private readonly ICompetitionLogic _logic; + private readonly ISportTypeLogic _logicST; + private int? _id; + + public int Id + { + set { _id = value; } + } + public FormCompetition(ICompetitionLogic logic, ISportTypeLogic logicST) + { + InitializeComponent(); + _logic = logic; + _logicST = logicST; + } + private void FormCompetition_Load(object sender, EventArgs e) + { + var _listR = _logicST.ReadList(null); + if (_listR != null) + { + comboBoxSportType.DisplayMember = "SportTypeName"; + comboBoxSportType.ValueMember = "Id"; + comboBoxSportType.DataSource = _listR; + comboBoxSportType.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните Имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + try + { + var model = new CompetitionBindingModel + { + Id = _id ?? 0, + CompetitionName = textBoxName.Text, + StartDate = dateTimePicker1.Value, + EndDate = dateTimePicker2.Value, + Location = textBoxLocation.Text, + SportTypeId = comboBoxSportType.SelectedIndex + 1, + }; + 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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormCompetition.resx b/SportCompetitions/SportCompetitionsView/FormCompetition.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCompetition.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormCompetitions.Designer.cs b/SportCompetitions/SportCompetitionsView/FormCompetitions.Designer.cs new file mode 100644 index 0000000..e20edaf --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCompetitions.Designer.cs @@ -0,0 +1,107 @@ +namespace SportCompetitionsView +{ + partial class FormCompetitions + { + /// + /// 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.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(1, 0); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(628, 481); + this.dataGridView1.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(660, 22); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 36); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(660, 79); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 36); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(660, 138); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 36); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // FormCompetitions + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(786, 484); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormCompetitions"; + this.Text = "Соревнования"; + this.Click += new System.EventHandler(this.FormCompetitions_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormCompetitions.cs b/SportCompetitions/SportCompetitionsView/FormCompetitions.cs new file mode 100644 index 0000000..e6baf7a --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCompetitions.cs @@ -0,0 +1,99 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +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; + +namespace SportCompetitionsView +{ + public partial class FormCompetitions : Form + { + private readonly ICompetitionLogic _logic; + public FormCompetitions(ICompetitionLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormCompetitions_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["CompetitionName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["StartDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["EndDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView1.Columns["Location"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCompetition)); + if (service is FormCompetition form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCompetition)); + if (service is FormCompetition form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new CompetitionBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах"); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormCompetitions.resx b/SportCompetitions/SportCompetitionsView/FormCompetitions.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormCompetitions.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormMain.Designer.cs b/SportCompetitions/SportCompetitionsView/FormMain.Designer.cs new file mode 100644 index 0000000..72dcd9c --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormMain.Designer.cs @@ -0,0 +1,135 @@ +namespace SportCompetitionsView +{ + 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() + { + this.menuStrip1 = new System.Windows.Forms.MenuStrip(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripMenuItem(); + this.мемберToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.рекордыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonCompetitions = new System.Windows.Forms.Button(); + this.menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // menuStrip1 + // + this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); + this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.toolStripMenuItem1, + this.toolStripMenuItem2, + this.мемберToolStripMenuItem, + this.рекордыToolStripMenuItem}); + this.menuStrip1.Location = new System.Drawing.Point(0, 0); + this.menuStrip1.Name = "menuStrip1"; + this.menuStrip1.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3); + this.menuStrip1.Size = new System.Drawing.Size(1054, 30); + this.menuStrip1.TabIndex = 1; + this.menuStrip1.Text = "menuStrip1"; + // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(95, 24); + this.toolStripMenuItem1.Text = "Участники"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.ParticipantsToolStripMenuItem_Click); + // + // toolStripMenuItem2 + // + this.toolStripMenuItem2.Name = "toolStripMenuItem2"; + this.toolStripMenuItem2.Size = new System.Drawing.Size(85, 24); + this.toolStripMenuItem2.Text = "Тренеры"; + this.toolStripMenuItem2.Click += new System.EventHandler(this.CoachesToolStripMenuItem_Click); + // + // мемберToolStripMenuItem + // + this.мемберToolStripMenuItem.Name = "мемберToolStripMenuItem"; + this.мемберToolStripMenuItem.Size = new System.Drawing.Size(101, 24); + this.мемберToolStripMenuItem.Text = "Вид спорта"; + this.мемберToolStripMenuItem.Click += new System.EventHandler(this.SportTypesToolStripMenuItem_Click); + // + // рекордыToolStripMenuItem + // + this.рекордыToolStripMenuItem.Name = "рекордыToolStripMenuItem"; + this.рекордыToolStripMenuItem.Size = new System.Drawing.Size(146, 24); + this.рекордыToolStripMenuItem.Text = "Спортивный клуб"; + this.рекордыToolStripMenuItem.Click += new System.EventHandler(this.SportClubsToolStripMenuItem_Click); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 47); + this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(853, 364); + this.dataGridView.TabIndex = 9; + // + // buttonCompetitions + // + this.buttonCompetitions.Location = new System.Drawing.Point(871, 84); + this.buttonCompetitions.Name = "buttonCompetitions"; + this.buttonCompetitions.Size = new System.Drawing.Size(171, 54); + this.buttonCompetitions.TabIndex = 10; + this.buttonCompetitions.Text = "Создать соревнование"; + this.buttonCompetitions.UseVisualStyleBackColor = true; + this.buttonCompetitions.Click += new System.EventHandler(this.ButtonCreateCompetition_Click); + // + // FormMain + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(1054, 553); + this.Controls.Add(this.buttonCompetitions); + this.Controls.Add(this.dataGridView); + this.Controls.Add(this.menuStrip1); + this.MainMenuStrip = this.menuStrip1; + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormMain"; + this.Text = "ГлавнаяФорма"; + this.menuStrip1.ResumeLayout(false); + this.menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private MenuStrip menuStrip1; + private ToolStripMenuItem toolStripMenuItem1; + private ToolStripMenuItem toolStripMenuItem2; + private ToolStripMenuItem мемберToolStripMenuItem; + private ToolStripMenuItem рекордыToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCompetitions; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormMain.cs b/SportCompetitions/SportCompetitionsView/FormMain.cs new file mode 100644 index 0000000..0b03b80 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormMain.cs @@ -0,0 +1,108 @@ +using Microsoft.Extensions.Logging; +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsDatabaseImplement; +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; + +namespace SportCompetitionsView +{ + public partial class FormMain : Form + { + private readonly ILogger _logger; + private ICompetitionLogic _logicC; + private ISportTypeLogic _logicT; + public FormMain(ILogger logger, ISportTypeLogic logicT, ICompetitionLogic logicC) + { + InitializeComponent(); + _logger = logger; + _logicT = logicT; + _logicC = logicC; + } + private void LoadData() + { + try + { + var list = _logicC.ReadList(null); + var listT = _logicT.ReadList(null); + if (list != null && listT != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["SportTypeId"].Visible = false; + dataGridView.Columns["SportTypeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["CompetitionId"].Visible = false; + dataGridView.Columns["CompetitionName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["StartDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["EndDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка соревнований"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CompetitionToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCompetitions)); + if (service is FormCompetitions form) + { + form.ShowDialog(); + } + } + + private void SportTypesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSportTypes)); + if (service is FormSportTypes form) + { + form.ShowDialog(); + } + } + + private void ParticipantsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormParticipants)); + if (service is FormParticipants form) + { + form.ShowDialog(); + } + } + private void CoachesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCoaches)); + if (service is FormCoaches form) + { + form.ShowDialog(); + } + } + + private void SportClubsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSportClubs)); + if (service is FormSportClubs form) + { + form.ShowDialog(); + } + } + private void ButtonCreateCompetition_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormCompetition)); + if (service is FormCompetition form) + { + form.ShowDialog(); + LoadData(); + } + } + + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormMain.resx b/SportCompetitions/SportCompetitionsView/FormMain.resx new file mode 100644 index 0000000..05252e7 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormMain.resx @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 25 + + \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormParticipant.Designer.cs b/SportCompetitions/SportCompetitionsView/FormParticipant.Designer.cs new file mode 100644 index 0000000..7ec13e2 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormParticipant.Designer.cs @@ -0,0 +1,209 @@ +namespace SportCompetitionsView +{ + partial class FormParticipant + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.comboBoxCoach = new System.Windows.Forms.ComboBox(); + this.comboBoxCompetition = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); + this.label6 = new System.Windows.Forms.Label(); + this.textBoxGender = new System.Windows.Forms.TextBox(); + this.textBoxCountry = new System.Windows.Forms.TextBox(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxBirthYear = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(251, 370); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(367, 370); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // comboBoxCoach + // + this.comboBoxCoach.FormattingEnabled = true; + this.comboBoxCoach.Location = new System.Drawing.Point(171, 263); + this.comboBoxCoach.Name = "comboBoxCoach"; + this.comboBoxCoach.Size = new System.Drawing.Size(290, 28); + this.comboBoxCoach.TabIndex = 2; + // + // comboBoxCompetition + // + this.comboBoxCompetition.FormattingEnabled = true; + this.comboBoxCompetition.Location = new System.Drawing.Point(171, 321); + this.comboBoxCompetition.Name = "comboBoxCompetition"; + this.comboBoxCompetition.Size = new System.Drawing.Size(290, 28); + this.comboBoxCompetition.TabIndex = 3; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(16, 51); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(45, 20); + this.label1.TabIndex = 4; + this.label1.Text = "ФИО:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(16, 107); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(111, 20); + this.label2.TabIndex = 5; + this.label2.Text = "Год рождения:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(16, 155); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(61, 20); + this.label3.TabIndex = 6; + this.label3.Text = "Страна:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(16, 213); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(40, 20); + this.label4.TabIndex = 7; + this.label4.Text = "Пол:"; + // + // label5 + // + this.label5.AutoSize = true; + this.label5.Location = new System.Drawing.Point(16, 271); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(63, 20); + this.label5.TabIndex = 8; + this.label5.Text = "Тренер:"; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Location = new System.Drawing.Point(16, 329); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(115, 20); + this.label6.TabIndex = 9; + this.label6.Text = "Соревнование:"; + // + // textBoxGender + // + this.textBoxGender.Location = new System.Drawing.Point(171, 206); + this.textBoxGender.Name = "textBoxGender"; + this.textBoxGender.Size = new System.Drawing.Size(290, 27); + this.textBoxGender.TabIndex = 10; + // + // textBoxCountry + // + this.textBoxCountry.Location = new System.Drawing.Point(171, 155); + this.textBoxCountry.Name = "textBoxCountry"; + this.textBoxCountry.Size = new System.Drawing.Size(290, 27); + this.textBoxCountry.TabIndex = 11; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(171, 51); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(290, 27); + this.textBoxName.TabIndex = 12; + // + // textBoxBirthYear + // + this.textBoxBirthYear.Location = new System.Drawing.Point(171, 100); + this.textBoxBirthYear.Name = "textBoxBirthYear"; + this.textBoxBirthYear.Size = new System.Drawing.Size(290, 27); + this.textBoxBirthYear.TabIndex = 13; + // + // FormParticipant + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(478, 414); + this.Controls.Add(this.textBoxBirthYear); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.textBoxCountry); + this.Controls.Add(this.textBoxGender); + this.Controls.Add(this.label6); + this.Controls.Add(this.label5); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBoxCompetition); + this.Controls.Add(this.comboBoxCoach); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormParticipant"; + this.Text = "Участник"; + this.Load += new System.EventHandler(this.FormParticipant_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxCoach; + private ComboBox comboBoxCompetition; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private Label label6; + private TextBox textBoxGender; + private TextBox textBoxCountry; + private TextBox textBoxName; + private TextBox textBoxBirthYear; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormParticipant.cs b/SportCompetitions/SportCompetitionsView/FormParticipant.cs new file mode 100644 index 0000000..e1ff22a --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormParticipant.cs @@ -0,0 +1,93 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +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; + +namespace SportCompetitionsView +{ + public partial class FormParticipant : Form + { + private readonly IParticipantLogic _logic; + private readonly ICoachLogic _logicC; + private readonly ICompetitionLogic _logicCN; + private int? _id; + + public int Id + { + set { _id = value; } + } + public FormParticipant(IParticipantLogic logic, ICoachLogic logicC, ICompetitionLogic logicCN) + { + InitializeComponent(); + _logic = logic; + _logicC = logicC; + _logicCN = logicCN; + } + private void FormParticipant_Load(object sender, EventArgs e) + { + var _listP = _logicC.ReadList(null); + if (_listP != null) + { + comboBoxCoach.DisplayMember = "CoachName"; + comboBoxCoach.ValueMember = "Id"; + comboBoxCoach.DataSource = _listP; + comboBoxCoach.SelectedItem = null; + } + var _listR = _logicCN.ReadList(null); + if (_listR != null) + { + comboBoxCompetition.DisplayMember = "CompetitionName"; + comboBoxCompetition.ValueMember = "Id"; + comboBoxCompetition.DataSource = _listR; + comboBoxCompetition.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните Имя", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + + return; + } + try + { + var model = new ParticipantBindingModel + { + Id = _id ?? 0, + ParticipantName = textBoxName.Text, + BirthYear = Convert.ToInt32(textBoxBirthYear.Text), + Country = textBoxCountry.Text, + Gender = textBoxGender.Text, + CoachId = comboBoxCoach.SelectedIndex + 1, + CompetitionId = comboBoxCompetition.SelectedIndex + 1 + }; + 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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormParticipant.resx b/SportCompetitions/SportCompetitionsView/FormParticipant.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormParticipant.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormParticipants.Designer.cs b/SportCompetitions/SportCompetitionsView/FormParticipants.Designer.cs new file mode 100644 index 0000000..2eb6ca3 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormParticipants.Designer.cs @@ -0,0 +1,107 @@ +namespace SportCompetitionsView +{ + partial class FormParticipants + { + /// + /// 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.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(1, 0); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(628, 481); + this.dataGridView1.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(660, 22); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 36); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(660, 79); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 36); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(660, 138); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 36); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // FormParticipants + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(786, 484); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormParticipants"; + this.Text = "Участники"; + this.Click += new System.EventHandler(this.FormParticipants_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormParticipants.cs b/SportCompetitions/SportCompetitionsView/FormParticipants.cs new file mode 100644 index 0000000..602daa9 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormParticipants.cs @@ -0,0 +1,99 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +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; + +namespace SportCompetitionsView +{ + public partial class FormParticipants : Form + { + private readonly IParticipantLogic _logic; + + public FormParticipants(IParticipantLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormParticipants_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["ParticipantName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormParticipant)); + if (service is FormParticipant form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormParticipant)); + if (service is FormParticipant form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new ParticipantBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах"); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormParticipants.resx b/SportCompetitions/SportCompetitionsView/FormParticipants.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormParticipants.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormSportClub.Designer.cs b/SportCompetitions/SportCompetitionsView/FormSportClub.Designer.cs new file mode 100644 index 0000000..c985f88 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportClub.Designer.cs @@ -0,0 +1,163 @@ +namespace SportCompetitionsView +{ + partial class FormSportClub + { + /// + /// 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.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.textBoxAddress = new System.Windows.Forms.TextBox(); + this.textBoxPhone = new System.Windows.Forms.TextBox(); + this.textBoxEmail = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(277, 273); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 0; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(395, 273); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 1; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(16, 220); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(51, 20); + this.label1.TabIndex = 2; + this.label1.Text = "Почта"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(16, 59); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(80, 20); + this.label2.TabIndex = 3; + this.label2.Text = "Название:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(16, 118); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(54, 20); + this.label3.TabIndex = 4; + this.label3.Text = "Адрес:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(16, 168); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(69, 20); + this.label4.TabIndex = 5; + this.label4.Text = "Телефон"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(137, 52); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(323, 27); + this.textBoxName.TabIndex = 6; + // + // textBoxAddress + // + this.textBoxAddress.Location = new System.Drawing.Point(137, 111); + this.textBoxAddress.Name = "textBoxAddress"; + this.textBoxAddress.Size = new System.Drawing.Size(323, 27); + this.textBoxAddress.TabIndex = 7; + // + // textBoxPhone + // + this.textBoxPhone.Location = new System.Drawing.Point(137, 161); + this.textBoxPhone.Name = "textBoxPhone"; + this.textBoxPhone.Size = new System.Drawing.Size(323, 27); + this.textBoxPhone.TabIndex = 8; + // + // textBoxEmail + // + this.textBoxEmail.Location = new System.Drawing.Point(137, 213); + this.textBoxEmail.Name = "textBoxEmail"; + this.textBoxEmail.Size = new System.Drawing.Size(323, 27); + this.textBoxEmail.TabIndex = 9; + // + // FormSportClub + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(501, 314); + this.Controls.Add(this.textBoxEmail); + this.Controls.Add(this.textBoxPhone); + this.Controls.Add(this.textBoxAddress); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.label4); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Name = "FormSportClub"; + this.Text = "Спортивный клуб"; + this.Load += new System.EventHandler(this.FormSportClub_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private TextBox textBoxName; + private TextBox textBoxAddress; + private TextBox textBoxPhone; + private TextBox textBoxEmail; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormSportClub.cs b/SportCompetitions/SportCompetitionsView/FormSportClub.cs new file mode 100644 index 0000000..d3a05fa --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportClub.cs @@ -0,0 +1,88 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; +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; + +namespace SportCompetitionsView +{ + public partial class FormSportClub : Form + { + private ISportClubLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormSportClub(ISportClubLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormSportClub_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new SportClubSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.SportClubName; + textBoxAddress.Text = view.SportClubAddress; + textBoxPhone.Text = view.SportClubPhone; + textBoxEmail.Text = view.SportClubEmail; + + } + } + catch (Exception 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; + } + try + { + var model = new SportClubBindingModel + { + Id = _id ?? 0, + SportClubName = textBoxName.Text, + SportClubAddress = textBoxAddress.Text, + SportClubPhone = textBoxPhone.Text, + SportClubEmail = textBoxEmail.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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormSportClub.resx b/SportCompetitions/SportCompetitionsView/FormSportClub.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportClub.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormSportClubs.Designer.cs b/SportCompetitions/SportCompetitionsView/FormSportClubs.Designer.cs new file mode 100644 index 0000000..93cbe79 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportClubs.Designer.cs @@ -0,0 +1,107 @@ +namespace SportCompetitionsView +{ + partial class FormSportClubs + { + /// + /// 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.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(1, 0); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(628, 481); + this.dataGridView1.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(660, 22); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 36); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(660, 79); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 36); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(660, 138); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 36); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // FormSportClubs + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(786, 484); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormSportClubs"; + this.Text = "Спортивные клубы"; + this.Load += new System.EventHandler(this.FormSportClubs_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormSportClubs.cs b/SportCompetitions/SportCompetitionsView/FormSportClubs.cs new file mode 100644 index 0000000..eea8bfe --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportClubs.cs @@ -0,0 +1,99 @@ +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 SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; + +namespace SportCompetitionsView +{ + public partial class FormSportClubs : Form + { + private readonly ISportClubLogic _logic; + + public FormSportClubs(ISportClubLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void FormSportClubs_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["SportClubName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSportClub)); + if (service is FormSportClub form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSportClub)); + if (service is FormSportClub form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new SportClubBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах"); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormSportClubs.resx b/SportCompetitions/SportCompetitionsView/FormSportClubs.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportClubs.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormSportType.Designer.cs b/SportCompetitions/SportCompetitionsView/FormSportType.Designer.cs new file mode 100644 index 0000000..8c9ea10 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportType.Designer.cs @@ -0,0 +1,96 @@ +namespace SportCompetitionsView +{ + partial class FormSportType + { + /// + /// 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.labelName = new System.Windows.Forms.Label(); + this.textBoxName = new System.Windows.Forms.TextBox(); + this.buttonSave = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelName + // + this.labelName.AutoSize = true; + this.labelName.Location = new System.Drawing.Point(12, 29); + this.labelName.Name = "labelName"; + this.labelName.Size = new System.Drawing.Size(80, 20); + this.labelName.TabIndex = 0; + this.labelName.Text = "Название:"; + // + // textBoxName + // + this.textBoxName.Location = new System.Drawing.Point(103, 22); + this.textBoxName.Name = "textBoxName"; + this.textBoxName.Size = new System.Drawing.Size(230, 27); + this.textBoxName.TabIndex = 1; + // + // buttonSave + // + this.buttonSave.Location = new System.Drawing.Point(103, 77); + this.buttonSave.Name = "buttonSave"; + this.buttonSave.Size = new System.Drawing.Size(94, 29); + this.buttonSave.TabIndex = 2; + this.buttonSave.Text = "Сохранить"; + this.buttonSave.UseVisualStyleBackColor = true; + this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(222, 77); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormSportType + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(345, 142); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSave); + this.Controls.Add(this.textBoxName); + this.Controls.Add(this.labelName); + this.Name = "FormSportType"; + this.Text = "Вид спорта"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormSportType.cs b/SportCompetitions/SportCompetitionsView/FormSportType.cs new file mode 100644 index 0000000..68e856b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportType.cs @@ -0,0 +1,80 @@ +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.SearchModels; +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; + +namespace SportCompetitionsView +{ + public partial class FormSportType : Form + { + private ISportTypeLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormSportType(ISportTypeLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormSportType_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new SportTypeSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.SportTypeName; + } + } + catch (Exception 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; + } + try + { + var model = new SportTypeBindingModel + { + Id = _id ?? 0, + SportTypeName = textBoxName.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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormSportType.resx b/SportCompetitions/SportCompetitionsView/FormSportType.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportType.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/FormSportTypes.Designer.cs b/SportCompetitions/SportCompetitionsView/FormSportTypes.Designer.cs new file mode 100644 index 0000000..2dfe9aa --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportTypes.Designer.cs @@ -0,0 +1,107 @@ +namespace SportCompetitionsView +{ + partial class FormSportTypes + { + /// + /// 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.dataGridView1 = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonEdit = new System.Windows.Forms.Button(); + this.buttonDel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView1 + // + this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView1.Location = new System.Drawing.Point(1, 0); + this.dataGridView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.dataGridView1.Name = "dataGridView1"; + this.dataGridView1.RowHeadersWidth = 51; + this.dataGridView1.RowTemplate.Height = 25; + this.dataGridView1.Size = new System.Drawing.Size(628, 481); + this.dataGridView1.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(660, 22); + this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(110, 36); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonEdit + // + this.buttonEdit.Location = new System.Drawing.Point(660, 79); + this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonEdit.Name = "buttonEdit"; + this.buttonEdit.Size = new System.Drawing.Size(110, 36); + this.buttonEdit.TabIndex = 2; + this.buttonEdit.Text = "Изменить"; + this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonUpd_Click); + // + // buttonDel + // + this.buttonDel.Location = new System.Drawing.Point(660, 138); + this.buttonDel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonDel.Name = "buttonDel"; + this.buttonDel.Size = new System.Drawing.Size(110, 36); + this.buttonDel.TabIndex = 3; + this.buttonDel.Text = "Удалить"; + this.buttonDel.UseVisualStyleBackColor = true; + this.buttonDel.Click += new System.EventHandler(this.buttonDel_Click); + // + // FormSportTypes + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(786, 484); + this.Controls.Add(this.buttonDel); + this.Controls.Add(this.buttonEdit); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView1); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.Name = "FormSportTypes"; + this.Text = "Виды спорта"; + this.Load += new System.EventHandler(this.FormSportTypes_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonEdit; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/SportCompetitions/SportCompetitionsView/FormSportTypes.cs b/SportCompetitions/SportCompetitionsView/FormSportTypes.cs new file mode 100644 index 0000000..2055085 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportTypes.cs @@ -0,0 +1,97 @@ +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 Microsoft.EntityFrameworkCore.Diagnostics; +using SportCompetitionsContracts.BindingModels; +using SportCompetitionsContracts.BusinessLogicsContracts; + +namespace SportCompetitionsView +{ + public partial class FormSportTypes : Form + { + private readonly ISportTypeLogic _logic; + public FormSportTypes(ISportTypeLogic logic) + { + InitializeComponent(); + _logic = logic; + } + public void FormSportTypes_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView1.DataSource = list; + dataGridView1.Columns["SportTypeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSportType)); + if (service is FormSportType form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSportType)); + if (service is FormSportType form) + { + form.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView1.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new SportTypeBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Доп информация в логах"); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/SportCompetitions/SportCompetitionsView/FormSportTypes.resx b/SportCompetitions/SportCompetitionsView/FormSportTypes.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/FormSportTypes.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SportCompetitions/SportCompetitionsView/Program.cs b/SportCompetitions/SportCompetitionsView/Program.cs new file mode 100644 index 0000000..176f370 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/Program.cs @@ -0,0 +1,69 @@ +using System; +using Microsoft.Extensions.DependencyInjection; +using SportCompetitionsBusinessLogic.BusinessLogics; +using SportCompetitionsContracts.BusinessLogicsContracts; +using SportCompetitionsContracts.StoragesContracts; +using SportCompetitionsDatabaseImplement.Implements; +using NLog.Extensions.Logging; +using Microsoft.Extensions.Logging; + +namespace SportCompetitionsView +{ + 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(); + + 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/SportCompetitions/SportCompetitionsView/Properties/Resources.Designer.cs b/SportCompetitions/SportCompetitionsView/Properties/Resources.Designer.cs new file mode 100644 index 0000000..b4f63a8 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace SportCompetitionsView.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("SportCompetitionsView.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/SportCompetitions/SportCompetitionsView/Properties/Resources.resx b/SportCompetitions/SportCompetitionsView/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/Properties/Resources.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/SportCompetitions/SportCompetitionsView/SportCompetitionsView.csproj b/SportCompetitions/SportCompetitionsView/SportCompetitionsView.csproj new file mode 100644 index 0000000..d88c522 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/SportCompetitionsView.csproj @@ -0,0 +1,44 @@ + + + + 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/SportCompetitions/SportCompetitionsView/nlog.config b/SportCompetitions/SportCompetitionsView/nlog.config new file mode 100644 index 0000000..85797a7 --- /dev/null +++ b/SportCompetitions/SportCompetitionsView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file