перезагрузка 2

This commit is contained in:
Salikh 2024-05-01 17:00:04 +04:00
parent badd6a4a80
commit 09fc8ca9de
6 changed files with 37 additions and 22 deletions

View File

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

View File

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

View File

@ -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
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)

View File

@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace HotelDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitMigration : Migration
public partial class NewMigration : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)

View File

@ -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();

View File

@ -7,6 +7,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.11">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>