Compare commits
No commits in common. "f80eb3c08cb173ca1dceea92ff1a384d2055ceac" and "f1ff090bc19537e4dcbc657f4d2d0cc76984368c" have entirely different histories.
f80eb3c08c
...
f1ff090bc1
@ -22,6 +22,7 @@
|
|||||||
<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 IShopLogic _shopLogic;
|
private readonly IShopStorage _shopStorage;
|
||||||
private readonly IPizzaStorage _pizzaStorage;
|
private readonly IPizzaStorage _pizzaStorage;
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IPizzaStorage pizzaStorage)
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage, IPizzaStorage pizzaStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
_shopLogic = shopLogic;
|
_shopStorage = shopStorage;
|
||||||
_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(!TryRestoreShops(pizza, model.Count))
|
if(!_shopStorage.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,38 +124,5 @@ 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,7 +141,6 @@ 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,6 +11,7 @@ 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);
|
||||||
|
@ -1,248 +0,0 @@
|
|||||||
// <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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +0,0 @@
|
|||||||
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,59 +121,6 @@ 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")
|
||||||
@ -204,25 +151,6 @@ 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");
|
||||||
@ -234,11 +162,6 @@ 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,11 +3,13 @@ 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;
|
||||||
@ -41,7 +43,8 @@ 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 ShopPizza
|
Pizzas = model.ShopPizzas.Select(x => new
|
||||||
|
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,7 +2,6 @@
|
|||||||
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
|
||||||
@ -113,10 +112,5 @@ namespace PizzeriaListImplement.Implements
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TrySellPizza(IPizzaModel pizza, int count)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,64 @@ 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