Почти всё
This commit is contained in:
parent
32c42afffa
commit
7f95f9d161
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JewelryStoreContracts.ViewModels
|
||||
{
|
||||
public class JewelCount
|
||||
{
|
||||
public JewelViewModel Jewel { get; set; }
|
||||
public int Count { get; set; } = new();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JewelryStoreContracts.ViewModels
|
||||
{
|
||||
public class ShopJewelViewModel
|
||||
{
|
||||
public StoreViewModel Shop { get; set; } = new();
|
||||
public Dictionary<int, JewelCount> ShopJewel { get; set; } = new();
|
||||
}
|
||||
}
|
@ -5,121 +5,75 @@ using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
namespace JewelryStoreDatabaseImplement.Migrations
|
||||
{
|
||||
|
||||
/// <inheritdoc />
|
||||
public partial class InitialCreate : Migration
|
||||
public partial class Hard_init : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Adress = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
JewelMaxCount = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Jewels",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
JewelName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Jewels", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "JewelComponents",
|
||||
name: "ShopJewels",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
JewelId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_JewelComponents", x => x.Id);
|
||||
table.PrimaryKey("PK_ShopJewels", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_JewelComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_JewelComponents_Jewels_JewelId",
|
||||
name: "FK_ShopJewels_Jewels_JewelId",
|
||||
column: x => x.JewelId,
|
||||
principalTable: "Jewels",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
JewelId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Jewels_JewelId",
|
||||
column: x => x.JewelId,
|
||||
principalTable: "Jewels",
|
||||
name: "FK_ShopJewels_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_JewelComponents_ComponentId",
|
||||
table: "JewelComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_JewelComponents_JewelId",
|
||||
table: "JewelComponents",
|
||||
name: "IX_ShopJewels_JewelId",
|
||||
table: "ShopJewels",
|
||||
column: "JewelId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_JewelId",
|
||||
table: "Orders",
|
||||
column: "JewelId");
|
||||
name: "IX_ShopJewels_ShopId",
|
||||
table: "ShopJewels",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "JewelComponents");
|
||||
name: "ShopJewels");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Jewels");
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
@ -67,6 +67,44 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("JewelId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("JewelId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Jewel", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -113,7 +151,7 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
||||
b.ToTable("JewelComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
@ -121,53 +159,49 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
b.Property<string>("Adress")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("JewelMaxCount")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.ShopJewels", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("JewelId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("JewelId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
|
||||
{
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("JewelComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("JewelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Jewel");
|
||||
b.ToTable("ShopJewels");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Order", b =>
|
||||
@ -189,6 +223,44 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
||||
b.Navigation("Jewel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.JewelComponent", b =>
|
||||
{
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("JewelComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("JewelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Jewel");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.ShopJewels", b =>
|
||||
{
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Jewel", "Jewel")
|
||||
.WithMany("ShopJewels")
|
||||
.HasForeignKey("JewelId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("JewelryStoreDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Jewels")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Jewel");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
@ -205,6 +277,11 @@ namespace JewelryStoreDatabaseImplement.Migrations
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("JewelryStoreDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Jewels");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,12 @@ namespace JewelryStoreFileImplement
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string JewelFileName = "Jewel.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Jewel> Jewels { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public List<Store> Shops { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
@ -31,6 +33,7 @@ namespace JewelryStoreFileImplement
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
|
||||
public void SaveClients() => SaveData(Clients, OrderFileName, "Clients", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
@ -38,6 +41,7 @@ namespace JewelryStoreFileImplement
|
||||
Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
|
@ -0,0 +1,12 @@
|
||||
namespace JewelryStoreRestApi
|
||||
{
|
||||
public class APIConfig
|
||||
{
|
||||
public static string? ShopPassword;
|
||||
|
||||
public static void LoadData(IConfiguration configuration)
|
||||
{
|
||||
ShopPassword = configuration["ShopAPIPassword"];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,157 @@
|
||||
using JewelryStoreContracts.BindingModels;
|
||||
using JewelryStoreContracts.BusinessLogicsContracts;
|
||||
using JewelryStoreContracts.SearchModels;
|
||||
using JewelryStoreContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace JewelryStoreRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ShopController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreLogic _shopLogic;
|
||||
|
||||
public ShopController(ILogger<ShopController> logger, IStoreLogic shopLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_shopLogic = shopLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public bool Authentication(string password)
|
||||
{
|
||||
return CheckPassword(password);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public List<StoreViewModel>? GetShopList(string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
return _shopLogic.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка магазинов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ShopJewelViewModel? GetShop(int shopId, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
try
|
||||
{
|
||||
var shop = _shopLogic.ReadElement(new StoreSearchModel { Id = shopId });
|
||||
return new ShopJewelViewModel
|
||||
{
|
||||
Shop = shop,
|
||||
ShopJewel = shop.ShopJewels.ToDictionary(x => x.Key, x => new JewelCount
|
||||
{
|
||||
Jewel = new JewelViewModel()
|
||||
{
|
||||
Id = x.Value.Item1.Id,
|
||||
JewelName = x.Value.Item1.PizzaName,
|
||||
JewelComponents = x.Value.Item1.JewelComponents,
|
||||
Price = x.Value.Item1.Price,
|
||||
},
|
||||
Count = x.Value.Item2
|
||||
})
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateShop(StoreBindingModel model, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateShop(StoreBindingModel model, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete]
|
||||
public void DeleteShop(int shopId, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.Delete(new StoreBindingModel { Id = shopId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления магазина");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void MakeSypply(SupplyBindingModel model, string password)
|
||||
{
|
||||
if (!CheckPassword(password))
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
_shopLogic.MakeSupply(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания поставки в магазин");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckPassword(string password)
|
||||
{
|
||||
return APIConfig.ShopPassword == password;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,10 +15,11 @@ builder.Logging.AddLog4Net("log4net.config");
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IJewelStorage, JewelStorage>();
|
||||
|
||||
builder.Services.AddTransient<IStoreStorage, StoreStorage>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IJewelLogic, JewelLogic>();
|
||||
builder.Services.AddTransient<IStoreLogic, StoreLogic>();
|
||||
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
@ -5,5 +5,6 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"ShopAPIPassword": "123456"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user