diff --git a/Hotel/HotelBusinessLogic/BusinessLogic/MealPlanLogic.cs b/Hotel/HotelBusinessLogic/BusinessLogic/MealPlanLogic.cs index 6b08839..6bf22ed 100644 --- a/Hotel/HotelBusinessLogic/BusinessLogic/MealPlanLogic.cs +++ b/Hotel/HotelBusinessLogic/BusinessLogic/MealPlanLogic.cs @@ -62,7 +62,7 @@ namespace HotelBusinessLogic.BusinessLogic CheckModel(model); model.MealPlanParticipants = new(); - if (_mealPlanStorage.Insert == null) + if (_mealPlanStorage.Insert(model) == null) { _logger.LogWarning("Insert error"); return false; @@ -75,7 +75,7 @@ namespace HotelBusinessLogic.BusinessLogic { CheckModel(model); - if (_mealPlanStorage.Update == null) + if (_mealPlanStorage.Update(model) == null) { _logger.LogWarning("Update error"); return false; @@ -90,7 +90,7 @@ namespace HotelBusinessLogic.BusinessLogic _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_mealPlanStorage.Delete == null) + if (_mealPlanStorage.Delete(model) == null) { _logger.LogWarning("Delete error"); return false; diff --git a/Hotel/HotelDataBaseImplement/Implements/MealPlanStorage.cs b/Hotel/HotelDataBaseImplement/Implements/MealPlanStorage.cs index d89ee88..a853037 100644 --- a/Hotel/HotelDataBaseImplement/Implements/MealPlanStorage.cs +++ b/Hotel/HotelDataBaseImplement/Implements/MealPlanStorage.cs @@ -97,22 +97,33 @@ namespace HotelDataBaseImplement.Implements .GetViewModel; } - public MealPlanViewModel? Insert(MealPlanBindingModel model) - { - using var context = new HotelDataBase(); - var newMealPlan = MealPlan.Create(context, model); + public MealPlanViewModel? Insert(MealPlanBindingModel model) + { + using var context = new HotelDataBase(); + var newMealPlan = MealPlan.Create(context, model); - if (newMealPlan == null) - { - return null; - } + if (newMealPlan == null) + { + return null; + } - context.MealPlans.Add(newMealPlan); - context.SaveChanges(); - return newMealPlan.GetViewModel; - } + context.MealPlans.Add(newMealPlan); + context.SaveChanges(); + 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 => x.Id == newMealPlan.Id) + ?.GetViewModel; + } - public MealPlanViewModel? Update(MealPlanBindingModel model) + public MealPlanViewModel? Update(MealPlanBindingModel model) { using var context = new HotelDataBase(); using var transaction = context.Database.BeginTransaction(); @@ -126,7 +137,7 @@ namespace HotelDataBaseImplement.Implements elem.Update(model); context.SaveChanges(); if (model.MealPlanParticipants != null) - elem.UpdateMembers(context, model); + elem.UpdateParticipants(context, model); transaction.Commit(); return elem.GetViewModel; } diff --git a/Hotel/HotelDataBaseImplement/Migrations/20240428153913_InitMigration.Designer.cs b/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.Designer.cs similarity index 99% rename from Hotel/HotelDataBaseImplement/Migrations/20240428153913_InitMigration.Designer.cs rename to Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.Designer.cs index 865f521..e7cff3a 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/20240428153913_InitMigration.Designer.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace HotelDataBaseImplement.Migrations { [DbContext(typeof(HotelDataBase))] - [Migration("20240428153913_InitMigration")] - partial class InitMigration + [Migration("20240501104100_NewMigration")] + partial class NewMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) diff --git a/Hotel/HotelDataBaseImplement/Migrations/20240428153913_InitMigration.cs b/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.cs similarity index 99% rename from Hotel/HotelDataBaseImplement/Migrations/20240428153913_InitMigration.cs rename to Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.cs index f927f0c..9e472bb 100644 --- a/Hotel/HotelDataBaseImplement/Migrations/20240428153913_InitMigration.cs +++ b/Hotel/HotelDataBaseImplement/Migrations/20240501104100_NewMigration.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace HotelDataBaseImplement.Migrations { /// - public partial class InitMigration : Migration + public partial class NewMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) diff --git a/Hotel/HotelDataBaseImplement/Models/MealPlan.cs b/Hotel/HotelDataBaseImplement/Models/MealPlan.cs index b752e9d..4eab1aa 100644 --- a/Hotel/HotelDataBaseImplement/Models/MealPlan.cs +++ b/Hotel/HotelDataBaseImplement/Models/MealPlan.cs @@ -63,7 +63,6 @@ namespace HotelDataBaseImplement.Models public void Update(MealPlanBindingModel model) { - if (model == null) return; MealPlanName = model.MealPlanName; MealPlanPrice = model.MealPlanPrice; OrganiserId = model.OrganiserId; @@ -75,9 +74,10 @@ namespace HotelDataBaseImplement.Models MealPlanName = MealPlanName, MealPlanPrice = MealPlanPrice, OrganiserId = OrganiserId, + MealPlanParticipants = MealPlanParticipants }; - public void UpdateMembers(HotelDataBase context, MealPlanBindingModel model) + public void UpdateParticipants(HotelDataBase context, MealPlanBindingModel model) { var mealPlanParticipants = context.MealPlanParticipants.Where(rec => rec.MealPlanId == model.Id).ToList(); diff --git a/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj b/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj index c034399..2c26fa5 100644 --- a/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj +++ b/Hotel/HotelOrganiserApp/HotelOrganiserApp.csproj @@ -7,6 +7,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive +