перезагрузка 2
This commit is contained in:
parent
badd6a4a80
commit
09fc8ca9de
@ -62,7 +62,7 @@ namespace HotelBusinessLogic.BusinessLogic
|
|||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
model.MealPlanParticipants = new();
|
model.MealPlanParticipants = new();
|
||||||
|
|
||||||
if (_mealPlanStorage.Insert == null)
|
if (_mealPlanStorage.Insert(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert error");
|
_logger.LogWarning("Insert error");
|
||||||
return false;
|
return false;
|
||||||
@ -75,7 +75,7 @@ namespace HotelBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
|
||||||
if (_mealPlanStorage.Update == null)
|
if (_mealPlanStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update error");
|
_logger.LogWarning("Update error");
|
||||||
return false;
|
return false;
|
||||||
@ -90,7 +90,7 @@ namespace HotelBusinessLogic.BusinessLogic
|
|||||||
|
|
||||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
|
||||||
if (_mealPlanStorage.Delete == null)
|
if (_mealPlanStorage.Delete(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete error");
|
_logger.LogWarning("Delete error");
|
||||||
return false;
|
return false;
|
||||||
|
@ -109,7 +109,18 @@ namespace HotelDataBaseImplement.Implements
|
|||||||
|
|
||||||
context.MealPlans.Add(newMealPlan);
|
context.MealPlans.Add(newMealPlan);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newMealPlan.GetViewModel;
|
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)
|
||||||
@ -126,7 +137,7 @@ namespace HotelDataBaseImplement.Implements
|
|||||||
elem.Update(model);
|
elem.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
if (model.MealPlanParticipants != null)
|
if (model.MealPlanParticipants != null)
|
||||||
elem.UpdateMembers(context, model);
|
elem.UpdateParticipants(context, model);
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
return elem.GetViewModel;
|
return elem.GetViewModel;
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace HotelDataBaseImplement.Migrations
|
namespace HotelDataBaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(HotelDataBase))]
|
[DbContext(typeof(HotelDataBase))]
|
||||||
[Migration("20240428153913_InitMigration")]
|
[Migration("20240501104100_NewMigration")]
|
||||||
partial class InitMigration
|
partial class NewMigration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace HotelDataBaseImplement.Migrations
|
namespace HotelDataBaseImplement.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class InitMigration : Migration
|
public partial class NewMigration : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
@ -63,7 +63,6 @@ namespace HotelDataBaseImplement.Models
|
|||||||
|
|
||||||
public void Update(MealPlanBindingModel model)
|
public void Update(MealPlanBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null) return;
|
|
||||||
MealPlanName = model.MealPlanName;
|
MealPlanName = model.MealPlanName;
|
||||||
MealPlanPrice = model.MealPlanPrice;
|
MealPlanPrice = model.MealPlanPrice;
|
||||||
OrganiserId = model.OrganiserId;
|
OrganiserId = model.OrganiserId;
|
||||||
@ -75,9 +74,10 @@ namespace HotelDataBaseImplement.Models
|
|||||||
MealPlanName = MealPlanName,
|
MealPlanName = MealPlanName,
|
||||||
MealPlanPrice = MealPlanPrice,
|
MealPlanPrice = MealPlanPrice,
|
||||||
OrganiserId = OrganiserId,
|
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();
|
var mealPlanParticipants = context.MealPlanParticipants.Where(rec => rec.MealPlanId == model.Id).ToList();
|
||||||
|
|
||||||
|
@ -7,6 +7,10 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<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" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user