final commit

This commit is contained in:
Salikh 2024-05-01 19:51:05 +04:00
parent 09fc8ca9de
commit d4966200cd
13 changed files with 128 additions and 85 deletions

View File

@ -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<OrganiserLogic> 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("Организатор с таким логином уже есть");
}
}
}
}

View File

@ -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; }

View File

@ -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; }

View File

@ -26,25 +26,12 @@ namespace HotelDataBaseImplement.Implements
public List<ConferenceBookingViewModel> 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)

View File

@ -32,13 +32,26 @@ namespace HotelDataBaseImplement.Implements
public List<ConferenceViewModel> 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)

View File

@ -35,14 +35,30 @@ namespace HotelDataBaseImplement.Implements
public List<RoomViewModel> 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)

View File

@ -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
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -73,6 +73,9 @@ namespace HotelDataBaseImplement.Migrations
b.Property<int>("OrganiserId")
.HasColumnType("integer");
b.Property<DateTime>("StartDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
@ -329,8 +332,8 @@ namespace HotelDataBaseImplement.Migrations
b.Property<int>("AdministratorId")
.HasColumnType("integer");
b.Property<int>("CountBeds")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp without time zone");
b.Property<int?>("MealPlanId")
.HasColumnType("integer");

View File

@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace HotelDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class NewMigration : Migration
public partial class SeqMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
@ -76,6 +76,7 @@ namespace HotelDataBaseImplement.Migrations
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ConferenceName = table.Column<string>(type: "text", nullable: false),
Subject = table.Column<string>(type: "text", nullable: false),
StartDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
OrganiserId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
@ -165,8 +166,8 @@ namespace HotelDataBaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
RoomNumber = table.Column<int>(type: "integer", nullable: false),
CountBeds = table.Column<int>(type: "integer", nullable: false),
RoomPrice = table.Column<double>(type: "double precision", nullable: false),
DateCreate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
AdministratorId = table.Column<int>(type: "integer", nullable: false),
MealPlanId = table.Column<int>(type: "integer", nullable: true)
},

View File

@ -70,6 +70,9 @@ namespace HotelDataBaseImplement.Migrations
b.Property<int>("OrganiserId")
.HasColumnType("integer");
b.Property<DateTime>("StartDate")
.HasColumnType("timestamp without time zone");
b.Property<string>("Subject")
.IsRequired()
.HasColumnType("text");
@ -326,8 +329,8 @@ namespace HotelDataBaseImplement.Migrations
b.Property<int>("AdministratorId")
.HasColumnType("integer");
b.Property<int>("CountBeds")
.HasColumnType("integer");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp without time zone");
b.Property<int?>("MealPlanId")
.HasColumnType("integer");

View File

@ -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
};

View File

@ -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

View File

@ -10,7 +10,7 @@ namespace HotelDataModels.Models
{
int RoomNumber { get; }
double RoomPrice { get; }
DateTime? DateCreate { get; }
DateTime DateCreate { get; }
int AdministratorId { get; }
public Dictionary<int, IDinnerModel> RoomDinners { get; }
}

View File

@ -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)
{