Merge branch 'first_branch' of https://git.is.ulstu.ru/Extrimal/PIbd-21_Kurs_Work_Hotel into first_branch

This commit is contained in:
Extrimal 2024-04-29 12:10:43 +04:00
commit c69db82f0f
29 changed files with 1527 additions and 31 deletions

View File

@ -99,7 +99,7 @@ namespace HotelBusinessLogic.BusinessLogic
return true; return true;
} }
public bool AddMemberToMealPlan(MealPlanSearchModel model, IParticipantModel participant) public bool AddParticipantToMealPlan(MealPlanSearchModel model, IParticipantModel participant)
{ {
if (model == null) if (model == null)
{ {

View File

@ -126,7 +126,7 @@ namespace HotelBusinessLogic.BusinessLogic
_logger.LogInformation("Organiser. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}", model.OrganiserFIO, model.OrganiserLogin, model.Id); _logger.LogInformation("Organiser. OrganiserFIO: {OrganiserFIO}. OrganiserLogin: {OrganiserLogin}. Id: {Id}", model.OrganiserFIO, model.OrganiserLogin, model.Id);
var element = _organiserStorage.GetElement(new() var element = _organiserStorage.GetElement(new OrganiserSearchModel
{ {
OrganiserEmail = model.OrganiserEmail, OrganiserEmail = model.OrganiserEmail,
}); });
@ -135,6 +135,15 @@ namespace HotelBusinessLogic.BusinessLogic
{ {
throw new InvalidOperationException("Организатор с таким логином уже есть"); throw new InvalidOperationException("Организатор с таким логином уже есть");
} }
var elementLogin = _organiserStorage.GetElement(new OrganiserSearchModel
{
OrganiserLogin = model.OrganiserLogin
});
if (elementLogin != null && elementLogin.Id != model.Id)
{
throw new InvalidOperationException("Организатор с таким логином уже есть");
}
} }
} }
} }

View File

@ -25,7 +25,7 @@ namespace HotelBusinessLogic.BusinessLogic
public List<ParticipantViewModel>? ReadList(ParticipantSearchModel? model) public List<ParticipantViewModel>? ReadList(ParticipantSearchModel? model)
{ {
_logger.LogInformation("ReadList. FIO:{FIO}.Id:{Id}", model?.FIO, model?.Id); _logger.LogInformation("ReadList. FIO:{FIO}.Id:{Id}", model?.ParticipantFIO, model?.Id);
var list = model == null ? _participantStorage.GetFullList() : _participantStorage.GetFilteredList(model); var list = model == null ? _participantStorage.GetFullList() : _participantStorage.GetFilteredList(model);
@ -47,7 +47,7 @@ namespace HotelBusinessLogic.BusinessLogic
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
_logger.LogInformation("ReadElement.FIO:{FIO}.Id:{Id}", model.FIO, model.Id); _logger.LogInformation("ReadElement.FIO:{FIO}.Id:{Id}", model.ParticipantFIO, model.Id);
var element = _participantStorage.GetElement(model); var element = _participantStorage.GetElement(model);
@ -110,12 +110,12 @@ namespace HotelBusinessLogic.BusinessLogic
if (!withParams) if (!withParams)
return; return;
if (string.IsNullOrEmpty(model.FIO)) if (string.IsNullOrEmpty(model.ParticipantFIO))
throw new ArgumentNullException("Нет ФИО участника", nameof(model.FIO)); throw new ArgumentNullException("Нет ФИО участника", nameof(model.ParticipantFIO));
if (string.IsNullOrEmpty (model.Number)) if (string.IsNullOrEmpty (model.Number))
throw new ArgumentNullException("Нет номера участника", nameof(model.Number)); throw new ArgumentNullException("Нет номера участника", nameof(model.Number));
_logger.LogInformation("Participant. FIO:{FIO}.Number:{Number}. Id:{Id}", model.FIO, model.Number, model.Id); _logger.LogInformation("Participant. FIO:{FIO}.Number:{Number}. Id:{Id}", model.ParticipantFIO, model.Number, model.Id);
} }
} }
} }

View File

@ -11,7 +11,7 @@ namespace HotelContracts.BindingModels
{ {
public int Id { get; set; } public int Id { get; set; }
public string FIO { get; set; } = string.Empty; public string ParticipantFIO { get; set; } = string.Empty;
public string Number { get; set; } = string.Empty; public string Number { get; set; } = string.Empty;

View File

@ -13,6 +13,6 @@ namespace HotelContracts.BusinessLogicsContracts
bool Create(MealPlanBindingModel model); bool Create(MealPlanBindingModel model);
bool Update(MealPlanBindingModel model); bool Update(MealPlanBindingModel model);
bool Delete(MealPlanBindingModel model); bool Delete(MealPlanBindingModel model);
bool AddMemberToMealPlan(MealPlanSearchModel model, IParticipantModel participant); bool AddParticipantToMealPlan(MealPlanSearchModel model, IParticipantModel participant);
} }
} }

View File

@ -13,5 +13,7 @@ namespace HotelContracts.SearchModels
public int? ConferenceId { get; set; } public int? ConferenceId { get; set; }
public string? PlaceСonference { get; set; } public string? PlaceСonference { get; set; }
public DateTime? DateСonference { get; set; } public DateTime? DateСonference { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
} }
} }

View File

