rest api
This commit is contained in:
parent
66b98e27e2
commit
1976b6b183
@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantListImp
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantFileImplement", "PrecastConcretePlantFileImplement\PrecastConcretePlantFileImplement.csproj", "{F30348DF-E10F-4D90-957A-9F8BDA2051FC}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantFileImplement", "PrecastConcretePlantFileImplement\PrecastConcretePlantFileImplement.csproj", "{F30348DF-E10F-4D90-957A-9F8BDA2051FC}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantDatabaseImplement", "PrecastConcretePlantDatabaseImplement\PrecastConcretePlantDatabaseImplement.csproj", "{D298F0E7-CD5E-4FD2-9341-706F4BF75998}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrecastConcretePlantDatabaseImplement", "PrecastConcretePlantDatabaseImplement\PrecastConcretePlantDatabaseImplement.csproj", "{D298F0E7-CD5E-4FD2-9341-706F4BF75998}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrecastConcretePlantRestApi", "PrecastConcretePlantRestApi\PrecastConcretePlantRestApi.csproj", "{9C1CD48A-67B2-4A22-8D05-6B465A8DAA63}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -51,6 +53,10 @@ Global
|
|||||||
{D298F0E7-CD5E-4FD2-9341-706F4BF75998}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{D298F0E7-CD5E-4FD2-9341-706F4BF75998}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{D298F0E7-CD5E-4FD2-9341-706F4BF75998}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{D298F0E7-CD5E-4FD2-9341-706F4BF75998}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{D298F0E7-CD5E-4FD2-9341-706F4BF75998}.Release|Any CPU.Build.0 = Release|Any CPU
|
{D298F0E7-CD5E-4FD2-9341-706F4BF75998}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{9C1CD48A-67B2-4A22-8D05-6B465A8DAA63}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{9C1CD48A-67B2-4A22-8D05-6B465A8DAA63}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{9C1CD48A-67B2-4A22-8D05-6B465A8DAA63}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{9C1CD48A-67B2-4A22-8D05-6B465A8DAA63}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,214 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using PrecastConcretePlantDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PrecastConcretePlantDatabase))]
|
||||||
|
[Migration("20240407190406_ClientAddition")]
|
||||||
|
partial class ClientAddition
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.16")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClientFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Clients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.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>("ReinforcedId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ClientId");
|
||||||
|
|
||||||
|
b.HasIndex("ReinforcedId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.Property<string>("ReinforcedName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Reinforceds");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ReinforcedId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("ReinforcedId");
|
||||||
|
|
||||||
|
b.ToTable("ReinforcedComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ClientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ReinforcedId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Client");
|
||||||
|
|
||||||
|
b.Navigation("Reinforced");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.ReinforcedComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("ReinforcedComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("ReinforcedId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Reinforced");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("ReinforcedComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Reinforced", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,68 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PrecastConcretePlantDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class ClientAddition : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "Orders",
|
||||||
|
type: "int",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Clients",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Orders_ClientId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "ClientId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_Orders_Clients_ClientId",
|
||||||
|
table: "Orders",
|
||||||
|
column: "ClientId",
|
||||||
|
principalTable: "Clients",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_Orders_Clients_ClientId",
|
||||||
|
table: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Clients");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_Orders_ClientId",
|
||||||
|
table: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "ClientId",
|
||||||
|
table: "Orders");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,31 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClientFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Clients");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -50,6 +75,9 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ClientId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Count")
|
b.Property<int>("Count")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
@ -70,6 +98,8 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ClientId");
|
||||||
|
|
||||||
b.HasIndex("ReinforcedId");
|
b.HasIndex("ReinforcedId");
|
||||||
|
|
||||||
b.ToTable("Orders");
|
b.ToTable("Orders");
|
||||||
@ -123,12 +153,20 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
|
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Client", "Client")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ClientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
b.HasOne("PrecastConcretePlantDatabaseImplement.Models.Reinforced", "Reinforced")
|
||||||
.WithMany("Orders")
|
.WithMany("Orders")
|
||||||
.HasForeignKey("ReinforcedId")
|
.HasForeignKey("ReinforcedId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Client");
|
||||||
|
|
||||||
b.Navigation("Reinforced");
|
b.Navigation("Reinforced");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -151,6 +189,11 @@ namespace PrecastConcretePlantDatabaseImplement.Migrations
|
|||||||
b.Navigation("Reinforced");
|
b.Navigation("Reinforced");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
modelBuilder.Entity("PrecastConcretePlantDatabaseImplement.Models.Component", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("ReinforcedComponents");
|
b.Navigation("ReinforcedComponents");
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using PrecastConcretePlantContracts.BindingModels;
|
||||||
|
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||||||
|
using PrecastConcretePlantContracts.SearchModels;
|
||||||
|
using PrecastConcretePlantContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace PrecastConcretePlantRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class ClientController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IClientLogic _logic;
|
||||||
|
|
||||||
|
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public ClientViewModel? Login(string login, string password)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _logic.ReadElement(new ClientSearchModel
|
||||||
|
{
|
||||||
|
Email = login,
|
||||||
|
Password = password
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка входа в систему");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Register(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка регистрации");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateData(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка обновления данных");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using PrecastConcretePlantContracts.BindingModels;
|
||||||
|
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||||||
|
using PrecastConcretePlantContracts.SearchModels;
|
||||||
|
using PrecastConcretePlantContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace PrecastConcretePlantRestApi.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class MainController : Controller
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
private readonly IOrderLogic _order;
|
||||||
|
|
||||||
|
private readonly IReinforcedLogic _reinforced;
|
||||||
|
|
||||||
|
public MainController(ILogger<MainController> logger, IOrderLogic order, IReinforcedLogic reinforced)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_order = order;
|
||||||
|
_reinforced = reinforced;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<ReinforcedViewModel>? GetReinforcedList()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _reinforced.ReadList(null);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка изделий");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public ReinforcedViewModel? GetReinforced(int reinforcedId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _reinforced.ReadElement(new ReinforcedSearchModel { Id = reinforcedId });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", reinforcedId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<OrderViewModel>? GetOrders(int clientId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _order.ReadList(new OrderSearchModel { ClientId = clientId });
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения списка заказов клиента id={Id}", clientId);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void CreateOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_order.CreateOrder(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания заказа");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PrecastConcretePlantBusinessLogic\PrecastConcretePlantBusinessLogic.csproj" />
|
||||||
|
<ProjectReference Include="..\PrecastConcretePlantDatabaseImplement\PrecastConcretePlantDatabaseImplement.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
41
PrecastConcretePlant/PrecastConcretePlantRestApi/Program.cs
Normal file
41
PrecastConcretePlant/PrecastConcretePlantRestApi/Program.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using PrecastConcretePlantBusinessLogic.BusinessLogics;
|
||||||
|
using PrecastConcretePlantContracts.BusinessLogicsContracts;
|
||||||
|
using PrecastConcretePlantContracts.StoragesContracts;
|
||||||
|
using PrecastConcretePlantDatabaseImplement.Implements;
|
||||||
|
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||||
|
builder.Logging.AddLog4Net("log4net.config");
|
||||||
|
// Add services to the container.
|
||||||
|
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||||
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
|
builder.Services.AddTransient<IReinforcedStorage, ReinforcedStorage>();
|
||||||
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
|
builder.Services.AddTransient<IReinforcedLogic, ReinforcedLogic>();
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at
|
||||||
|
https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerDoc("v1", new OpenApiInfo
|
||||||
|
{
|
||||||
|
Title = "PrecastConcretePlantRestApi",
|
||||||
|
Version
|
||||||
|
= "v1"
|
||||||
|
});
|
||||||
|
});
|
||||||
|
var app = builder.Build();
|
||||||
|
// Configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json",
|
||||||
|
"PrecastConcretePlantRestApi v1"));
|
||||||
|
}
|
||||||
|
app.UseHttpsRedirection();
|
||||||
|
app.UseAuthorization();
|
||||||
|
app.MapControllers();
|
||||||
|
app.Run();
|
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:58033",
|
||||||
|
"sslPort": 44376
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"PrecastConcretePlantRestApi": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"applicationUrl": "https://localhost:7010;http://localhost:5199",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "swagger",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<log4net>
|
||||||
|
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||||
|
<file value="c:/temp/PrecastConcretePlantRestApi.log" />
|
||||||
|
<appendToFile value="true" />
|
||||||
|
<maximumFileSize value="100KB" />
|
||||||
|
<maxSizeRollBackups value="2" />
|
||||||
|
<layout type="log4net.Layout.PatternLayout">
|
||||||
|
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
|
||||||
|
</layout>
|
||||||
|
</appender>
|
||||||
|
<root>
|
||||||
|
<level value="TRACE" />
|
||||||
|
<appender-ref ref="RollingFile" />
|
||||||
|
</root>
|
||||||
|
</log4net>
|
Loading…
Reference in New Issue
Block a user