перезагрузка 2
This commit is contained in:
parent
badd6a4a80
commit
09fc8ca9de
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)
|
@ -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)
|
@ -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();
|
||||
|
||||
|
@ -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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user