Compare commits
3 Commits
f1ff090bc1
...
f80eb3c08c
Author | SHA1 | Date | |
---|---|---|---|
|
f80eb3c08c | ||
|
205cc3df40 | ||
|
d4b269564b |
@ -22,7 +22,6 @@
|
|||||||
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj" />
|
<ProjectReference Include="..\PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaShopFileImplement\PizzeriaFileImplement.csproj" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -12,13 +12,13 @@ namespace PizzeriaBusinessLogic
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
private readonly IShopStorage _shopStorage;
|
private readonly IShopLogic _shopLogic;
|
||||||
private readonly IPizzaStorage _pizzaStorage;
|
private readonly IPizzaStorage _pizzaStorage;
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage, IPizzaStorage pizzaStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IPizzaStorage pizzaStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
_shopStorage = shopStorage;
|
_shopLogic = shopLogic;
|
||||||
_pizzaStorage = pizzaStorage;
|
_pizzaStorage = pizzaStorage;
|
||||||
}
|
}
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
@ -74,7 +74,7 @@ namespace PizzeriaBusinessLogic
|
|||||||
{
|
{
|
||||||
var pizza = _pizzaStorage.GetElement(new PizzaSearchModel { Id = model.PizzaId });
|
var pizza = _pizzaStorage.GetElement(new PizzaSearchModel { Id = model.PizzaId });
|
||||||
|
|
||||||
if(!_shopStorage.TryRestoreShops(pizza, model.Count))
|
if(!TryRestoreShops(pizza, model.Count))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Incorrect count.");
|
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Incorrect count.");
|
||||||
throw new ArgumentException("Количество изделий слишком велико");
|
throw new ArgumentException("Количество изделий слишком велико");
|
||||||
@ -124,5 +124,38 @@ namespace PizzeriaBusinessLogic
|
|||||||
_logger.LogInformation("Sum:{ Sum}. Id: { Id}", model.Sum, model.Id);
|
_logger.LogInformation("Sum:{ Sum}. Id: { Id}", model.Sum, model.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool TryRestoreShops(IPizzaModel pizza, int count)
|
||||||
|
{
|
||||||
|
int freePlaces = 0;
|
||||||
|
|
||||||
|
_shopLogic.ReadList(null).ForEach(x =>
|
||||||
|
{
|
||||||
|
int currentFreePlaces = x.Capacity;
|
||||||
|
foreach (var pair in x.ShopPizzas)
|
||||||
|
{
|
||||||
|
currentFreePlaces -= pair.Value.Item2;
|
||||||
|
}
|
||||||
|
freePlaces += currentFreePlaces;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (freePlaces < count) return false;
|
||||||
|
|
||||||
|
_shopLogic.ReadList(null).ForEach(x =>
|
||||||
|
{
|
||||||
|
if (count <= 0) return;
|
||||||
|
|
||||||
|
int currentFreePlaces = x.Capacity;
|
||||||
|
foreach (var elem in x.ShopPizzas)
|
||||||
|
{
|
||||||
|
currentFreePlaces -= elem.Value.Item2;
|
||||||
|
}
|
||||||
|
|
||||||
|
_shopLogic.AddPizza(new ShopSearchModel { Id = x.Id }, pizza, Math.Min(currentFreePlaces, count));
|
||||||
|
count -= currentFreePlaces;
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -141,6 +141,7 @@ namespace PizzeriaBusinessLogic
|
|||||||
ShopName = model.ShopName,
|
ShopName = model.ShopName,
|
||||||
OpenTime = model.OpenTime,
|
OpenTime = model.OpenTime,
|
||||||
Addres = model.Addres,
|
Addres = model.Addres,
|
||||||
|
Capacity = model.Capacity,
|
||||||
ShopPizzas = model.ShopPizzas,
|
ShopPizzas = model.ShopPizzas,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ namespace PizzeriaContracts.StoragesContracts
|
|||||||
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
List<ShopViewModel> GetFilteredList(ShopSearchModel model);
|
||||||
ShopViewModel? GetElement(ShopSearchModel model);
|
ShopViewModel? GetElement(ShopSearchModel model);
|
||||||
bool TrySellPizza(IPizzaModel pizza, int count);
|
bool TrySellPizza(IPizzaModel pizza, int count);
|
||||||
bool TryRestoreShops(IPizzaModel pizza, int count);
|
|
||||||
ShopViewModel? Insert(ShopBindingModel model);
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
248
Pizzeria/PizzeriaDatabaseImplement/Migrations/20230423174224_AddShop.Designer.cs
generated
Normal file
248
Pizzeria/PizzeriaDatabaseImplement/Migrations/20230423174224_AddShop.Designer.cs
generated
Normal file
@ -0,0 +1,248 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using PizzeriaDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PizzeriaDatabase))]
|
||||||
|
[Migration("20230423174224_AddShop")]
|
||||||
|
partial class AddShop
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("PizzaName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("double precision");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Pizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.ToTable("PizzaComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Addres")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("Capacity")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("OpenTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopPizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("PizzaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Pizza");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.models.Component", "Component")
|
||||||
|
.WithMany("PizzaComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("PizzaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Pizza");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("PizzaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.models.Shop", "Shop")
|
||||||
|
.WithMany("Pizzas")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Pizza");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("PizzaComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pizzas");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddShop : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Shops",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
ShopName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Addres = table.Column<string>(type: "text", nullable: false),
|
||||||
|
OpenTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
Capacity = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ShopPizzas",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
|
PizzaId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
ShopId = table.Column<int>(type: "integer", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "integer", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ShopPizzas", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopPizzas_Pizzas_PizzaId",
|
||||||
|
column: x => x.PizzaId,
|
||||||
|
principalTable: "Pizzas",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopPizzas_Shops_ShopId",
|
||||||
|
column: x => x.ShopId,
|
||||||
|
principalTable: "Shops",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopPizzas_PizzaId",
|
||||||
|
table: "ShopPizzas",
|
||||||
|
column: "PizzaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopPizzas_ShopId",
|
||||||
|
table: "ShopPizzas",
|
||||||
|
column: "ShopId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ShopPizzas");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Shops");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -121,6 +121,59 @@ namespace PizzeriaDatabaseImplement.Migrations
|
|||||||
b.ToTable("PizzaComponents");
|
b.ToTable("PizzaComponents");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("Addres")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("Capacity")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("OpenTime")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopPizzas");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||||
@ -151,6 +204,25 @@ namespace PizzeriaDatabaseImplement.Migrations
|
|||||||
b.Navigation("Pizza");
|
b.Navigation("Pizza");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.ShopPizza", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("PizzaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.models.Shop", "Shop")
|
||||||
|
.WithMany("Pizzas")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Pizza");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("PizzaComponents");
|
b.Navigation("PizzaComponents");
|
||||||
@ -162,6 +234,11 @@ namespace PizzeriaDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.Navigation("Orders");
|
b.Navigation("Orders");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pizzas");
|
||||||
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,11 @@ using PizzeriaContracts.ViewModels;
|
|||||||
using PizzeriaDataModels;
|
using PizzeriaDataModels;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.models
|
namespace PizzeriaDatabaseImplement.models
|
||||||
{
|
{
|
||||||
public class Shop : IShopModel
|
public class Shop : IShopModel
|
||||||
{
|
{
|
||||||
[Required]
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
public string ShopName { get; set; } = string.Empty;
|
public string ShopName { get; set; } = string.Empty;
|
||||||
@ -43,8 +41,7 @@ namespace PizzeriaDatabaseImplement.models
|
|||||||
Addres = model.Addres,
|
Addres = model.Addres,
|
||||||
OpenTime = model.OpenTime,
|
OpenTime = model.OpenTime,
|
||||||
Capacity = model.Capacity,
|
Capacity = model.Capacity,
|
||||||
Pizzas = model.ShopPizzas.Select(x => new
|
Pizzas = model.ShopPizzas.Select(x => new ShopPizza
|
||||||
ShopPizza
|
|
||||||
{
|
{
|
||||||
Pizza = context.Pizzas.First(y => y.Id == x.Key),
|
Pizza = context.Pizzas.First(y => y.Id == x.Key),
|
||||||
Count = x.Value.Item2
|
Count = x.Value.Item2
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using PizzeriaContracts.SearchModels;
|
using PizzeriaContracts.SearchModels;
|
||||||
using PizzeriaContracts.StoragesContracts;
|
using PizzeriaContracts.StoragesContracts;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels;
|
||||||
using PizzeriaListImplement.Models;
|
using PizzeriaListImplement.Models;
|
||||||
|
|
||||||
namespace PizzeriaListImplement.Implements
|
namespace PizzeriaListImplement.Implements
|
||||||
@ -112,5 +113,10 @@ namespace PizzeriaListImplement.Implements
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TrySellPizza(IPizzaModel pizza, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,64 +42,6 @@ namespace PizzeriaFileImplement.Implements
|
|||||||
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryRestoreShops(IPizzaModel pizza, int count)
|
|
||||||
{
|
|
||||||
int freePlaces = 0;
|
|
||||||
|
|
||||||
source.Shops.ForEach(x =>
|
|
||||||
{
|
|
||||||
int currentFreePlaces = x.Capacity;
|
|
||||||
foreach (var pair in x.ShopPizzas)
|
|
||||||
{
|
|
||||||
currentFreePlaces -= pair.Value.Item2;
|
|
||||||
}
|
|
||||||
freePlaces += currentFreePlaces;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (freePlaces < count) return false;
|
|
||||||
|
|
||||||
source.Shops.ForEach(x =>
|
|
||||||
{
|
|
||||||
int currentFreePlaces = x.Capacity;
|
|
||||||
foreach (var elem in x.ShopPizzas)
|
|
||||||
{
|
|
||||||
currentFreePlaces -= elem.Value.Item2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!x.ShopPizzas.TryGetValue(pizza.Id, out var check))
|
|
||||||
{
|
|
||||||
x.ShopPizzas.Add(pizza.Id, (pizza, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
x.ShopPizzas.TryGetValue(pizza.Id, out var pair);
|
|
||||||
|
|
||||||
if (count >= currentFreePlaces)
|
|
||||||
{
|
|
||||||
count -= currentFreePlaces;
|
|
||||||
x.ShopPizzas[pizza.Id] = (pizza, pair.Item2 + currentFreePlaces);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
x.ShopPizzas[pizza.Id] = (pizza, pair.Item2 + count);
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
x.Update(new ShopBindingModel
|
|
||||||
{
|
|
||||||
Id = x.Id,
|
|
||||||
Addres = x.Addres,
|
|
||||||
Capacity = x.Capacity,
|
|
||||||
OpenTime = x.OpenTime,
|
|
||||||
ShopName = x.ShopName,
|
|
||||||
ShopPizzas = x.ShopPizzas
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
source.SaveShops();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TrySellPizza(IPizzaModel pizza, int count)
|
public bool TrySellPizza(IPizzaModel pizza, int count)
|
||||||
{
|
{
|
||||||
int hasCount = 0;
|
int hasCount = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user