From 933b919e686fda547b99159d60f51a2203b67ee5 Mon Sep 17 00:00:00 2001 From: russell Date: Wed, 29 May 2024 13:06:49 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=B2=D1=8F=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B8=20=D0=BF=D1=80=D0=BE=D1=87=D0=B0=D1=8F=20=D1=84?= =?UTF-8?q?=D0=B8=D0=B3=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ExcursionGroupBindingModel.cs | 2 + .../ViewModels/ExcursionGroupViewModel.cs | 2 + .../Models/IExcursionGroupModel.cs | 2 + .../Implements/ExcursionGroupStorage.cs | 12 ++ ... 20240529060724_InitialCreate.Designer.cs} | 48 +++++++- ...ate.cs => 20240529060724_InitialCreate.cs} | 39 +++++++ .../TravelAgencyDatabaseModelSnapshot.cs | 46 ++++++++ .../Models/ExcursionGroup.cs | 52 ++++++++- .../Models/ExcursionGroupPlace.cs | 19 +++ .../Models/Place.cs | 3 + .../TravelAgencyDatabase.cs | 2 + .../Controllers/ExcursionGroupController.cs | 70 +++++++++++- .../Controllers/HomeController.cs | 51 ++++++++- .../Views/Excursion/CreateExcursion.cshtml | 6 +- .../Views/Excursion/UpdateExcursion.cshtml | 6 +- .../ExcursionGroup/ConnectGroupToPlace.cshtml | 58 ++++++++++ .../CreateExcursionGroup.cshtml | 6 +- .../ExcursionGroup/ExcursionGroups.cshtml | 5 +- .../UpdateExcursionGroup.cshtml | 6 +- .../Views/Home/Privacy.cshtml | 6 +- .../Views/Home/ReportTourPeriod.cshtml | 14 ++- .../Views/Home/ReportTourPlace.cshtml | 4 +- .../Views/Shared/_Layout.cshtml | 7 +- .../Views/Tour/Tours.cshtml | 108 +++++++++--------- 24 files changed, 480 insertions(+), 94 deletions(-) rename TravelAgency/TravelAgencyDatabaseImplement/Migrations/{20240529001818_InitialCreate.Designer.cs => 20240529060724_InitialCreate.Designer.cs} (90%) rename TravelAgency/TravelAgencyDatabaseImplement/Migrations/{20240529001818_InitialCreate.cs => 20240529060724_InitialCreate.cs} (88%) create mode 100644 TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroupPlace.cs create mode 100644 TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ConnectGroupToPlace.cshtml diff --git a/TravelAgency/TravelAgencyContracts/BindingModels/ExcursionGroupBindingModel.cs b/TravelAgency/TravelAgencyContracts/BindingModels/ExcursionGroupBindingModel.cs index e1483b4..2fa3f7f 100644 --- a/TravelAgency/TravelAgencyContracts/BindingModels/ExcursionGroupBindingModel.cs +++ b/TravelAgency/TravelAgencyContracts/BindingModels/ExcursionGroupBindingModel.cs @@ -15,5 +15,7 @@ namespace TravelAgencyContracts.BindingModels public int GuideId { get; set; } public Dictionary ExcursionGroupTours { get; set; } = new(); + + public Dictionary ExcursionGroupPlaces { get; set; } = new(); } } diff --git a/TravelAgency/TravelAgencyContracts/ViewModels/ExcursionGroupViewModel.cs b/TravelAgency/TravelAgencyContracts/ViewModels/ExcursionGroupViewModel.cs index cc7e90b..08a3291 100644 --- a/TravelAgency/TravelAgencyContracts/ViewModels/ExcursionGroupViewModel.cs +++ b/TravelAgency/TravelAgencyContracts/ViewModels/ExcursionGroupViewModel.cs @@ -21,5 +21,7 @@ namespace TravelAgencyContracts.ViewModels public string? GuideFIO { get; set; } = string.Empty; public Dictionary ExcursionGroupTours { get; set; } = new(); + + public Dictionary ExcursionGroupPlaces { get; set; } = new(); } } diff --git a/TravelAgency/TravelAgencyDataModels/Models/IExcursionGroupModel.cs b/TravelAgency/TravelAgencyDataModels/Models/IExcursionGroupModel.cs index 10d2996..298a7ed 100644 --- a/TravelAgency/TravelAgencyDataModels/Models/IExcursionGroupModel.cs +++ b/TravelAgency/TravelAgencyDataModels/Models/IExcursionGroupModel.cs @@ -11,5 +11,7 @@ int GuideId { get; } Dictionary ExcursionGroupTours { get; } + + Dictionary ExcursionGroupPlaces { get; } } } diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Implements/ExcursionGroupStorage.cs b/TravelAgency/TravelAgencyDatabaseImplement/Implements/ExcursionGroupStorage.cs index 1eccb28..c11864a 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/Implements/ExcursionGroupStorage.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/Implements/ExcursionGroupStorage.cs @@ -17,6 +17,8 @@ namespace TravelAgencyDatabaseImplement.Implements .Include(x => x.Guide) .Include(x => x.Tours) .ThenInclude(x => x.Tour) + .Include(x => x.Places) + .ThenInclude(x => x.Place) .ToList() .Select(x => x.GetViewModel) .ToList(); @@ -32,6 +34,8 @@ namespace TravelAgencyDatabaseImplement.Implements .Include(x => x.Guide) .Include(x => x.Tours) .ThenInclude(x => x.Tour) + .Include(x => x.Places) + .ThenInclude(x => x.Place) .Where(x => x.ExcursionGroupName.Contains(model.ExcursionGroupName)) .ToList() .Select(x => x.GetViewModel) @@ -44,6 +48,8 @@ namespace TravelAgencyDatabaseImplement.Implements .Include(x => x.Guide) .Include(x => x.Tours) .ThenInclude(x => x.Tour) + .Include(x => x.Places) + .ThenInclude(x => x.Place) .Where(x => x.UserId.Equals(model.UserId)) .ToList() .Select(x => x.GetViewModel) @@ -56,6 +62,8 @@ namespace TravelAgencyDatabaseImplement.Implements .Include(x => x.Guide) .Include(x => x.Tours) .ThenInclude(x => x.Tour) + .Include(x => x.Places) + .ThenInclude(x => x.Place) .Where(x => x.GuideId.Equals(model.GuideId)) .ToList() .Select(x => x.GetViewModel) @@ -76,6 +84,8 @@ namespace TravelAgencyDatabaseImplement.Implements .Include(x => x.Guide) .Include(x => x.Tours) .ThenInclude(x => x.Tour) + .Include(x => x.Places) + .ThenInclude(x => x.Place) .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ExcursionGroupName) && x.ExcursionGroupName == model.ExcursionGroupName) || (model.Id.HasValue && x.Id == model.Id)) ?.GetViewModel; @@ -108,6 +118,7 @@ namespace TravelAgencyDatabaseImplement.Implements excursionGroup.Update(model); context.SaveChanges(); excursionGroup.UpdateTours(context, model); + excursionGroup.UpdatePlaces(context, model); transaction.Commit(); return excursionGroup.GetViewModel; } @@ -123,6 +134,7 @@ namespace TravelAgencyDatabaseImplement.Implements using var context = new TravelAgencyDatabase(); var element = context.ExcursionGroups .Include(x => x.Tours) + .Include(x => x.Places) .FirstOrDefault(rec => rec.Id == model.Id); if (element != null) { diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529001818_InitialCreate.Designer.cs b/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529060724_InitialCreate.Designer.cs similarity index 90% rename from TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529001818_InitialCreate.Designer.cs rename to TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529060724_InitialCreate.Designer.cs index 843c0f7..7661044 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529001818_InitialCreate.Designer.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529060724_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using TravelAgencyDatabaseImplement; namespace TravelAgencyDatabaseImplement.Migrations { [DbContext(typeof(TravelAgencyDatabase))] - [Migration("20240529001818_InitialCreate")] + [Migration("20240529060724_InitialCreate")] partial class InitialCreate { /// @@ -89,6 +89,29 @@ namespace TravelAgencyDatabaseImplement.Migrations b.ToTable("ExcursionGroups"); }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupPlace", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ExcursionGroupId") + .HasColumnType("int"); + + b.Property("PlaceId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExcursionGroupId"); + + b.HasIndex("PlaceId"); + + b.ToTable("ExcursionGroupPlaces"); + }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupTour", b => { b.Property("Id") @@ -328,6 +351,25 @@ namespace TravelAgencyDatabaseImplement.Migrations b.Navigation("User"); }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupPlace", b => + { + b.HasOne("TravelAgencyDatabaseImplement.Models.ExcursionGroup", "ExcursionGroup") + .WithMany("Places") + .HasForeignKey("ExcursionGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("TravelAgencyDatabaseImplement.Models.Place", "Place") + .WithMany("ExcursionGroups") + .HasForeignKey("PlaceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ExcursionGroup"); + + b.Navigation("Place"); + }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupTour", b => { b.HasOne("TravelAgencyDatabaseImplement.Models.ExcursionGroup", "ExcursionGroup") @@ -414,6 +456,8 @@ namespace TravelAgencyDatabaseImplement.Migrations modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroup", b => { + b.Navigation("Places"); + b.Navigation("Tours"); }); @@ -426,6 +470,8 @@ namespace TravelAgencyDatabaseImplement.Migrations modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b => { + b.Navigation("ExcursionGroups"); + b.Navigation("Excursions"); b.Navigation("Trips"); diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529001818_InitialCreate.cs b/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529060724_InitialCreate.cs similarity index 88% rename from TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529001818_InitialCreate.cs rename to TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529060724_InitialCreate.cs index 28bd31f..bdae5f5 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529001818_InitialCreate.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/Migrations/20240529060724_InitialCreate.cs @@ -183,6 +183,32 @@ namespace TravelAgencyDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateTable( + name: "ExcursionGroupPlaces", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ExcursionGroupId = table.Column(type: "int", nullable: false), + PlaceId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ExcursionGroupPlaces", x => x.Id); + table.ForeignKey( + name: "FK_ExcursionGroupPlaces_ExcursionGroups_ExcursionGroupId", + column: x => x.ExcursionGroupId, + principalTable: "ExcursionGroups", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_ExcursionGroupPlaces_Places_PlaceId", + column: x => x.PlaceId, + principalTable: "Places", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + migrationBuilder.CreateTable( name: "ExcursionGroupTours", columns: table => new @@ -235,6 +261,16 @@ namespace TravelAgencyDatabaseImplement.Migrations onDelete: ReferentialAction.Cascade); }); + migrationBuilder.CreateIndex( + name: "IX_ExcursionGroupPlaces_ExcursionGroupId", + table: "ExcursionGroupPlaces", + column: "ExcursionGroupId"); + + migrationBuilder.CreateIndex( + name: "IX_ExcursionGroupPlaces_PlaceId", + table: "ExcursionGroupPlaces", + column: "PlaceId"); + migrationBuilder.CreateIndex( name: "IX_ExcursionGroups_GuideId", table: "ExcursionGroups", @@ -299,6 +335,9 @@ namespace TravelAgencyDatabaseImplement.Migrations /// protected override void Down(MigrationBuilder migrationBuilder) { + migrationBuilder.DropTable( + name: "ExcursionGroupPlaces"); + migrationBuilder.DropTable( name: "ExcursionGroupTours"); diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Migrations/TravelAgencyDatabaseModelSnapshot.cs b/TravelAgency/TravelAgencyDatabaseImplement/Migrations/TravelAgencyDatabaseModelSnapshot.cs index a3ca8a7..fdd2435 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/Migrations/TravelAgencyDatabaseModelSnapshot.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/Migrations/TravelAgencyDatabaseModelSnapshot.cs @@ -86,6 +86,29 @@ namespace TravelAgencyDatabaseImplement.Migrations b.ToTable("ExcursionGroups"); }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupPlace", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ExcursionGroupId") + .HasColumnType("int"); + + b.Property("PlaceId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ExcursionGroupId"); + + b.HasIndex("PlaceId"); + + b.ToTable("ExcursionGroupPlaces"); + }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupTour", b => { b.Property("Id") @@ -325,6 +348,25 @@ namespace TravelAgencyDatabaseImplement.Migrations b.Navigation("User"); }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupPlace", b => + { + b.HasOne("TravelAgencyDatabaseImplement.Models.ExcursionGroup", "ExcursionGroup") + .WithMany("Places") + .HasForeignKey("ExcursionGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("TravelAgencyDatabaseImplement.Models.Place", "Place") + .WithMany("ExcursionGroups") + .HasForeignKey("PlaceId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ExcursionGroup"); + + b.Navigation("Place"); + }); + modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroupTour", b => { b.HasOne("TravelAgencyDatabaseImplement.Models.ExcursionGroup", "ExcursionGroup") @@ -411,6 +453,8 @@ namespace TravelAgencyDatabaseImplement.Migrations modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.ExcursionGroup", b => { + b.Navigation("Places"); + b.Navigation("Tours"); }); @@ -423,6 +467,8 @@ namespace TravelAgencyDatabaseImplement.Migrations modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b => { + b.Navigation("ExcursionGroups"); + b.Navigation("Excursions"); b.Navigation("Trips"); diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroup.cs b/TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroup.cs index 5536c56..f46348e 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroup.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroup.cs @@ -47,6 +47,25 @@ namespace TravelAgencyDatabaseImplement.Models [ForeignKey("ExcursionGroupId")] public virtual List Tours { get; set; } = new(); + private Dictionary? _excursionGroupPlaces = null; + + [NotMapped] + public Dictionary ExcursionGroupPlaces + { + get + { + if (_excursionGroupPlaces == null) + { + _excursionGroupPlaces = Places + .ToDictionary(recPC => recPC.PlaceId, recPC => recPC.Place as IPlaceModel); + } + return _excursionGroupPlaces; + } + } + + [ForeignKey("ExcursionGroupId")] + public virtual List Places { get; set; } = new(); + public static ExcursionGroup? Create(TravelAgencyDatabase context, ExcursionGroupBindingModel? model) { if (model == null) @@ -65,6 +84,10 @@ namespace TravelAgencyDatabaseImplement.Models Tours = model.ExcursionGroupTours.Select(x => new ExcursionGroupTour { Tour = context.Tours.First(y => y.Id == x.Key) + }).ToList(), + Places = model.ExcursionGroupPlaces.Select(x => new ExcursionGroupPlace + { + Place = context.Places.First(y => y.Id == x.Key) }).ToList() }; } @@ -90,7 +113,8 @@ namespace TravelAgencyDatabaseImplement.Models UserId = UserId, GuideId = GuideId, GuideFIO = Guide?.GuideFIO, - ExcursionGroupTours = ExcursionGroupTours + ExcursionGroupTours = ExcursionGroupTours, + ExcursionGroupPlaces = ExcursionGroupPlaces }; public void UpdateTours(TravelAgencyDatabase context, ExcursionGroupBindingModel model) @@ -118,5 +142,31 @@ namespace TravelAgencyDatabaseImplement.Models } _excursionGroupTours = null; } + + public void UpdatePlaces(TravelAgencyDatabase context, ExcursionGroupBindingModel model) + { + var excursionGroupPlaces = context.ExcursionGroupPlaces.Where(rec => rec.ExcursionGroupId == model.Id).ToList(); + if (excursionGroupPlaces != null && excursionGroupPlaces.Count > 0) + { // удалили те, которых нет в модели + context.ExcursionGroupPlaces.RemoveRange(excursionGroupPlaces.Where(rec => !model.ExcursionGroupPlaces.ContainsKey(rec.PlaceId))); + context.SaveChanges(); + } + var excursionGroup = context.ExcursionGroups.First(x => x.Id == Id); + foreach (var et in model.ExcursionGroupPlaces) + { + + if (excursionGroupPlaces!.Any(x => x.PlaceId == et.Key)) + { + continue; + } + context.ExcursionGroupPlaces.Add(new ExcursionGroupPlace + { + ExcursionGroup = excursionGroup, + Place = context.Places.First(x => x.Id == et.Key) + }); + context.SaveChanges(); + } + _excursionGroupPlaces = null; + } } } diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroupPlace.cs b/TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroupPlace.cs new file mode 100644 index 0000000..4ae7bcf --- /dev/null +++ b/TravelAgency/TravelAgencyDatabaseImplement/Models/ExcursionGroupPlace.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; + +namespace TravelAgencyDatabaseImplement.Models +{ + public class ExcursionGroupPlace + { + public int Id { get; set; } + + [Required] + public int ExcursionGroupId { get; set; } + + [Required] + public int PlaceId { get; set; } + + public virtual ExcursionGroup ExcursionGroup { get; set; } = new(); + + public virtual Place Place { get; set; } = new(); + } +} diff --git a/TravelAgency/TravelAgencyDatabaseImplement/Models/Place.cs b/TravelAgency/TravelAgencyDatabaseImplement/Models/Place.cs index a581980..145d05a 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/Models/Place.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/Models/Place.cs @@ -28,6 +28,9 @@ namespace TravelAgencyDatabaseImplement.Models [ForeignKey("PlaceId")] public virtual List Excursions { get; set; } = new(); + [ForeignKey("PlaceId")] + public virtual List ExcursionGroups { get; set; } = new(); + public static Place? Create(PlaceBindingModel? model) { if (model == null) diff --git a/TravelAgency/TravelAgencyDatabaseImplement/TravelAgencyDatabase.cs b/TravelAgency/TravelAgencyDatabaseImplement/TravelAgencyDatabase.cs index f1c592b..dae01a2 100644 --- a/TravelAgency/TravelAgencyDatabaseImplement/TravelAgencyDatabase.cs +++ b/TravelAgency/TravelAgencyDatabaseImplement/TravelAgencyDatabase.cs @@ -24,6 +24,8 @@ namespace TravelAgencyDatabaseImplement public virtual DbSet ExcursionGroupTours { set; get; } + public virtual DbSet ExcursionGroupPlaces { set; get; } + public virtual DbSet Guides { set; get; } public virtual DbSet Places { set; get; } diff --git a/TravelAgency/TravelAgencyWebApp/Controllers/ExcursionGroupController.cs b/TravelAgency/TravelAgencyWebApp/Controllers/ExcursionGroupController.cs index 02f3eb9..3030314 100644 --- a/TravelAgency/TravelAgencyWebApp/Controllers/ExcursionGroupController.cs +++ b/TravelAgency/TravelAgencyWebApp/Controllers/ExcursionGroupController.cs @@ -1,5 +1,7 @@ -using Microsoft.AspNetCore.Mvc; +using DocumentFormat.OpenXml.Office2010.Excel; +using Microsoft.AspNetCore.Mvc; using System; +using System.Linq; using TravelAgencyContracts.BindingModels; using TravelAgencyContracts.BusinessLogicsContracts; using TravelAgencyContracts.SearchModels; @@ -18,12 +20,15 @@ namespace TravelAgencyWebApp.Controllers private readonly IGuideLogic _guideLogic; - public ExcursionGroupController(ILogger logger, IExcursionGroupLogic excursionGroupLogic, ITourLogic tourLogic, IGuideLogic guideLogic) + private readonly IPlaceLogic _placeLogic; + + public ExcursionGroupController(ILogger logger, IExcursionGroupLogic excursionGroupLogic, ITourLogic tourLogic, IGuideLogic guideLogic, IPlaceLogic placeLogic) { _logger = logger; _excursionGroupLogic = excursionGroupLogic; _tourLogic = tourLogic; _guideLogic = guideLogic; + _placeLogic = placeLogic; } [HttpGet] @@ -129,6 +134,8 @@ namespace TravelAgencyWebApp.Controllers excursionGroupTours.Add(tourId, _tourLogic.ReadElement(new TourSearchModel { Id = tourId })!); } + var excursionGroup = _excursionGroupLogic.ReadElement(new ExcursionGroupSearchModel() { Id = id }); + _excursionGroupLogic.Update(new ExcursionGroupBindingModel { Id = id, @@ -136,7 +143,8 @@ namespace TravelAgencyWebApp.Controllers ParticipantsAmount = participantsAmount, UserId = LoggedinUser.User.Id, GuideId = guide, - ExcursionGroupTours = excursionGroupTours + ExcursionGroupTours = excursionGroupTours, + ExcursionGroupPlaces = excursionGroup.ExcursionGroupPlaces }); Response.Redirect("/ExcursionGroup/ExcursionGroups"); @@ -157,5 +165,61 @@ namespace TravelAgencyWebApp.Controllers Response.Redirect("/ExcursionGroup/ExcursionGroups"); } + + [HttpGet] + public IActionResult ConnectGroupToPlace() + { + if (LoggedinUser.User == null) + { + return Redirect("~/Home/Enter"); + } + + ViewBag.ExcursionGroups = _excursionGroupLogic.ReadList(new ExcursionGroupSearchModel + { + UserId = LoggedinUser.User.Id, + }); + + ViewBag.Places = _placeLogic.ReadList(null); + + return View(); + } + + [HttpPost] + public IActionResult ConnectGroupToPlace(int excursionGroupId, int placeId) + { + if (LoggedinUser.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (excursionGroupId <= 0 || placeId <= 0) + { + throw new Exception("Введены не все данные!"); + } + var excursionGroup = _excursionGroupLogic.ReadElement(new ExcursionGroupSearchModel() { Id = excursionGroupId }); + Dictionary excursionGroupPlaces = excursionGroup.ExcursionGroupPlaces; + if (!excursionGroupPlaces.ContainsKey(placeId)) + excursionGroupPlaces.Add(placeId, _placeLogic.ReadElement(new PlaceSearchModel { Id = placeId })!); + + _excursionGroupLogic.Update(new ExcursionGroupBindingModel + { + Id = excursionGroupId, + ExcursionGroupName = excursionGroup.ExcursionGroupName, + ParticipantsAmount = excursionGroup.ParticipantsAmount, + UserId = LoggedinUser.User.Id, + GuideId = excursionGroup.GuideId, + ExcursionGroupTours = excursionGroup.ExcursionGroupTours, + ExcursionGroupPlaces = excursionGroupPlaces + }); + + ViewBag.ExcursionGroups = _excursionGroupLogic.ReadList(new ExcursionGroupSearchModel + { + UserId = LoggedinUser.User.Id, + }); + + ViewBag.Places = _placeLogic.ReadList(null); + + return View(); + } } } diff --git a/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs b/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs index 89cc598..1de1854 100644 --- a/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs +++ b/TravelAgency/TravelAgencyWebApp/Controllers/HomeController.cs @@ -51,13 +51,48 @@ namespace TravelAgencyWebApp.Controllers return View(LoggedinUser.User); } - [HttpGet] - public IActionResult Privacy() - { - return View(); - } + [HttpGet] + public IActionResult Privacy() + { + if (LoggedinUser.User == null) + { + return Redirect("~/Home/Enter"); + } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + return View(LoggedinUser.User); + } + + [HttpPost] + public void Privacy(string userFIO, string email, string phoneNumber, string password) + { + if (LoggedinUser.User == null) + { + throw new Exception("Необходимо авторизоваться!"); + } + + if (string.IsNullOrEmpty(userFIO) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введены не все данные!"); + } + + _userLogic.Update(new UserBindingModel + { + Id = LoggedinUser.User.Id, + UserFIO = userFIO, + Email = email, + PhoneNumber = phoneNumber, + Password = password + }); + + LoggedinUser.User.UserFIO = userFIO; + LoggedinUser.User.Email = email; + LoggedinUser.User.PhoneNumber = phoneNumber; + LoggedinUser.User.Password = password; + + Response.Redirect("Privacy"); + } + + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); @@ -139,6 +174,10 @@ namespace TravelAgencyWebApp.Controllers [HttpGet] public IActionResult ReportMenu() { + if (LoggedinUser.User == null) + { + return Redirect("~/Home/Enter"); + } return View(); } [HttpGet] diff --git a/TravelAgency/TravelAgencyWebApp/Views/Excursion/CreateExcursion.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Excursion/CreateExcursion.cshtml index 8a18b0e..c48e368 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Excursion/CreateExcursion.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Excursion/CreateExcursion.cshtml @@ -19,14 +19,14 @@
Место для посещения:
-
+
-
Туры
+
Туры
- +
diff --git a/TravelAgency/TravelAgencyWebApp/Views/Excursion/UpdateExcursion.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Excursion/UpdateExcursion.cshtml index df2a252..010e1d1 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Excursion/UpdateExcursion.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Excursion/UpdateExcursion.cshtml @@ -22,7 +22,7 @@
Место для посещения:
-
+
Название
+
diff --git a/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ConnectGroupToPlace.cshtml b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ConnectGroupToPlace.cshtml new file mode 100644 index 0000000..1e33c1f --- /dev/null +++ b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ConnectGroupToPlace.cshtml @@ -0,0 +1,58 @@ +@{ + ViewData["Title"] = "Create group to place"; +} +
+

Связывание группы и места для посещения

+
+ +
+
Группа:
+
+ +
+
+
+
Место:
+
+ +
+
+
+
+
+ + + +
Название
+ + + + + + + + @foreach (var eg in ViewBag.ExcursionGroups) + { + + + + + foreach (var ep in eg.ExcursionGroupPlaces) { + + + + + } + } + +
+ Группа + + Место +
+ @eg.ExcursionGroupName + +
+ + @ep.Value.PlaceName +
\ No newline at end of file diff --git a/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/CreateExcursionGroup.cshtml b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/CreateExcursionGroup.cshtml index 0ad18ca..2d96f25 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/CreateExcursionGroup.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/CreateExcursionGroup.cshtml @@ -15,14 +15,14 @@
Гид:
-
+
-
Туры
+
Туры
- +
diff --git a/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ExcursionGroups.cshtml b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ExcursionGroups.cshtml index 5565c95..18457cc 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ExcursionGroups.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/ExcursionGroups.cshtml @@ -32,10 +32,7 @@ Название -
Название - Описание - - Цена + Кол-во участников Гид diff --git a/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/UpdateExcursionGroup.cshtml b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/UpdateExcursionGroup.cshtml index 4025e59..14920b3 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/UpdateExcursionGroup.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/ExcursionGroup/UpdateExcursionGroup.cshtml @@ -18,7 +18,7 @@
Гид:
-
+
+
diff --git a/TravelAgency/TravelAgencyWebApp/Views/Home/Privacy.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Home/Privacy.cshtml index 90c2277..e7b32dc 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Home/Privacy.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Home/Privacy.cshtml @@ -11,7 +11,7 @@
Логин(почта):
-
+
Пароль:
@@ -19,11 +19,11 @@
Номер телефона:
-
+
ФИО:
-
+
diff --git a/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPeriod.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPeriod.cshtml index 6ced129..969438d 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPeriod.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPeriod.cshtml @@ -51,12 +51,14 @@ { foreach (var record in Model) { -
- - - - - + + + + + + + + var excursionGroups = new List(record.ExcursionGroups); var guides = new List(record.Guides); for (int i = 0; i < excursionGroups.Count; i++) diff --git a/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPlace.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPlace.cshtml index fde3716..526167c 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPlace.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Home/ReportTourPlace.cshtml @@ -9,9 +9,9 @@ -
Выберите тур:
+

Выберите тур:

-
Название
@record.Tour.TourName@record.Tour.Price@record.Tour.TourDate
@record.Tour.TourName@record.Tour.Price@record.Tour.TourDate.ToShortDateString()
+
diff --git a/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml b/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml index bb6cb88..66e16aa 100644 --- a/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml +++ b/TravelAgency/TravelAgencyWebApp/Views/Shared/_Layout.cshtml @@ -14,7 +14,7 @@
Название
- - - - - - - - - - - - - @foreach (var tour in Model) - { +

+ Создать тур +

+
- Номер - - Название - - Описание - - Цена - - Дата тура -
+ - - - - - - - + + + + + + + + + + @foreach (var tour in Model) + { + + + + + + + + + } - -
- @Html.DisplayFor(modelItem => tour.Id) - - @Html.DisplayFor(modelItem => tour.TourName) - - @Html.DisplayFor(modelItem => tour.TourDescription) - - @Html.DisplayFor(modelItem => tour.Price) - - @Html.DisplayFor(modelItem => tour.TourDate) - - - - - + Номер + + Название + + Описание + + Цена + + Дата тура +
+ @tour.Id + + @tour.TourName + + @tour.TourDescription + + @tour.Price + + @tour.TourDate.ToShortDateString() + + + + +
+ +
}
\ No newline at end of file