@ -8,14 +8,14 @@ namespace HotelContracts.SearchModels
{ {
public class OrganiserSearchModel public class OrganiserSearchModel
{ {
public int Id { get; set; } public int? Id { get; set; }
public string OrganiserLogin { get; set; } = string.Empty; public string? OrganiserLogin { get; set; } = string.Empty;
public string OrganiserPassword { get; set; } = string.Empty; public string? OrganiserPassword { get; set; } = string.Empty;
public string OrganiserEmail { get; set; } = string.Empty; public string? OrganiserEmail { get; set; } = string.Empty;
public string OrganiserFIO { get; set; } = string.Empty; public string? OrganiserFIO { get; set; } = string.Empty;
} }
} }

View File

@ -10,7 +10,7 @@ namespace HotelContracts.SearchModels
{ {
public int? Id { get; set; } public int? Id { get; set; }
public string? FIO { get; set; } public string? ParticipantFIO { get; set; }
public int? OrganiserId { get; set; } public int? OrganiserId { get; set; }
} }

View File

@ -13,7 +13,7 @@ namespace HotelContracts.ViewModels
public int Id { get; set; } public int Id { get; set; }
[DisplayName("ФИО участника")] [DisplayName("ФИО участника")]
public string FIO { get; set; } = string.Empty; public string ParticipantFIO { get; set; } = string.Empty;
[DisplayName("Номер участника")] [DisplayName("Номер участника")]
public string Number { get; set; } = string.Empty; public string Number { get; set; } = string.Empty;

View File

@ -19,11 +19,16 @@ namespace HotelDataBaseImplement
public virtual DbSet<Conference> Conferences { get; set; } public virtual DbSet<Conference> Conferences { get; set; }
public virtual DbSet<MealPlan> MealPlans { set; get; } public virtual DbSet<MealPlan> MealPlans { set; get; }
public virtual DbSet<Participant> Participant { set; get; } public virtual DbSet<Participant> Participants { set; get; }
public virtual DbSet<Organiser> Organisers { set; get; } public virtual DbSet<Organiser> Organisers { set; get; }
public virtual DbSet<Administrator> Administrators { set; get; } public virtual DbSet<Administrator> Administrators { set; get; }
public virtual DbSet<ConferenceBooking> ConferenceBookings { set; get; } public virtual DbSet<ConferenceBooking> ConferenceBookings { set; get; }
public virtual DbSet<Room> Rooms { set; get; } public virtual DbSet<Room> Rooms { set; get; }
public virtual DbSet<Dinner> Dinners { set; get; } public virtual DbSet<Dinner> Dinners { set; get; }
public virtual DbSet<ConferenceBookingDinner> ConferenceBookingDinners { set; get; }
public virtual DbSet<ConferenceParticipant> ConferenceParticipants { set; get; }
public virtual DbSet<MealPlanParticipant> MealPlanParticipants { set; get; }
public virtual DbSet<MealPlanRoom> MealPlanRooms { set; get; }
public virtual DbSet<RoomDinner> RoomDinners { set; get; }
} }
} }

View File

