From d4966200cd03e006e2807807a74176a058ff9985 Mon Sep 17 00:00:00 2001 From: Salikh Date: Wed, 1 May 2024 19:51:05 +0400 Subject: [PATCH] final commit --- .../BusinessLogic/OrganiserLogic.cs | 98 +++++++++++-------- .../BindingModels/RoomBindingModel.cs | 2 +- .../ViewModels/RoomViewModel.cs | 2 +- .../Implements/ConferenceBookingStorage.cs | 17 +--- .../Implements/ConferenceStorage.cs | 17 +++- .../Implements/RoomStorage.cs | 20 +++- ...> 20240501154837_SeqMigration.Designer.cs} | 11 ++- ...tion.cs => 20240501154837_SeqMigration.cs} | 5 +- .../Migrations/HotelDataBaseModelSnapshot.cs | 7 +- .../Models/Conference.cs | 8 +- Hotel/HotelDataBaseImplement/Models/Room.cs | 22 ++--- Hotel/HotelDataModels/Models/IRoomModel.cs | 2 +- .../Controllers/MainController.cs | 2 +- 13 files changed, 128 insertions(+), 85 deletions(-) rename Hotel/HotelDataBaseImplement/Migrations/{20240501104100_NewMigration.Designer.cs => 20240501154837_SeqMigration.Designer.cs} (98%) rename Hotel/HotelDataBaseImplement/Migrations/{20240501104100_NewMigration.cs => 20240501154837_SeqMigration.cs} (98%) diff --git a/Hotel/HotelBusinessLogic/BusinessLogic/OrganiserLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogic/OrganiserLogic.cs index 3b4a399..e0c56ea 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogic/OrganiserLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogic/OrganiserLogic.cs @@ -14,7 +14,9 @@ namespace HotelBusinessLogic.BusinessLogic { public class OrganiserLogic : IOrganiserLogic { - private readonly ILogger _logger; + private readonly int _loginMaxLength = 25; + private readonly int _passwordMaxLength = 50; + private readonly ILogger _logger; private readonly IOrganiserStorage _organiserStorage; public OrganiserLogic(ILogger logger, IOrganiserStorage organiserStorage) @@ -103,47 +105,63 @@ namespace HotelBusinessLogic.BusinessLogic public void CheckModel(OrganiserBindingModel model, bool withParams = true) { - if (model == null) - throw new ArgumentNullException(nameof(model)); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } - if (!withParams) - return; + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.OrganiserFIO)) + { + throw new ArgumentNullException("Нет ФИО организатора", nameof(model.OrganiserFIO)); + } + if (string.IsNullOrEmpty(model.OrganiserLogin)) + { + throw new ArgumentNullException("Нет логина организатора", nameof(model.OrganiserLogin)); + } + if (model.OrganiserLogin.Length > _loginMaxLength) + { + throw new ArgumentNullException("Логин превышает допустимое количество символов", nameof(model.OrganiserLogin)); + } + if (string.IsNullOrEmpty(model.OrganiserNumber)) + { + throw new ArgumentNullException("Нет номера телефона организатора", nameof(model.OrganiserNumber)); + } + if (string.IsNullOrEmpty(model.OrganiserEmail)) + { + throw new ArgumentNullException("Нет эл. почты администратора", nameof(model.OrganiserEmail)); + } + if (string.IsNullOrEmpty(model.OrganiserPassword)) + { + throw new ArgumentNullException("Нет пароля организатора", nameof(model.OrganiserPassword)); + } + if (model.OrganiserPassword.Length > _passwordMaxLength) + { + throw new ArgumentNullException("Пароль превышает допустимое количество символов", nameof(model.OrganiserPassword)); + } + _logger.LogInformation("Organiser. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. OrganiserNumber: {OrganiserNumber}.OrganiserEmail: {OrganiserEmail}.OrganiserPassword: {OrganiserPassword}.Id: {Id}", + model.OrganiserFIO, model.OrganiserLogin, model.OrganiserNumber, model.OrganiserEmail, model.OrganiserPassword, model.Id); - if (string.IsNullOrEmpty(model.OrganiserLogin)) - throw new ArgumentException("Нет логина организатора", nameof(model.OrganiserLogin)); + var elementEmail = _organiserStorage.GetElement(new OrganiserSearchModel + { + OrganiserEmail = model.OrganiserEmail + }); + if (elementEmail != null && elementEmail.Id != model.Id) + { + throw new InvalidOperationException("Администратор с такой почтой уже есть"); + } - if (string.IsNullOrEmpty(model.OrganiserPassword)) - throw new ArgumentException("Нет пароля организатора", nameof(model.OrganiserLogin)); - - if (string.IsNullOrEmpty(model.OrganiserEmail)) - throw new ArgumentException("Нет эл. почты организатора", nameof(model.OrganiserEmail)); - - if (string.IsNullOrEmpty(model.OrganiserNumber)) - throw new ArgumentException("Нет номера организатора", nameof(model.OrganiserNumber)); - - if (string.IsNullOrEmpty(model.OrganiserFIO)) - throw new ArgumentException("Нет ФИО организатора", nameof(model.OrganiserFIO)); - - _logger.LogInformation("Organiser. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}", model.OrganiserFIO, model.OrganiserLogin, model.Id); - - var element = _organiserStorage.GetElement(new OrganiserSearchModel - { - OrganiserEmail = model.OrganiserEmail, - }); - - if (element != null && element.Id == model.Id) - { - throw new InvalidOperationException("Организатор с таким логином уже есть"); - } - - var elementLogin = _organiserStorage.GetElement(new OrganiserSearchModel - { - OrganiserLogin = model.OrganiserLogin - }); - if (elementLogin != null && elementLogin.Id != model.Id) - { - throw new InvalidOperationException("Организатор с таким логином уже есть"); - } - } + var elementLogin = _organiserStorage.GetElement(new OrganiserSearchModel + { + OrganiserLogin = model.OrganiserLogin + }); + if (elementLogin != null && elementLogin.Id != model.Id) + { + throw new InvalidOperationException("Организатор с таким логином уже есть"); + } + } } } diff --git a/Hotel/HotelContracts/BindingModels/RoomBindingModel.cs b/Hotel/HotelContracts/BindingModels/RoomBindingModel.cs index 2a5ec64..aa2563c 100644 --- a/Hotel/HotelContracts/BindingModels/RoomBindingModel.cs +++ b/Hotel/HotelContracts/BindingModels/RoomBindingModel.cs @@ -11,7 +11,7 @@ namespace HotelContracts.BindingModels { public int Id { get; set; } public int RoomNumber { get; set; } - public DateTime? DateCreate { get; set; } + public DateTime DateCreate { get; set; } public double RoomPrice { get; set; } public int AdministratorId { get; set; } public int? MealPlanId { get; set; } diff --git a/Hotel/HotelContracts/ViewModels/RoomViewModel.cs b/Hotel/HotelContracts/ViewModels/RoomViewModel.cs index 013bb01..01d7222 100644 --- a/Hotel/HotelContracts/ViewModels/RoomViewModel.cs +++ b/Hotel/HotelContracts/ViewModels/RoomViewModel.cs @@ -14,7 +14,7 @@ namespace HotelContracts.ViewModels [DisplayName("Номер комнаты")] public int RoomNumber { get; set; } [DisplayName("Дата создания номера")] - public DateTime? DateCreate { get; set; } + public DateTime DateCreate { get; set; } [DisplayName("Стоимость номера")] public double RoomPrice { get; set; } public int AdministratorId { get; set; } diff --git a/Hotel/HotelDataBaseImplement/Implements/ConferenceBookingStorage.cs b/Hotel/HotelDataBaseImplement/Implements/ConferenceBookingStorage.cs index 8316673..405aaf9 100644 --- a/Hotel/HotelDataBaseImplement/Implements/ConferenceBookingStorage.cs +++ b/Hotel/HotelDataBaseImplement/Implements/ConferenceBookingStorage.cs @@ -26,25 +26,12 @@ namespace HotelDataBaseImplement.Implements public List GetFilteredList(ConferenceBookingSearchModel model) { - if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.AdministratorId.HasValue) + if (!model.AdministratorId.HasValue) { return new(); } using var context = new HotelDataBase(); - if (model.DateFrom.HasValue) - { - return context.ConferenceBookings - .Include(x => x.Dinners) - .ThenInclude(x => x.Dinner) - .ThenInclude(x => x.RoomDinners) - .ThenInclude(x => x.Room) - .Include(x => x.Conference) - .Include(x => x.Administrator) - .Where(x => x.DateСonference >= model.DateFrom && x.DateСonference <= model.DateTo && x.AdministratorId == model.AdministratorId) - .Select(x => x.GetViewModel) - .ToList(); - } - else if (model.AdministratorId.HasValue) + if (model.AdministratorId.HasValue) { return context.ConferenceBookings .Include(x => x.Dinners) diff --git a/Hotel/HotelDataBaseImplement/Implements/ConferenceStorage.cs b/Hotel/HotelDataBaseImplement/Implements/ConferenceStorage.cs index d680141..adb2898 100644 --- a/Hotel/HotelDataBaseImplement/Implements/ConferenceStorage.cs +++ b/Hotel/HotelDataBaseImplement/Implements/ConferenceStorage.cs @@ -32,13 +32,26 @@ namespace HotelDataBaseImplement.Implements public List GetFilteredList(ConferenceSearchModel model) { - if (!model.OrganiserId.HasValue) + if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.OrganiserId.HasValue) { return new(); } using var context = new HotelDataBase(); - if (model.OrganiserId.HasValue) + if (model.DateFrom.HasValue) + { + return context.Conferences + .Include(x => x.Participants) + .ThenInclude(x => x.Participant) + .ThenInclude(x => x.MealPlanParticipants) + .ThenInclude(x => x.MealPlan) + .Include(x => x.Bookings) + .Include(x => x.Organiser) + .Where(x => x.StartDate >= model.DateFrom && x.StartDate <= model.DateTo && x.OrganiserId == model.OrganiserId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.OrganiserId.HasValue) return context.Conferences .Include(x => x.Participants) .ThenInclude(x => x.Participant) diff --git a/Hotel/HotelDataBaseImplement/Implements/RoomStorage.cs b/Hotel/HotelDataBaseImplement/Implements/RoomStorage.cs index afd499b..0d8e6e9 100644 --- a/Hotel/HotelDataBaseImplement/Implements/RoomStorage.cs +++ b/Hotel/HotelDataBaseImplement/Implements/RoomStorage.cs @@ -35,14 +35,30 @@ namespace HotelDataBaseImplement.Implements public List GetFilteredList(RoomSearchModel model) { - if (!model.Id.HasValue && !model.AdministratorId.HasValue) + if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !model.Id.HasValue && !model.AdministratorId.HasValue) { return new(); } using var context = new HotelDataBase(); - if (model.AdministratorId.HasValue) + if (model.DateFrom.HasValue) + { + return context.Rooms + .Include(x => x.Dinners) + .ThenInclude(x => x.Dinner) + .ThenInclude(x => x.ConferenceBookingDinner) + .ThenInclude(x => x.ConferenceBooking) + .Include(x => x.MealPlanRooms) + .ThenInclude(x => x.MealPlan) + .ThenInclude(x => x.Participants) + .ThenInclude(x => x.Participant) + .Include(x => x.Administrator) + .Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo && x.AdministratorId == model.AdministratorId) + .Select(x => x.GetViewModel) + .ToList(); + } + else if (model.AdministratorId.HasValue) { return context.Rooms .Include(x => x.Dinners) diff --git a/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.Designer.cs b/Hotel/HotelDataBaseImplement/Migrations/20240501154837_SeqMigration.Designer.cs similarity index 98% rename from Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.Designer.cs rename to Hotel/HotelDataBaseImplement/Migrations/20240501154837_SeqMigration.Designer.cs index e7cff3a..dac093c 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.Designer.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/20240501154837_SeqMigration.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace HotelDataBaseImplement.Migrations { [DbContext(typeof(HotelDataBase))] - [Migration("20240501104100_NewMigration")] - partial class NewMigration + [Migration("20240501154837_SeqMigration")] + partial class SeqMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -73,6 +73,9 @@ namespace HotelDataBaseImplement.Migrations b.Property("OrganiserId") .HasColumnType("integer"); + b.Property("StartDate") + .HasColumnType("timestamp without time zone"); + b.Property("Subject") .IsRequired() .HasColumnType("text"); @@ -329,8 +332,8 @@ namespace HotelDataBaseImplement.Migrations b.Property("AdministratorId") .HasColumnType("integer"); - b.Property("CountBeds") - .HasColumnType("integer"); + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); b.Property("MealPlanId") .HasColumnType("integer"); diff --git a/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.cs b/Hotel/HotelDataBaseImplement/Migrations/20240501154837_SeqMigration.cs similarity index 98% rename from Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.cs rename to Hotel/HotelDataBaseImplement/Migrations/20240501154837_SeqMigration.cs index 9e472bb..013d7cc 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/20240501154837_SeqMigration.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace HotelDataBaseImplement.Migrations { /// - public partial class NewMigration : Migration + public partial class SeqMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -76,6 +76,7 @@ namespace HotelDataBaseImplement.Migrations .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ConferenceName = table.Column(type: "text", nullable: false), Subject = table.Column(type: "text", nullable: false), + StartDate = table.Column(type: "timestamp without time zone", nullable: false), OrganiserId = table.Column(type: "integer", nullable: false) }, constraints: table => @@ -165,8 +166,8 @@ namespace HotelDataBaseImplement.Migrations Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), RoomNumber = table.Column(type: "integer", nullable: false), - CountBeds = table.Column(type: "integer", nullable: false), RoomPrice = table.Column(type: "double precision", nullable: false), + DateCreate = table.Column(type: "timestamp without time zone", nullable: false), AdministratorId = table.Column(type: "integer", nullable: false), MealPlanId = table.Column(type: "integer", nullable: true) }, diff --git a/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs b/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs index 5fb6c7d..53b6bbd 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/HotelDataBaseModelSnapshot.cs @@ -70,6 +70,9 @@ namespace HotelDataBaseImplement.Migrations b.Property("OrganiserId") .HasColumnType("integer"); + b.Property("StartDate") + .HasColumnType("timestamp without time zone"); + b.Property("Subject") .IsRequired() .HasColumnType("text"); @@ -326,8 +329,8 @@ namespace HotelDataBaseImplement.Migrations b.Property("AdministratorId") .HasColumnType("integer"); - b.Property("CountBeds") - .HasColumnType("integer"); + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); b.Property("MealPlanId") .HasColumnType("integer"); diff --git a/Hotel/HotelDataBaseImplement/Models/Conference.cs b/Hotel/HotelDataBaseImplement/Models/Conference.cs index c5cc4e9..01b089e 100644 --- a/Hotel/HotelDataBaseImplement/Models/Conference.cs +++ b/Hotel/HotelDataBaseImplement/Models/Conference.cs @@ -22,7 +22,10 @@ namespace HotelDataBaseImplement.Models [Required] public string Subject { get; set; } = string.Empty; - public int OrganiserId { get; private set; } + [Required] + public DateTime StartDate { get; set; } = DateTime.Now; + + public int OrganiserId { get; private set; } public virtual Organiser Organiser { get; set; } @@ -56,6 +59,7 @@ namespace HotelDataBaseImplement.Models Id = model.Id, ConferenceName = model.ConferenceName, Subject = model.Subject, + StartDate = model.StartDate, OrganiserId = model.OrganiserId, Participants = model.ConferenceParticipants.Select(x => new ConferenceParticipant { @@ -68,6 +72,7 @@ namespace HotelDataBaseImplement.Models { ConferenceName = model.ConferenceName; Subject = model.Subject; + StartDate = model.StartDate; OrganiserId = model.OrganiserId; } @@ -76,6 +81,7 @@ namespace HotelDataBaseImplement.Models Id = Id, ConferenceName = ConferenceName, Subject = Subject, + StartDate= StartDate, OrganiserId = OrganiserId, ConferenceParticipants = ConferenceParticipants }; diff --git a/Hotel/HotelDataBaseImplement/Models/Room.cs b/Hotel/HotelDataBaseImplement/Models/Room.cs index c9f7bf0..a5f4cfa 100644 --- a/Hotel/HotelDataBaseImplement/Models/Room.cs +++ b/Hotel/HotelDataBaseImplement/Models/Room.cs @@ -1,27 +1,23 @@ using HotelContracts.BindingModels; using HotelContracts.ViewModels; using HotelDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; -using System.Linq; -using System.Text; -using System.Threading.Tasks; + namespace HotelDataBaseImplement.Models { public class Room : IRoomModel - { + { public int Id { get; private set; } [Required] public int RoomNumber { get; set; } [Required] - public int CountBeds { get; set; } - [Required] public double RoomPrice { get; set; } + [Required] + public DateTime DateCreate { get; set; } = DateTime.Now; - public int AdministratorId { get; private set; } + public int AdministratorId { get; private set; } public int? MealPlanId { get; private set; } public virtual Administrator Administrator { get; set; } public virtual MealPlan? MealPlan { get; set; } @@ -54,8 +50,8 @@ namespace HotelDataBaseImplement.Models { Id = model.Id, RoomNumber = model.RoomNumber, - CountBeds = model.CountBeds, RoomPrice = model.RoomPrice, + DateCreate = model.DateCreate, AdministratorId = model.AdministratorId, MealPlanId = model.MealPlanId, Dinners = model.RoomDinners.Select(x => new RoomDinner @@ -68,9 +64,9 @@ namespace HotelDataBaseImplement.Models public void Update(RoomBindingModel model) { RoomNumber = model.RoomNumber; - CountBeds = model.CountBeds; RoomPrice = model.RoomPrice; - AdministratorId = model.AdministratorId; + DateCreate = model.DateCreate; + AdministratorId = model.AdministratorId; MealPlanId = model.MealPlanId; } @@ -78,8 +74,8 @@ namespace HotelDataBaseImplement.Models { Id = Id, RoomNumber = RoomNumber, - CountBeds = CountBeds, RoomPrice = RoomPrice, + DateCreate = DateCreate, AdministratorId = AdministratorId, MealPlanId = MealPlanId, RoomDinners = RoomDinners diff --git a/Hotel/HotelDataModels/Models/IRoomModel.cs b/Hotel/HotelDataModels/Models/IRoomModel.cs index f5fb18d..4557b4e 100644 --- a/Hotel/HotelDataModels/Models/IRoomModel.cs +++ b/Hotel/HotelDataModels/Models/IRoomModel.cs @@ -10,7 +10,7 @@ namespace HotelDataModels.Models { int RoomNumber { get; } double RoomPrice { get; } - DateTime? DateCreate { get; } + DateTime DateCreate { get; } int AdministratorId { get; } public Dictionary RoomDinners { get; } } diff --git a/Hotel/HotelRestApi/Controllers/MainController.cs b/Hotel/HotelRestApi/Controllers/MainController.cs index 5583bf5..8be9e43 100644 --- a/Hotel/HotelRestApi/Controllers/MainController.cs +++ b/Hotel/HotelRestApi/Controllers/MainController.cs @@ -361,7 +361,7 @@ namespace HotelRestApi.Controllers var elem = _mealPlan.ReadElement(new MealPlanSearchModel { Id = mealPlanId }); if (elem == null) return null; - return Tuple.Create(elem, elem.MealPlanParticipants.Select(x => Tuple.Create(x.Value.ParticipantFIO, x.Value.Number)).ToList(), context.Rooms.Where(x => x.MealPlanId == elem.Id).Select(x => Tuple.Create(x.RoomNumber, x.CountBeds)).ToList()); + return Tuple.Create(elem, elem.MealPlanParticipants.Select(x => Tuple.Create(x.Value.ParticipantFIO, x.Value.Number)).ToList(), context.Rooms.Where(x => x.MealPlanId == elem.Id).Select(x => Tuple.Create(x.RoomNumber, x.DateCreate.Year)).ToList()); } catch (Exception ex) {