мучения

This commit is contained in:
Inohara 2023-03-27 22:06:24 +04:00
parent 2767e576c9
commit e33998f1f0
12 changed files with 476 additions and 149 deletions

View File

@ -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);

View File

@ -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<T>(result);
}

View File

@ -8,140 +8,140 @@ namespace IceCreamShopClientApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
}
public IActionResult Index()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<OrderViewModel>>($"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<ClientViewModel>($"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<ClientViewModel>($"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<List<IceCreamViewModel>>("api/main/geticecreamlist");
return View();
}
[HttpGet]
public IActionResult Create()
{
ViewBag.IceCreams = APIClient.GetRequest<List<IceCreamViewModel>>("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<IceCreamViewModel>($"api/main/getproduct?productId={icecream}");
return count * (prod?.Price ?? 1);
}
}
[HttpPost]
public double Calc(int count, int icecream)
{
var prod = APIClient.GetRequest<IceCreamViewModel>($"api/main/geticecream?icecreamId={icecream}");
return count * (prod?.Price ?? 1);
}
}
}

View File

@ -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())
{

View File

@ -8,7 +8,7 @@
<div class="row">
<div class="col-4">Мороженое:</div>
<div class="col-8">
<select id="icecream" name="icecream" class="form-control" asp-items="@(new SelectList(@ViewBag.Products,"Id", "IceCreamName"))"></select>
<select id="icecream" name="icecream" class="form-control" asp-items="@(new SelectList(@ViewBag.IceCreams,"Id", "IceCreamName"))"></select>
</div>
</div>
<div class="row">

View File

@ -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();
}

View File

@ -0,0 +1,214 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<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("IceCreamShopDatabaseImplement.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("IceCreamShopDatabaseImplement.Models.IceCream", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("IceCreamName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("IceCreams");
});
modelBuilder.Entity("IceCreamShopDatabaseImplement.Models.IceCreamComponent", 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>("IceCreamId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ComponentId");
b.HasIndex("IceCreamId");
b.ToTable("IceCreamComponents");
});
modelBuilder.Entity("IceCreamShopDatabaseImplement.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>("IceCreamId")
.HasColumnType("int");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<double>("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
}
}
}

View File

@ -0,0 +1,69 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace IceCreamShopDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class LabWork05Migr : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql("TRUNCATE TABLE Orders");
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");
}
}
}

View File

@ -22,6 +22,31 @@ namespace IceCreamShopDatabaseImplement.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("IceCreamShopDatabaseImplement.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("IceCreamShopDatabaseImplement.Models.Component", b =>
{
b.Property<int>("Id")
@ -96,6 +121,9 @@ namespace IceCreamShopDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("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");

View File

@ -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)
{

View File

@ -24,7 +24,7 @@ namespace IceCreamShopRestApi.Controllers
}
[HttpGet]
public List<IceCreamViewModel>? GetIceCreamtList()
public List<IceCreamViewModel>? GetIceCreamList()
{
try
{

View File

@ -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();