@ -0,0 +1,126 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace HotelDataBaseImplement.Implements
{
public class AdministratorStorage : IAdministratorStorage
{
public List<AdministratorViewModel> GetFullList()
{
using var context = new HotelDataBase();
return context.Administrators.Select(x => x.GetViewModel).ToList();
}
public List<AdministratorViewModel> GetFilteredList(AdministratorSearchModel model)
{
if (string.IsNullOrEmpty(model.AdministratorFIO))
{
return null;
}
using var context = new HotelDataBase();
return context.Administrators
.Include(x => x.ConferenceBookings)
.Include(x => x.Dinners)
.Include(x => x.Rooms)
.Where(x => x.AdministratorLogin.Contains(model.AdministratorLogin) && x.AdministratorPassword == model.AdministratorPassword)
.Select(x => x.GetViewModel)
.ToList();
}
public AdministratorViewModel? GetElement(AdministratorSearchModel model)
{
using var context = new HotelDataBase();
if(model.Id.HasValue)
{
return context.Administrators
.Include(x => x.ConferenceBookings)
.Include(x => x.Dinners)
.Include(x => x.Rooms)
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
}
if(!string.IsNullOrEmpty(model.AdministratorEmail) && !string.IsNullOrEmpty(model.AdministratorPassword))
{
return context.Administrators
.Include(x => x.ConferenceBookings)
.Include(x => x.Dinners)
.Include(x => x.Rooms)
.FirstOrDefault(x => x.AdministratorEmail.Equals(model.AdministratorEmail) && x.AdministratorPassword.Equals(model.AdministratorPassword))?
.GetViewModel;
}
if (!string.IsNullOrEmpty(model.AdministratorEmail))
{
return context.Administrators
.Include(x => x.ConferenceBookings)
.Include(x => x.Dinners)
.Include(x => x.Rooms)
.FirstOrDefault(x => x.AdministratorEmail.Equals(model.AdministratorEmail))?
.GetViewModel;
}
return null;
}
public AdministratorViewModel? Insert(AdministratorBindingModel model)
{
var newAdministrator = Administrator.Create(model);
if (string.IsNullOrEmpty(model.AdministratorFIO))
{
return new();
}
using var context = new HotelDataBase();
context.Administrators.Add(newAdministrator);
context.SaveChanges();
return newAdministrator.GetViewModel;
}
public AdministratorViewModel? Update(AdministratorBindingModel model)
{
using var context = new HotelDataBase();
var administrator = context.Administrators
.FirstOrDefault(x => x.Id == model.Id);
if (administrator == null)
{
return null;
}
administrator.Update(model);
context.SaveChanges();
return administrator.GetViewModel;
}
public AdministratorViewModel? Delete(AdministratorBindingModel model)
{
using var context = new HotelDataBase();
var element = context.Administrators.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Administrators.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,167 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace HotelDataBaseImplement.Implements
{
public class ConferenceBookingStorage : IConferenceBookingStorage
{
public List<ConferenceBookingViewModel> GetFullList()
{
using var context = new HotelDataBase();
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)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ConferenceBookingViewModel> GetFilteredList(ConferenceBookingSearchModel model)
{
if (!model.DateFrom.HasValue && !model.DateTo.HasValue && !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)
{
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.AdministratorId == model.AdministratorId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
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.PlaceСonference.Contains(model.PlaceСonference))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public ConferenceBookingViewModel? GetElement(ConferenceBookingSearchModel model)
{
if (string.IsNullOrEmpty(model.PlaceСonference) && !model.Id.HasValue)
{
return null;
}
using var context = new HotelDataBase();
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)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PlaceСonference) && x.PlaceСonference == model.PlaceСonference) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public ConferenceBookingViewModel? Insert(ConferenceBookingBindingModel model)
{
using var context = new HotelDataBase();
var newConferenceBooking = ConferenceBooking.Create(context, model);
if (newConferenceBooking == null)
{
return null;
}
context.ConferenceBookings.Add(newConferenceBooking);
context.SaveChanges();
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)
.FirstOrDefault(x => x.Id == newConferenceBooking.Id)
?.GetViewModel;
}
public ConferenceBookingViewModel? Update(ConferenceBookingBindingModel model)
{
using var context = new HotelDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var elem = context.ConferenceBookings
.Include(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.ThenInclude(x => x.ConferenceBookingDinner)
.ThenInclude(x => x.ConferenceBooking)
.ThenInclude(x => x.Conference)
.FirstOrDefault(rec => rec.Id == model.Id); if (elem == null)
{
return null;
}
elem.Update(model);
context.SaveChanges();
if (model.ConferenceBookingDinners != null)
elem.UpdateDinners(context, model);
transaction.Commit();
return elem.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ConferenceBookingViewModel? Delete(ConferenceBookingBindingModel model)
{
using var context = new HotelDataBase();
var element = context.ConferenceBookings
.Include(x => x.Dinners)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.ConferenceBookings.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,155 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelDataBaseImplement.Implements
{
public class ConferenceStorage : IConferenceStorage
{
public List<ConferenceViewModel> GetFullList()
{
using var context = new HotelDataBase();
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)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<ConferenceViewModel> GetFilteredList(ConferenceSearchModel model)
{
if (!model.OrganiserId.HasValue)
{
return new();
}
using var context = new HotelDataBase();
if (model.OrganiserId.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.OrganiserId == model.OrganiserId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
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.ConferenceName.Contains(model.ConferenceName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public ConferenceViewModel? GetElement(ConferenceSearchModel model)
{
if (string.IsNullOrEmpty(model.ConferenceName) && !model.Id.HasValue)
{
return null;
}
using var context = new HotelDataBase();
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)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ConferenceName) && x.ConferenceName == model.ConferenceName) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public ConferenceViewModel? Insert(ConferenceBindingModel model)
{
using var context = new HotelDataBase();
var newConference = Conference.Create(context, model);
if (newConference == null)
{
return null;
}
context.Conferences.Add(newConference);
context.SaveChanges();
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)
.FirstOrDefault(x => x.Id == newConference.Id)
?.GetViewModel;
}
public ConferenceViewModel? Update(ConferenceBindingModel model)
{
using var context = new HotelDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var elem = context.Conferences.FirstOrDefault(rec => rec.Id == model.Id);
if (elem == null)
{
return null;
}
elem.Update(model);
context.SaveChanges();
if (model.ConferenceParticipants != null)
elem.UpdateMembers(context, model);
transaction.Commit();
return elem.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public ConferenceViewModel? Delete(ConferenceBindingModel model)
{
using var context = new HotelDataBase();
var element = context.Conferences
.Include(x => x.Participants)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Conferences.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,133 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelDataBaseImplement.Implements
{
public class DinnerStorage : IDinnerStorage
{
public List<DinnerViewModel> GetFullList()
{
using var context = new HotelDataBase();
return context.Dinners
.Include(x => x.RoomDinners)
.ThenInclude(x => x.Room)
.Include(x => x.ConferenceBookingDinner)
.ThenInclude(x => x.ConferenceBooking)
.Include(x => x.Administrator)
.Select(x => x.GetViewModel)
.ToList();
}
public List<DinnerViewModel> GetFilteredList(DinnerSearchModel model)
{
if (string.IsNullOrEmpty(model.DinnerName) && !model.AdministratorId.HasValue)
{
return new();
}
using var context = new HotelDataBase();
if (model.AdministratorId.HasValue)
{
return context.Dinners
.Include(x => x.RoomDinners)
.ThenInclude(x => x.Room)
.Include(x => x.ConferenceBookingDinner)
.ThenInclude(x => x.ConferenceBooking)
.Include(x => x.Administrator)
.Where(x => x.AdministratorId == model.AdministratorId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Dinners
.Include(x => x.RoomDinners)
.ThenInclude(x => x.Room)
.Include(x => x.ConferenceBookingDinner)
.ThenInclude(x => x.ConferenceBooking)
.Include(x => x.Administrator)
.Where(x => x.DinnerName.Contains(model.DinnerName))
.Select(x => x.GetViewModel)
.ToList();
}
public DinnerViewModel? GetElement(DinnerSearchModel model)
{
if (string.IsNullOrEmpty(model.DinnerName) && !model.Id.HasValue)
{
return null;
}
using var context = new HotelDataBase();
return context.Dinners
.Include(x => x.RoomDinners)
.ThenInclude(x => x.Room)
.Include(x => x.ConferenceBookingDinner)
.ThenInclude(x => x.ConferenceBooking)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DinnerName) && x.DinnerName == model.DinnerName) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public DinnerViewModel? Insert(DinnerBindingModel model)
{
using var context = new HotelDataBase();
var newDinner = Dinner.Create(model);
if (newDinner == null)
{
return null;
}
context.Dinners.Add(newDinner);
context.SaveChanges();
return newDinner.GetViewModel;
}
public DinnerViewModel? Update(DinnerBindingModel model)
{
using var context = new HotelDataBase();
var dinner = context.Dinners.FirstOrDefault(x => x.Id == model.Id);
if (dinner == null)
{
return null;
}
dinner.Update(model);
context.SaveChanges();
return dinner.GetViewModel;
}
public DinnerViewModel? Delete(DinnerBindingModel model)
{
using var context = new HotelDataBase();
var element = context.Dinners.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Dinners.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,159 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelDataBaseImplement.Implements
{
public class MealPlanStorage : IMealPlanStorage
{
public List<MealPlanViewModel> GetFullList()
{
using var context = new HotelDataBase();
return context.MealPlans
.Include(x => x.Participants)
.ThenInclude(x => x.Participant)
.ThenInclude(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.Rooms)
.ThenInclude(x => x.Room)
.ThenInclude(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.Include(x => x.Organiser)
.Select(x => x.GetViewModel)
.ToList();
}
public List<MealPlanViewModel> GetFilteredList(MealPlanSearchModel model)
{
if (string.IsNullOrEmpty(model.MealPlanName) && !model.OrganiserId.HasValue)
{
return new();
}
using var context = new HotelDataBase();
if (model.OrganiserId.HasValue)
{
return context.MealPlans
.Include(x => x.Participants)
.ThenInclude(x => x.Participant)
.ThenInclude(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.Rooms)
.ThenInclude(x => x.Room)
.ThenInclude(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.Include(x => x.Organiser)
.Where(x => x.OrganiserId == model.OrganiserId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return context.MealPlans
.Include(x => x.Participants)
.ThenInclude(x => x.Participant)
.ThenInclude(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.Rooms)
.ThenInclude(x => x.Room)
.ThenInclude(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.Include(x => x.Organiser)
.Where(x => x.MealPlanName.Contains(model.MealPlanName))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public MealPlanViewModel? GetElement(MealPlanSearchModel model)
{
if (string.IsNullOrEmpty(model.MealPlanName) && !model.Id.HasValue)
{
return null;
}
using var context = new HotelDataBase();
return context.MealPlans
.Include(x => x.Participants)
.ThenInclude(x => x.Participant)
.ThenInclude(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.Rooms)
.ThenInclude(x => x.Room)
.ThenInclude(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.Include(x => x.Organiser)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.MealPlanName) && x.MealPlanName == model.MealPlanName) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public MealPlanViewModel? Insert(MealPlanBindingModel model)
{
using var context = new HotelDataBase();
var newMealPlan = MealPlan.Create(context, model);
if (newMealPlan == null)
{
return null;
}
context.MealPlans.Add(newMealPlan);
context.SaveChanges();
return newMealPlan.GetViewModel;
}
public MealPlanViewModel? Update(MealPlanBindingModel model)
{
using var context = new HotelDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var elem = context.MealPlans.FirstOrDefault(rec => rec.Id == model.Id);
if (elem == null)
{
return null;
}
elem.Update(model);
context.SaveChanges();
if (model.MealPlanParticipants != null)
elem.UpdateMembers(context, model);
transaction.Commit();
return elem.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public MealPlanViewModel? Delete(MealPlanBindingModel model)
{
using var context = new HotelDataBase();
var element = context.MealPlans
.Include(x => x.Participants)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.MealPlans.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,113 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace HotelDataBaseImplement.Implements
{
public class OrganiserStorage : IOrganiserStorage
{
public List<OrganiserViewModel> GetFullList()
{
using var context = new HotelDataBase();
return context.Organisers.Select(x => x.GetViewModel).ToList();
}
public List<OrganiserViewModel> GetFilteredList(OrganiserSearchModel model)
{
if (string.IsNullOrEmpty(model.OrganiserFIO))
{
return new();
}
using var context = new HotelDataBase();
return context.Organisers
.Include(x => x.MealPlans)
.Include(x => x.Participants)
.Include(x => x.Conferences)
.Where(x => x.OrganiserLogin.Contains(model.OrganiserLogin) && x.OrganiserPassword == model.OrganiserPassword)
.Select(x => x.GetViewModel)
.ToList();
}
public OrganiserViewModel? GetElement(OrganiserSearchModel model)
{
using var context = new HotelDataBase();
if (model.Id.HasValue)
{
return context.Organisers
.Include(x => x.MealPlans)
.Include(x => x.Participants)
.Include(x => x.Conferences)
.FirstOrDefault(x => x.Id == model.Id)?
.GetViewModel;
}
if (!string.IsNullOrEmpty(model.OrganiserEmail) && !string.IsNullOrEmpty(model.OrganiserPassword))
return context.Organisers
.Include(x => x.MealPlans)
.Include(x => x.Participants)
.Include(x => x.Conferences)
.FirstOrDefault(x => x.OrganiserEmail.Equals(model.OrganiserEmail) && x.OrganiserPassword.Equals(model.OrganiserPassword))?
.GetViewModel;
if (!string.IsNullOrEmpty(model.OrganiserEmail))
return context.Organisers
.Include(x => x.MealPlans)
.Include(x => x.Participants)
.Include(x => x.Conferences)
.FirstOrDefault(x => x.OrganiserEmail.Equals(model.OrganiserEmail))?
.GetViewModel;
return null;
}
public OrganiserViewModel? Insert(OrganiserBindingModel model)
{
var newOrganiser = Organiser.Create(model);
if(newOrganiser == null) return null;
using var context = new HotelDataBase();
context.Organisers.Add(newOrganiser);
context.SaveChanges();
return newOrganiser.GetViewModel;
}
public OrganiserViewModel? Update(OrganiserBindingModel model)
{
using var context = new HotelDataBase();
var organiser = context.Organisers.FirstOrDefault(x => x.Id == model.Id);
if (organiser == null) return null;
organiser.Update(model);
context.SaveChanges();
return organiser.GetViewModel;
}
public OrganiserViewModel? Delete(OrganiserBindingModel model)
{
using var context = new HotelDataBase();
var element = context.Organisers.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
context.Organisers.Remove(element);
context.SaveChanges();
}
return null;
}
}
}

View File

@ -0,0 +1,135 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Diagnostics.Metrics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelDataBaseImplement.Implements
{
public class ParticipantStorage : IParticipantStorage
{
public List<ParticipantViewModel> GetFullList()
{
using var context = new HotelDataBase();
return context.Participants
.Include(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.MealPlanParticipants)
.ThenInclude(x => x.MealPlan)
.Include(x => x.Organiser)
.Select(x => x.GetViewModel)
.ToList();
}
public List<ParticipantViewModel> GetFilteredList(ParticipantSearchModel model)
{
if (string.IsNullOrEmpty(model.ParticipantFIO) && !model.OrganiserId.HasValue)
{
return new();
}
using var context = new HotelDataBase();
if (model.OrganiserId.HasValue)
{
return context.Participants
.Include(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.MealPlanParticipants)
.ThenInclude(x => x.MealPlan)
.Include(x => x.Organiser)
.Where(x => x.OrganiserId == model.OrganiserId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Participants
.Include(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.MealPlanParticipants)
.ThenInclude(x => x.MealPlan)
.Include(x => x.Organiser)
.Where(x => x.ParticipantFIO.Contains(model.ParticipantFIO))
.Select(x => x.GetViewModel)
.ToList();
}
public ParticipantViewModel? GetElement(ParticipantSearchModel model)
{
if (string.IsNullOrEmpty(model.ParticipantFIO) && !model.Id.HasValue)
{
return null;
}
using var context = new HotelDataBase();
return context.Participants
.Include(x => x.ConferenceParticipants)
.ThenInclude(x => x.Conference)
.Include(x => x.MealPlanParticipants)
.ThenInclude(x => x.MealPlan)
.Include(x => x.Organiser)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ParticipantFIO) && x.ParticipantFIO == model.ParticipantFIO) || (model.Id.HasValue && x.Id == model.Id))?
.GetViewModel;
}
public ParticipantViewModel? Insert(ParticipantBindingModel model)
{
using var context = new HotelDataBase();
var newParticipant = Participant.Create(model);
if (newParticipant == null)
{
return null;
}
context.Participants.Add(newParticipant);
context.SaveChanges();
return newParticipant.GetViewModel;
}
public ParticipantViewModel? Update(ParticipantBindingModel model)
{
using var context = new HotelDataBase();
var participant = context.Participants.FirstOrDefault(x => x.Id == model.Id);
if (participant == null)
{
return null;
}
participant.Update(model);
context.SaveChanges();
return participant.GetViewModel;
}
public ParticipantViewModel? Delete(ParticipantBindingModel model)
{
using var context = new HotelDataBase();
var element = context.Participants.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Participants.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,184 @@
using HotelContracts.BindingModels;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
using HotelDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelDataBaseImplement.Implements
{
public class RoomStorage : IRoomStorage
{
public List<RoomViewModel> GetFullList()
{
using var context = new HotelDataBase();
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)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public List<RoomViewModel> GetFilteredList(RoomSearchModel model)
{
if (!model.Id.HasValue && !model.AdministratorId.HasValue)
{
return new();
}
using var context = new HotelDataBase();
if (model.AdministratorId.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.AdministratorId == model.AdministratorId)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
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.RoomNumber == model.RoomNumber)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public RoomViewModel? GetElement(RoomSearchModel model)
{
if (!model.Id.HasValue && model.RoomNumber != null)
{
return null;
}
using var context = new HotelDataBase();
var room = 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)
.FirstOrDefault(x => (model.RoomNumber != null && x.RoomNumber == model.RoomNumber) || (model.Id.HasValue && x.Id == model.Id));
return room?.GetViewModel;
}
public RoomViewModel? Insert(RoomBindingModel model)
{
using var context = new HotelDataBase();
var newRoom = Room.Create(context, model);
if (newRoom == null)
{
return null;
}
context.Rooms.Add(newRoom);
context.SaveChanges();
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)
.FirstOrDefault(x => x.Id == newRoom.Id)
?.GetViewModel;
}
public RoomViewModel? Update(RoomBindingModel model)
{
using var context = new HotelDataBase();
using var transaction = context.Database.BeginTransaction();
try
{
var elem = context.Rooms
.Include(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.ThenInclude(x => x.ConferenceBookingDinner)
.ThenInclude(x => x.ConferenceBooking)
.ThenInclude(x => x.Conference)
.FirstOrDefault(rec => rec.Id == model.Id);
if (elem == null)
{
return null;
}
elem.Update(model);
context.SaveChanges();
if (model.RoomDinners != null)
elem.UpdateDinners(context, model);
transaction.Commit();
return elem.GetViewModel;
}
catch
{
transaction.Rollback();
throw;
}
}
public RoomViewModel? Delete(RoomBindingModel model)
{
using var context = new HotelDataBase();
var element = context.Rooms
.Include(x => x.Dinners)
.ThenInclude(x => x.Dinner)
.ThenInclude(x => x.ConferenceBookingDinner)
.ThenInclude(x => x.ConferenceBooking)
.ThenInclude(x => x.Conference)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Rooms.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -1,8 +1,11 @@
using HotelDataModels.Models; using HotelContracts.BindingModels;
using HotelContracts.ViewModels;
using HotelDataModels.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -21,14 +24,89 @@ namespace HotelDataBaseImplement.Models
public int OrganiserId { get; private set; } public int OrganiserId { get; private set; }
private Dictionary<int, IParticipantModel> _conferenceMembers = null; public virtual Organiser Organiser { get; set; }
private Dictionary<int, IParticipantModel> _conferenceParticipents = null;
[ForeignKey("ConferenceId")]
public virtual List<ConferenceBooking> Bookings { get; set; } = new();
[ForeignKey("ConferenceId")]
public virtual List<ConferenceParticipant> Participants { get; set; } = new();
[NotMapped]
public Dictionary<int, IParticipantModel> ConferenceParticipants public Dictionary<int, IParticipantModel> ConferenceParticipants
{ {
get get
{ {
return _conferenceMembers; if (_conferenceParticipents == null)
{
using var context = new HotelDataBase();
_conferenceParticipents = Participants.ToDictionary(x => x.ParticipantId, x => (context.Participants
.FirstOrDefault(y => y.Id == x.ParticipantId)! as IParticipantModel));
}
return _conferenceParticipents;
} }
} }
public static Conference Create(HotelDataBase context, ConferenceBindingModel model)
{
return new Conference()
{
Id = model.Id,
ConferenceName = model.ConferenceName,
Subject = model.Subject,
OrganiserId = model.OrganiserId,
Participants = model.ConferenceParticipants.Select(x => new ConferenceParticipant
{
Participant = context.Participants.First(y => y.Id == x.Key),
}).ToList()
};
}
public void Update(ConferenceBindingModel model)
{
ConferenceName = model.ConferenceName;
Subject = model.Subject;
OrganiserId = model.OrganiserId;
}
public ConferenceViewModel GetViewModel => new()
{
Id = Id,
ConferenceName = ConferenceName,
Subject = Subject,
OrganiserId = OrganiserId,
ConferenceParticipants = ConferenceParticipants
};
public void UpdateMembers(HotelDataBase context, ConferenceBindingModel model)
{
var сonferenceParticipants = context.ConferenceParticipants.Where(rec => rec.ConferenceId == model.Id).ToList();
if (сonferenceParticipants != null && сonferenceParticipants.Count > 0)
{
context.ConferenceParticipants.RemoveRange(сonferenceParticipants.Where(rec => !model.ConferenceParticipants.ContainsKey(rec.ParticipantId)));
context.SaveChanges();
foreach (var updateParticipant in сonferenceParticipants)
{
model.ConferenceParticipants.Remove(updateParticipant.ParticipantId);
}
context.SaveChanges();
}
var conference = context.Conferences.First(x => x.Id == Id);
foreach (var cm in model.ConferenceParticipants)
{
context.ConferenceParticipants.Add(new ConferenceParticipant
{
Conference = conference,
Participant = context.Participants.First(x => x.Id == cm.Key),
});
context.SaveChanges();
}
_conferenceParticipents = null;
}
} }
} }

View File

@ -70,5 +70,35 @@ namespace HotelDataBaseImplement.Models
DateСonference = DateСonference, DateСonference = DateСonference,
ConferenceBookingDinners = ConferenceBookingDinners ConferenceBookingDinners = ConferenceBookingDinners
}; };
public void UpdateDinners(HotelDataBase context, ConferenceBookingBindingModel model)
{
var conferenceBookingDinners = context.ConferenceBookingDinners.Where(rec => rec.ConferenceBookingId == model.Id).ToList();
if (conferenceBookingDinners != null && conferenceBookingDinners.Count > 0)
{
context.ConferenceBookingDinners.RemoveRange(conferenceBookingDinners.Where(rec => !model.ConferenceBookingDinners.ContainsKey(rec.DinnerId)));
context.SaveChanges();
foreach (var updateDinner in conferenceBookingDinners)
{
model.ConferenceBookingDinners.Remove(updateDinner.DinnerId);
}
context.SaveChanges();
}
var conferenceBooking = context.ConferenceBookings.First(x => x.Id == Id);
foreach (var cm in model.ConferenceBookingDinners)
{
context.ConferenceBookingDinners.Add(new ConferenceBookingDinner
{
ConferenceBooking = conferenceBooking,
Dinner = context.Dinners.First(x => x.Id == cm.Key)
});
context.SaveChanges();
}
_conferenceBookingDinners = null;
}
} }
} }

View File

@ -1,6 +1,19 @@
namespace HotelDataBaseImplement.Models using System.ComponentModel.DataAnnotations;
using System.Diagnostics.Metrics;
namespace HotelDataBaseImplement.Models
{ {
public class ConferenceParticipant public class ConferenceParticipant
{ {
public int Id { get; set; }
[Required]
public int ParticipantId { get; set; }
[Required]
public int ConferenceId { get; set; }
public virtual Conference Conference { get; set; } = new();
public virtual Participant Participant { get; set; } = new();
} }
} }

View File

@ -25,7 +25,8 @@ namespace HotelDataBaseImplement.Models
[ForeignKey("DinnerId")] [ForeignKey("DinnerId")]
public virtual List<RoomDinner> RoomDinners { get; set; } = new(); public virtual List<RoomDinner> RoomDinners { get; set; } = new();
[ForeignKey("DinnerId")] [ForeignKey("DinnerId")]
public virtual List<ConferenceBookingDinner> ConferenceBookingDinner { get; set; } = new(); public virtual List<ConferenceBookingDinner> ConferenceBookingDinner { get; set; }
public static Dinner? Create(DinnerBindingModel model) public static Dinner? Create(DinnerBindingModel model)
{ {
if (model == null) if (model == null)

View File

@ -1,8 +1,110 @@
using HotelDataModels.Models; using HotelContracts.BindingModels;
using HotelContracts.ViewModels;
using HotelDataModels.Models;
using Npgsql.PostgresTypes;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Globalization;
namespace HotelDataBaseImplement.Models namespace HotelDataBaseImplement.Models
{ {
public class MealPlan : IMealPlanModel public class MealPlan : IMealPlanModel
{ {
public int Id { get; private set; }
[Required]
public string MealPlanName { get; set; } = string.Empty;
[Required]
public double MealPlanPrice { get; set; }
public int OrganiserId { get; private set; }
public virtual Organiser Organiser { get; set; }
private Dictionary<int, IParticipantModel> _mealPlanParticipants = null;
[ForeignKey("MealPlanId")]
public virtual List<MealPlanParticipant> Participants { get; set; } = new();
[ForeignKey("MealPlanId")]
public virtual List<MealPlanRoom> Rooms { get; set; } = new();
[NotMapped]
public Dictionary<int, IParticipantModel> MealPlanParticipants
{
get
{
if( _mealPlanParticipants == null )
{
using var contex = new HotelDataBase();
_mealPlanParticipants = Participants.ToDictionary(x => x.ParticipantId, x => (contex.Participants
.FirstOrDefault(y => y.Id == x.ParticipantId)! as IParticipantModel));
}
return _mealPlanParticipants;
}
}
public static MealPlan Create(HotelDataBase context, MealPlanBindingModel model)
{
return new MealPlan()
{
Id = model.Id,
MealPlanName = model.MealPlanName,
MealPlanPrice = model.MealPlanPrice,
OrganiserId = model.OrganiserId,
Participants = model.MealPlanParticipants.Select(x => new MealPlanParticipant
{
Participant = context.Participants.First(y => y.Id == x.Key),
}).ToList()
};
}
public void Update(MealPlanBindingModel model)
{
if (model == null) return;
MealPlanName = model.MealPlanName;
MealPlanPrice = model.MealPlanPrice;
OrganiserId = model.OrganiserId;
}
public MealPlanViewModel GetViewModel => new()
{
Id = Id,
MealPlanName = MealPlanName,
MealPlanPrice = MealPlanPrice,
OrganiserId = OrganiserId,
};
public void UpdateMembers(HotelDataBase context, MealPlanBindingModel model)
{
var mealPlanParticipants = context.MealPlanParticipants.Where(rec => rec.MealPlanId == model.Id).ToList();
if (mealPlanParticipants != null && mealPlanParticipants.Count > 0)
{
context.MealPlanParticipants.RemoveRange(mealPlanParticipants.Where(rec => !model.MealPlanParticipants.ContainsKey(rec.ParticipantId)));
context.SaveChanges();
foreach (var updateMember in mealPlanParticipants)
{
model.MealPlanParticipants.Remove(updateMember.ParticipantId);
}
context.SaveChanges();
}
var mealPlan = context.MealPlans.First(x => x.Id == Id);
foreach (var cm in model.MealPlanParticipants)
{
context.MealPlanParticipants.Add(new MealPlanParticipant
{
MealPlan = mealPlan,
Participant = context.Participants.First(x => x.Id == cm.Key)
});
context.SaveChanges();
}
_mealPlanParticipants = null;
}
} }
} }

View File

@ -1,6 +1,18 @@
namespace HotelDataBaseImplement.Models using System.ComponentModel.DataAnnotations;
namespace HotelDataBaseImplement.Models
{ {
public class MealPlanParticipant public class MealPlanParticipant
{ {
public int Id { get; set; }
[Required]
public int ParticipantId { get; set; }
[Required]
public int MealPlanId { get; set; }
public virtual MealPlan MealPlan { get; set; } = new();
public virtual Participant Participant { get; set; } = new();
} }
} }

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelDataBaseImplement.Models
{
public class MealPlanRoom
{
public int Id { get; set; }
[Required]
public int RoomId { get; set; }
[Required]
public int MealPlanId { get; set; }
public virtual MealPlan MealPlan { get; set; } = new();
public virtual Room Room { get; set; } = new();
}
}

View File

@ -16,7 +16,7 @@ namespace HotelDataBaseImplement.Models
public int Id { get; private set; } public int Id { get; private set; }
[Required] [Required]
public string FIO { get; set; } = string.Empty; public string ParticipantFIO { get; set; } = string.Empty;
[Required] [Required]
public string Number { get; set; } = string.Empty; public string Number { get; set; } = string.Empty;
@ -29,7 +29,7 @@ namespace HotelDataBaseImplement.Models
public virtual List<MealPlanParticipant> MealPlanParticipants { get; set; } = new(); public virtual List<MealPlanParticipant> MealPlanParticipants { get; set; } = new();
[ForeignKey("ParticipantId")] [ForeignKey("ParticipantId")]
public virtual List<ConferenceParticipant> ConferenceParticipant { get; set; } = new(); public virtual List<ConferenceParticipant> ConferenceParticipants { get; set; } = new();
public static Participant? Create(ParticipantBindingModel model) public static Participant? Create(ParticipantBindingModel model)
{ {
@ -37,7 +37,7 @@ namespace HotelDataBaseImplement.Models
return new Participant() return new Participant()
{ {
Id = model.Id, Id = model.Id,
FIO = model.FIO, ParticipantFIO = model.ParticipantFIO,
Number = model.Number, Number = model.Number,
OrganiserId = model.OrganiserId, OrganiserId = model.OrganiserId,
}; };
@ -48,10 +48,26 @@ namespace HotelDataBaseImplement.Models
return new Participant return new Participant
{ {
Id = model.Id, Id = model.Id,
FIO = model.FIO, ParticipantFIO = model.ParticipantFIO,
Number = model.Number, Number = model.Number,
OrganiserId = model.OrganiserId, OrganiserId = model.OrganiserId,
}; };
} }
public void Update(ParticipantBindingModel model)
{
if (model == null) return;
ParticipantFIO = model.ParticipantFIO;
Number = model.Number;
OrganiserId = model.OrganiserId;
}
public ParticipantViewModel GetViewModel => new()
{
Id = Id,
ParticipantFIO = ParticipantFIO,
Number = Number,
OrganiserId = OrganiserId,
};
} }
} }

View File

@ -25,8 +25,12 @@ namespace HotelDataBaseImplement.Models
public int? MealPlanId { get; private set; } public int? MealPlanId { get; private set; }
public virtual Administrator Administrator { get; set; } public virtual Administrator Administrator { get; set; }
public virtual MealPlan? MealPlan { get; set; } public virtual MealPlan? MealPlan { get; set; }
[ForeignKey("RoomId")] [ForeignKey("RoomId")]
public virtual List<RoomDinner> Dinners { get; set; } public virtual List<RoomDinner> Dinners { get; set; } = new();
[ForeignKey("RoomId")]
public virtual List<MealPlanRoom> MealPlanRooms { get; set; }
private Dictionary<int, IDinnerModel> _roomDinners = null; private Dictionary<int, IDinnerModel> _roomDinners = null;
[NotMapped] [NotMapped]
@ -81,5 +85,34 @@ namespace HotelDataBaseImplement.Models
RoomDinners = RoomDinners RoomDinners = RoomDinners
}; };
public void UpdateDinners(HotelDataBase context, RoomBindingModel model)
{
var roomDinners = context.RoomDinners.Where(rec => rec.RoomId == model.Id).ToList();
if (roomDinners != null && roomDinners.Count > 0)
{
context.RoomDinners.RemoveRange(roomDinners.Where(rec => !model.RoomDinners.ContainsKey(rec.DinnerId)));
context.SaveChanges();
foreach (var updateDinner in roomDinners)
{
model.RoomDinners.Remove(updateDinner.DinnerId);
}
context.SaveChanges();
}
var room = context.Rooms.First(x => x.Id == Id);
foreach (var cm in model.RoomDinners)
{
context.RoomDinners.Add(new RoomDinner
{
Room = room,
Dinner = context.Dinners.First(x => x.Id == cm.Key),
});
context.SaveChanges();
}
_roomDinners = null;
}
} }
} }

View File

@ -2,7 +2,7 @@
{ {
public interface IParticipantModel : IId public interface IParticipantModel : IId
{ {
string FIO { get; } string ParticipantFIO { get; }
string Number { get; } string Number { get; }
int OrganiserId { get; } int OrganiserId { get; }
} }

View File

@ -1,7 +1,7 @@
using HotelBusinessLogic.BusinessLogic; using HotelBusinessLogic.BusinessLogic;
using HotelContracts.BusinessLogicsContracts; using HotelContracts.BusinessLogicsContracts;
using HotelContracts.StoragesContracts; using HotelContracts.StoragesContracts;
using HotelDataBaseImplement.Implemets; using HotelDataBaseImplement.Implements;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);