diff --git a/IceCreamShop/IceCreamShop/FormIceCreams.Designer.cs b/IceCreamShop/IceCreamShop/FormIceCreams.Designer.cs index 152124e..8a8a108 100644 --- a/IceCreamShop/IceCreamShop/FormIceCreams.Designer.cs +++ b/IceCreamShop/IceCreamShop/FormIceCreams.Designer.cs @@ -38,10 +38,9 @@ // // buttonUpdate // - this.buttonUpdate.Location = new System.Drawing.Point(468, 309); - this.buttonUpdate.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUpdate.Location = new System.Drawing.Point(535, 412); this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(133, 22); + this.buttonUpdate.Size = new System.Drawing.Size(152, 29); this.buttonUpdate.TabIndex = 10; this.buttonUpdate.Text = "Обновить"; this.buttonUpdate.UseVisualStyleBackColor = true; @@ -49,10 +48,9 @@ // // buttonDelete // - this.buttonDelete.Location = new System.Drawing.Point(468, 64); - this.buttonDelete.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDelete.Location = new System.Drawing.Point(535, 85); this.buttonDelete.Name = "buttonDelete"; - this.buttonDelete.Size = new System.Drawing.Size(133, 22); + this.buttonDelete.Size = new System.Drawing.Size(152, 29); this.buttonDelete.TabIndex = 9; this.buttonDelete.Text = "Удалить"; this.buttonDelete.UseVisualStyleBackColor = true; @@ -60,20 +58,19 @@ // // buttonEdit // - this.buttonEdit.Location = new System.Drawing.Point(468, 37); - this.buttonEdit.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonEdit.Location = new System.Drawing.Point(535, 49); this.buttonEdit.Name = "buttonEdit"; - this.buttonEdit.Size = new System.Drawing.Size(133, 22); + this.buttonEdit.Size = new System.Drawing.Size(152, 29); this.buttonEdit.TabIndex = 8; this.buttonEdit.Text = "Изменить"; this.buttonEdit.UseVisualStyleBackColor = true; + this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click); // // buttonAdd // - this.buttonAdd.Location = new System.Drawing.Point(468, 11); - this.buttonAdd.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonAdd.Location = new System.Drawing.Point(535, 15); this.buttonAdd.Name = "buttonAdd"; - this.buttonAdd.Size = new System.Drawing.Size(133, 22); + this.buttonAdd.Size = new System.Drawing.Size(152, 29); this.buttonAdd.TabIndex = 7; this.buttonAdd.Text = "Добавить"; this.buttonAdd.UseVisualStyleBackColor = true; @@ -82,24 +79,24 @@ // dataGridView // this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; - this.dataGridView.Location = new System.Drawing.Point(12, 11); - this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.dataGridView.Location = new System.Drawing.Point(14, 15); this.dataGridView.Name = "dataGridView"; this.dataGridView.RowHeadersWidth = 51; this.dataGridView.RowTemplate.Height = 29; - this.dataGridView.Size = new System.Drawing.Size(444, 320); + this.dataGridView.Size = new System.Drawing.Size(507, 427); this.dataGridView.TabIndex = 6; // // FormIceCreams // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(615, 343); + this.ClientSize = new System.Drawing.Size(703, 457); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonDelete); this.Controls.Add(this.buttonEdit); this.Controls.Add(this.buttonAdd); this.Controls.Add(this.dataGridView); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormIceCreams"; this.Text = "Мороженое "; this.Load += new System.EventHandler(this.FormIceCreams_Load); diff --git a/IceCreamShop/IceCreamShopClientApp/APIClient.cs b/IceCreamShop/IceCreamShopClientApp/APIClient.cs index bfed639..11828b7 100644 --- a/IceCreamShop/IceCreamShopClientApp/APIClient.cs +++ b/IceCreamShop/IceCreamShopClientApp/APIClient.cs @@ -22,7 +22,7 @@ namespace IceCreamShopClientApp { var response = _client.GetAsync(requestUrl); var result = response.Result.Content.ReadAsStringAsync().Result; - if (response.Result.IsSuccessStatusCode) + if (response.Result.IsSuccessStatusCode) { return JsonConvert.DeserializeObject(result); } diff --git a/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs b/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs index a3f4da4..be2cb9b 100644 --- a/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs +++ b/IceCreamShop/IceCreamShopClientApp/Controllers/HomeController.cs @@ -8,140 +8,140 @@ namespace IceCreamShopClientApp.Controllers { public class HomeController : Controller { - private readonly ILogger _logger; + private readonly ILogger _logger; - public HomeController(ILogger logger) - { - _logger = logger; - } + public HomeController(ILogger logger) + { + _logger = logger; + } - public IActionResult Index() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); - } + public IActionResult Index() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.GetRequest>($"api/main/getorders?clientId={APIClient.Client.Id}")); + } - [HttpGet] - public IActionResult Privacy() - { - if (APIClient.Client == null) - { - return Redirect("~/Home/Enter"); - } - return View(APIClient.Client); - } + [HttpGet] + public IActionResult Privacy() + { + if (APIClient.Client == null) + { + return Redirect("~/Home/Enter"); + } + return View(APIClient.Client); + } - [HttpPost] - public void Privacy(string login, string password, string fio) - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception("Введите логин, пароль и ФИО"); - } - APIClient.PostRequest("api/client/updatedata", new ClientBindingModel - { - Id = APIClient.Client.Id, - ClientFIO = fio, - Email = login, - Password = password - }); + [HttpPost] + public void Privacy(string login, string password, string fio) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/updatedata", new ClientBindingModel + { + Id = APIClient.Client.Id, + ClientFIO = fio, + Email = login, + Password = password + }); - APIClient.Client.ClientFIO = fio; - APIClient.Client.Email = login; - APIClient.Client.Password = password; - Response.Redirect("Index"); - } + APIClient.Client.ClientFIO = fio; + APIClient.Client.Email = login; + APIClient.Client.Password = password; + Response.Redirect("Index"); + } - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public IActionResult Error() + { + return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); + } - [HttpGet] - public IActionResult Enter() - { - return View(); - } + [HttpGet] + public IActionResult Enter() + { + return View(); + } - [HttpPost] - public void Enter(string login, string password) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) - { - throw new Exception("Введите логин и пароль"); - } - APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); - if (APIClient.Client == null) - { - throw new Exception("Неверный логин/пароль"); - } - Response.Redirect("Index"); - } + [HttpPost] + public void Enter(string login, string password) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) + { + throw new Exception("Введите логин и пароль"); + } + APIClient.Client = APIClient.GetRequest($"api/client/login?login={login}&password={password}"); + if (APIClient.Client == null) + { + throw new Exception("Неверный логин/пароль"); + } + Response.Redirect("Index"); + } - [HttpGet] - public IActionResult Register() - { - return View(); - } + [HttpGet] + public IActionResult Register() + { + return View(); + } - [HttpPost] - public void Register(string login, string password, string fio) - { - if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) - { - throw new Exception("Введите логин, пароль и ФИО"); - } - APIClient.PostRequest("api/client/register", new ClientBindingModel - { - ClientFIO = fio, - Email = login, - Password = password - }); - Response.Redirect("Enter"); - return; - } + [HttpPost] + public void Register(string login, string password, string fio) + { + if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) + { + throw new Exception("Введите логин, пароль и ФИО"); + } + APIClient.PostRequest("api/client/register", new ClientBindingModel + { + ClientFIO = fio, + Email = login, + Password = password + }); + Response.Redirect("Enter"); + return; + } - [HttpGet] - public IActionResult Create() - { - ViewBag.IceCreams = APIClient.GetRequest>("api/main/geticecreamlist"); - return View(); - } + [HttpGet] + public IActionResult Create() + { + ViewBag.IceCreams = APIClient.GetRequest>("api/main/geticecreamlist"); + return View(); + } - [HttpPost] - public void Create(int icecream, int count) - { - if (APIClient.Client == null) - { - throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - } - if (count <= 0) - { - throw new Exception("Количество и сумма должны быть больше 0"); - } - APIClient.PostRequest("api/main/createorder", new OrderBindingModel - { - //ClientId = APIClient.Client.Id, - IceCreamId = icecream, - Count = count, - Sum = Calc(count, icecream) - }); - Response.Redirect("Index"); - } + [HttpPost] + public void Create(int icecream, int count) + { + if (APIClient.Client == null) + { + throw new Exception("Вы как суда попали? Суда вход только авторизованным"); + } + if (count <= 0) + { + throw new Exception("Количество и сумма должны быть больше 0"); + } + APIClient.PostRequest("api/main/createorder", new OrderBindingModel + { + ClientId = APIClient.Client.Id, + IceCreamId = icecream, + Count = count, + Sum = Calc(count, icecream) + }); + Response.Redirect("Index"); + } - [HttpPost] - public double Calc(int count, int icecream) - { - var prod = APIClient.GetRequest($"api/main/getproduct?productId={icecream}"); - return count * (prod?.Price ?? 1); - } - } + [HttpPost] + public double Calc(int count, int icecream) + { + var prod = APIClient.GetRequest($"api/main/geticecream?icecreamId={icecream}"); + return count * (prod?.Price ?? 1); + } + } } \ No newline at end of file diff --git a/IceCreamShop/IceCreamShopClientApp/Program.cs b/IceCreamShop/IceCreamShopClientApp/Program.cs index 0727468..8641101 100644 --- a/IceCreamShop/IceCreamShopClientApp/Program.cs +++ b/IceCreamShop/IceCreamShopClientApp/Program.cs @@ -1,3 +1,5 @@ +using IceCreamShopClientApp; + var builder = WebApplication.CreateBuilder(args); // Add services to the container. @@ -5,6 +7,9 @@ builder.Services.AddControllersWithViews(); var app = builder.Build(); +APIClient.Connect(builder.Configuration); + + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { diff --git a/IceCreamShop/IceCreamShopClientApp/Views/Home/Create.cshtml b/IceCreamShop/IceCreamShopClientApp/Views/Home/Create.cshtml index c30e374..8b3f4cd 100644 --- a/IceCreamShop/IceCreamShopClientApp/Views/Home/Create.cshtml +++ b/IceCreamShop/IceCreamShopClientApp/Views/Home/Create.cshtml @@ -8,7 +8,7 @@
Мороженое:
- +
diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Implements/IceCreamStorage.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Implements/IceCreamStorage.cs index 2782f13..5f6c310 100644 --- a/IceCreamShop/IceCreamShopDatabaseImplement/Implements/IceCreamStorage.cs +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Implements/IceCreamStorage.cs @@ -16,7 +16,6 @@ namespace IceCreamShopDatabaseImplement.Implements return context.IceCreams .Include(x => x.Components) .ThenInclude(x => x.Component) - .ToList() .Select(x => x.GetViewModel) .ToList(); } @@ -31,9 +30,8 @@ namespace IceCreamShopDatabaseImplement.Implements return context.IceCreams .Include(x => x.Components) .ThenInclude(x => x.Component) - .Where(x => x.IceCreamName.Contains(model.IceCreamName)) - .ToList() .Select(x => x.GetViewModel) + .Where(x => x.IceCreamName.Contains(model.IceCreamName)) .ToList(); } diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/20230327111426_LabWork05Migr.Designer.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/20230327111426_LabWork05Migr.Designer.cs new file mode 100644 index 0000000..5d663f3 --- /dev/null +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/20230327111426_LabWork05Migr.Designer.cs @@ -0,0 +1,214 @@ +// +using System; +using IceCreamShopDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +#nullable disable + +namespace IceCreamShopDatabaseImplement.Migrations +{ + [DbContext(typeof(IceCreamShopDatabase))] + [Migration("20230327111426_LabWork05Migr")] + partial class LabWork05Migr + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Cost") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.IceCream", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("IceCreamName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.ToTable("IceCreams"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.IceCreamComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("IceCreamId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("IceCreamId"); + + b.ToTable("IceCreamComponents"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientId") + .HasColumnType("int"); + + b.Property("Count") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateImplement") + .HasColumnType("datetime2"); + + b.Property("IceCreamId") + .HasColumnType("int"); + + b.Property("Status") + .HasColumnType("int"); + + b.Property("Sum") + .HasColumnType("float"); + + b.HasKey("Id"); + + b.HasIndex("ClientId"); + + b.HasIndex("IceCreamId"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.IceCreamComponent", b => + { + b.HasOne("IceCreamShopDatabaseImplement.Models.Component", "Component") + .WithMany("IceCreamComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IceCreamShopDatabaseImplement.Models.IceCream", "IceCream") + .WithMany("Components") + .HasForeignKey("IceCreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("IceCream"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Order", b => + { + b.HasOne("IceCreamShopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("IceCreamShopDatabaseImplement.Models.IceCream", "IceCream") + .WithMany("Orders") + .HasForeignKey("IceCreamId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Client"); + + b.Navigation("IceCream"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Component", b => + { + b.Navigation("IceCreamComponents"); + }); + + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.IceCream", b => + { + b.Navigation("Components"); + + b.Navigation("Orders"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/20230327111426_LabWork05Migr.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/20230327111426_LabWork05Migr.cs new file mode 100644 index 0000000..9be063b --- /dev/null +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/20230327111426_LabWork05Migr.cs @@ -0,0 +1,69 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace IceCreamShopDatabaseImplement.Migrations +{ + /// + public partial class LabWork05Migr : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.Sql("TRUNCATE TABLE Orders"); + migrationBuilder.AddColumn( + name: "ClientId", + table: "Orders", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Clients", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ClientFIO = table.Column(type: "nvarchar(max)", nullable: false), + Email = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(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); + } + + /// + 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"); + } + } +} diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/IceCreamShopDatabaseModelSnapshot.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/IceCreamShopDatabaseModelSnapshot.cs index f1d25eb..5535d99 100644 --- a/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/IceCreamShopDatabaseModelSnapshot.cs +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Migrations/IceCreamShopDatabaseModelSnapshot.cs @@ -22,6 +22,31 @@ namespace IceCreamShopDatabaseImplement.Migrations SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Client", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ClientFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Clients"); + }); + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Component", b => { b.Property("Id") @@ -96,6 +121,9 @@ namespace IceCreamShopDatabaseImplement.Migrations SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + b.Property("ClientId") + .HasColumnType("int"); + b.Property("Count") .HasColumnType("int"); @@ -116,6 +144,8 @@ namespace IceCreamShopDatabaseImplement.Migrations b.HasKey("Id"); + b.HasIndex("ClientId"); + b.HasIndex("IceCreamId"); b.ToTable("Orders"); @@ -142,15 +172,28 @@ namespace IceCreamShopDatabaseImplement.Migrations modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Order", b => { + b.HasOne("IceCreamShopDatabaseImplement.Models.Client", "Client") + .WithMany("Orders") + .HasForeignKey("ClientId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + b.HasOne("IceCreamShopDatabaseImplement.Models.IceCream", "IceCream") .WithMany("Orders") .HasForeignKey("IceCreamId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.Navigation("Client"); + b.Navigation("IceCream"); }); + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Client", b => + { + b.Navigation("Orders"); + }); + modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.Component", b => { b.Navigation("IceCreamComponents"); diff --git a/IceCreamShop/IceCreamShopDatabaseImplement/Models/Order.cs b/IceCreamShop/IceCreamShopDatabaseImplement/Models/Order.cs index 8c30339..763453e 100644 --- a/IceCreamShop/IceCreamShopDatabaseImplement/Models/Order.cs +++ b/IceCreamShop/IceCreamShopDatabaseImplement/Models/Order.cs @@ -25,7 +25,7 @@ namespace IceCreamShopDatabaseImplement.Models public DateTime? DateImplement { get; set; } public int Id { get; set; } - public virtual Document Document { get; set; } + public virtual IceCream IceCream{ get; set; } public virtual Client Client { get; set; } public static Order? Create(OrderBindingModel? model) { diff --git a/IceCreamShop/IceCreamShopRestApi/Controllers/MainController.cs b/IceCreamShop/IceCreamShopRestApi/Controllers/MainController.cs index ded9725..73c17fa 100644 --- a/IceCreamShop/IceCreamShopRestApi/Controllers/MainController.cs +++ b/IceCreamShop/IceCreamShopRestApi/Controllers/MainController.cs @@ -24,7 +24,7 @@ namespace IceCreamShopRestApi.Controllers } [HttpGet] - public List? GetIceCreamtList() + public List? GetIceCreamList() { try { diff --git a/IceCreamShop/IceCreamShopRestApi/Program.cs b/IceCreamShop/IceCreamShopRestApi/Program.cs index 5b77dfa..f83f377 100644 --- a/IceCreamShop/IceCreamShopRestApi/Program.cs +++ b/IceCreamShop/IceCreamShopRestApi/Program.cs @@ -23,7 +23,7 @@ builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "AbstractShopRestApi", Version = "v1" }); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "IceScreamRestApi", Version = "v1" }); }); var app = builder.Build(); @@ -32,7 +32,8 @@ var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); - app.UseSwaggerUI(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", + "IceScreamRestApi v1")); } app.UseHttpsRedirection();