This commit is contained in:
Данила Селяев 2023-11-19 20:57:55 +04:00
parent d0ac7218a4
commit 67d4a78a39
19 changed files with 192 additions and 57 deletions

View File

@ -10,7 +10,7 @@ namespace FoodOrdersDatabaseImplement
{ {
if (optionsBuilder.IsConfigured == false) if (optionsBuilder.IsConfigured == false)
{ {
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=FoodOrdersDatabaseFull_2;Username=postgres;Password=12345"); optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=FoodOrdersDatabaseFull_2;Username=postgres;Password=user");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -34,7 +34,7 @@ namespace FoodOrderDatabaseImplement.Implements
using var context = new FoodOrdersDataBase(); using var context = new FoodOrdersDataBase();
return context.Clients return context.Clients
.Include(x => x.Orders) .Include(x => x.Orders)
.Where(x => x.Email.Contains(model.Email)) .Where(x => x.Login.Contains(model.Email))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -51,7 +51,7 @@ namespace FoodOrderDatabaseImplement.Implements
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{ {
return context.Clients return context.Clients
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))?.GetViewModel; .FirstOrDefault(x => (x.Login == model.Email && x.Password == model.Password))?.GetViewModel;
} }
return new(); return new();
} }

View File

@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FoodOrderDatabaseImplement.Migrations namespace FoodOrderDatabaseImplement.Migrations
{ {
[DbContext(typeof(FoodOrdersDataBase))] [DbContext(typeof(FoodOrdersDataBase))]
[Migration("20230416163421_InitMigration")] [Migration("20231119073616_InitialCreature")]
partial class InitMigration partial class InitialCreature
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -25,6 +25,31 @@ namespace FoodOrderDatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FoodOrderDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -99,6 +124,9 @@ namespace FoodOrderDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("integer"); .HasColumnType("integer");
@ -123,6 +151,8 @@ namespace FoodOrderDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("FoodId"); b.HasIndex("FoodId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -149,15 +179,28 @@ namespace FoodOrderDatabaseImplement.Migrations
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("FoodOrderDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FoodOrdersDatabaseImplement.Models.Food", "Food") b.HasOne("FoodOrdersDatabaseImplement.Models.Food", "Food")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("FoodId") .HasForeignKey("FoodId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client");
b.Navigation("Food"); b.Navigation("Food");
}); });
modelBuilder.Entity("FoodOrderDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
{ {
b.Navigation("FoodComponents"); b.Navigation("FoodComponents");

View File

@ -7,12 +7,26 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FoodOrderDatabaseImplement.Migrations namespace FoodOrderDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class InitMigration : Migration public partial class InitialCreature : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
{ {
migrationBuilder.Sql("DELETE FROM [dbo].[Orders]"); migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false),
Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable( migrationBuilder.CreateTable(
name: "Components", name: "Components",
columns: table => new columns: table => new
@ -76,6 +90,7 @@ namespace FoodOrderDatabaseImplement.Migrations
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
FoodId = table.Column<int>(type: "integer", nullable: false), FoodId = table.Column<int>(type: "integer", nullable: false),
FoodName = table.Column<string>(type: "text", nullable: false), FoodName = table.Column<string>(type: "text", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false),
Count = table.Column<int>(type: "integer", nullable: false), Count = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false), Sum = table.Column<double>(type: "double precision", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false), Status = table.Column<int>(type: "integer", nullable: false),
@ -85,6 +100,12 @@ namespace FoodOrderDatabaseImplement.Migrations
constraints: table => constraints: table =>
{ {
table.PrimaryKey("PK_Orders", x => x.Id); table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey( table.ForeignKey(
name: "FK_Orders_Foods_FoodId", name: "FK_Orders_Foods_FoodId",
column: x => x.FoodId, column: x => x.FoodId,
@ -103,6 +124,11 @@ namespace FoodOrderDatabaseImplement.Migrations
table: "FoodComponents", table: "FoodComponents",
column: "FoodId"); column: "FoodId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex( migrationBuilder.CreateIndex(
name: "IX_Orders_FoodId", name: "IX_Orders_FoodId",
table: "Orders", table: "Orders",
@ -121,6 +147,9 @@ namespace FoodOrderDatabaseImplement.Migrations
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Components"); name: "Components");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable( migrationBuilder.DropTable(
name: "Foods"); name: "Foods");
} }

View File

@ -22,6 +22,31 @@ namespace FoodOrderDatabaseImplement.Migrations
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("FoodOrderDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
{ {
b.Property<int>("Id") b.Property<int>("Id")
@ -96,6 +121,9 @@ namespace FoodOrderDatabaseImplement.Migrations
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id")); NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<int>("Count") b.Property<int>("Count")
.HasColumnType("integer"); .HasColumnType("integer");
@ -120,6 +148,8 @@ namespace FoodOrderDatabaseImplement.Migrations
b.HasKey("Id"); b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("FoodId"); b.HasIndex("FoodId");
b.ToTable("Orders"); b.ToTable("Orders");
@ -146,15 +176,28 @@ namespace FoodOrderDatabaseImplement.Migrations
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b => modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Order", b =>
{ {
b.HasOne("FoodOrderDatabaseImplement.Models.Client", "Client")
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("FoodOrdersDatabaseImplement.Models.Food", "Food") b.HasOne("FoodOrdersDatabaseImplement.Models.Food", "Food")
.WithMany("Orders") .WithMany("Orders")
.HasForeignKey("FoodId") .HasForeignKey("FoodId")
.OnDelete(DeleteBehavior.Cascade) .OnDelete(DeleteBehavior.Cascade)
.IsRequired(); .IsRequired();
b.Navigation("Client");
b.Navigation("Food"); b.Navigation("Food");
}); });
modelBuilder.Entity("FoodOrderDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b => modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
{ {
b.Navigation("FoodComponents"); b.Navigation("FoodComponents");

View File

@ -13,7 +13,7 @@ namespace FoodOrderDatabaseImplement.Models
[Required] [Required]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[Required] [Required]
public string Email { get; set; } = string.Empty; public string Login { get; set; } = string.Empty;
[Required] [Required]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")] [ForeignKey("ClientId")]
@ -28,7 +28,7 @@ namespace FoodOrderDatabaseImplement.Models
{ {
Id = model.Id, Id = model.Id,
ClientFIO = model.ClientFIO, ClientFIO = model.ClientFIO,
Email = model.Email, Login = model.Login,
Password = model.Password Password = model.Password
}; };
} }
@ -39,14 +39,14 @@ namespace FoodOrderDatabaseImplement.Models
return; return;
} }
ClientFIO = model.ClientFIO; ClientFIO = model.ClientFIO;
Email = model.Email; Login = model.Login;
Password = model.Password; Password = model.Password;
} }
public ClientViewModel GetViewModel => new() public ClientViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
ClientFIO = ClientFIO, ClientFIO = ClientFIO,
Email = Email, Login = Login,
Password = Password Password = Password
}; };
} }

View File

@ -10,12 +10,13 @@ namespace FoodOrdersDatabaseImplement.Models
public class Order : IOrderModel public class Order : IOrderModel
{ {
public int Id { get; private set; } public int Id { get; private set; }
[Required]
public int FoodId { get; private set; } public int FoodId { get; private set; }
public string FoodName { get; private set; } = string.Empty; public string FoodName { get; private set; } = string.Empty;
[Required] [Required]
public int ClientId { get; private set; } public int ClientId { get; private set; }
[Required] [Required]
public int Count { get; private set; } public int Count { get; private set; }
@ -30,8 +31,8 @@ namespace FoodOrdersDatabaseImplement.Models
public DateTime? DateImplement { get; private set; } public DateTime? DateImplement { get; private set; }
public virtual Food Food { get; set; } public virtual Food Food { get; private set; }
public virtual Client Client { get; set; } public virtual Client Client { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {

View File

@ -29,7 +29,7 @@ namespace FoodOrderFileImplement.Implements
if (!string.IsNullOrEmpty(model.Email)) if (!string.IsNullOrEmpty(model.Email))
{ {
return source.Clients return source.Clients
.Where(x => x.Email.Contains(model.Email)) .Where(x => x.Login.Contains(model.Email))
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -45,7 +45,7 @@ namespace FoodOrderFileImplement.Implements
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
{ {
return source.Clients return source.Clients
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))?.GetViewModel; .FirstOrDefault(x => (x.Login == model.Email && x.Password == model.Password))?.GetViewModel;
} }
return new(); return new();
} }

View File

@ -14,7 +14,7 @@ namespace FoodOrderFileImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty; public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty; public string Login { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel? model) public static Client? Create(ClientBindingModel? model)
{ {
@ -26,7 +26,7 @@ namespace FoodOrderFileImplement.Models
{ {
Id = model.Id, Id = model.Id,
ClientFIO = model.ClientFIO, ClientFIO = model.ClientFIO,
Email = model.Email, Login = model.Login,
Password = model.Password, Password = model.Password,
}; };
} }
@ -40,7 +40,7 @@ namespace FoodOrderFileImplement.Models
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ClientFIO = element.Element("ClientFIO")!.Value, ClientFIO = element.Element("ClientFIO")!.Value,
Email = element.Element("Email")!.Value, Login = element.Element("Email")!.Value,
Password = element.Element("Password")!.Value Password = element.Element("Password")!.Value
}; };
} }
@ -51,20 +51,20 @@ namespace FoodOrderFileImplement.Models
return; return;
} }
ClientFIO = model.ClientFIO; ClientFIO = model.ClientFIO;
Email = model.Email; Login = model.Login;
Password = model.Password; Password = model.Password;
} }
public ClientViewModel GetViewModel => new() public ClientViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
ClientFIO = ClientFIO, ClientFIO = ClientFIO,
Email = Email, Login = Login,
Password = Password Password = Password
}; };
public XElement GetXElement => new("Client", public XElement GetXElement => new("Client",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("ClientFIO", ClientFIO), new XElement("ClientFIO", ClientFIO),
new XElement("Email", Email), new XElement("Email", Login),
new XElement("Password", Password)); new XElement("Password", Password));
} }
} }

View File

@ -89,7 +89,7 @@ namespace FoodOrderBusinessLogic.BusinessLogic
{ {
throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientFIO)); throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientFIO));
} }
if (string.IsNullOrEmpty(model.Email)) if (string.IsNullOrEmpty(model.Login))
{ {
throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientFIO)); throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientFIO));
} }
@ -97,10 +97,10 @@ namespace FoodOrderBusinessLogic.BusinessLogic
{ {
throw new ArgumentNullException("Нет пароля учетной записи клиента", nameof(model.ClientFIO)); throw new ArgumentNullException("Нет пароля учетной записи клиента", nameof(model.ClientFIO));
} }
_logger.LogInformation("Client. ClientFIO:{ClientFIO}. Email:{Email}. Password:{Password}. Id:{Id}", model.ClientFIO, model.Email, model.Password, model.Id); _logger.LogInformation("Client. ClientFIO:{ClientFIO}. Email:{Email}. Password:{Password}. Id:{Id}", model.ClientFIO, model.Login, model.Password, model.Id);
var element = _clientStorage.GetElement(new ClientSearchModel var element = _clientStorage.GetElement(new ClientSearchModel
{ {
Email = model.Email Email = model.Login
}); });
if (element != null && element.Id != model.Id) if (element != null && element.Id != model.Id)
{ {

View File

@ -1,18 +1,22 @@
using FoodOrdersClientApp.Models; 
using FoodOrdersClientApp.Models;
using FoodOrdersClientApp;
using FoodOrdersContracts.BindingModels; using FoodOrdersContracts.BindingModels;
using FoodOrdersContracts.ViewModels; using FoodOrdersContracts.ViewModels;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Diagnostics; using System.Diagnostics;
namespace FoodOrdersClientApp.Controllers namespace AutoPlantClientApp.Controllers
{ {
public class HomeController : Controller public class HomeController : Controller
{ {
private readonly ILogger<HomeController> _logger; private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger) public HomeController(ILogger<HomeController> logger)
{ {
_logger = logger; _logger = logger;
} }
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
@ -21,6 +25,7 @@ namespace FoodOrdersClientApp.Controllers
} }
return View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}")); return View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
} }
[HttpGet] [HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
@ -30,12 +35,13 @@ namespace FoodOrdersClientApp.Controllers
} }
return View(APIClient.Client); return View(APIClient.Client);
} }
[HttpPost] [HttpPost]
public void Privacy(string login, string password, string fio) public void Privacy(string login, string password, string fio)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
throw new Exception("Вход только авторизованным. Пожалуйста, пройдите авторизацию."); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio)) if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{ {
@ -45,25 +51,28 @@ namespace FoodOrdersClientApp.Controllers
{ {
Id = APIClient.Client.Id, Id = APIClient.Client.Id,
ClientFIO = fio, ClientFIO = fio,
Email = login, Login = login,
Password = password Password = password
}); });
APIClient.Client.ClientFIO = fio; APIClient.Client.ClientFIO = fio;
APIClient.Client.Email = login; APIClient.Client.Login = login;
APIClient.Client.Password = password; APIClient.Client.Password = password;
Response.Redirect("Index"); Response.Redirect("Index");
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
} }
[HttpGet] [HttpGet]
public IActionResult Enter() public IActionResult Enter()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Enter(string login, string password) public void Enter(string login, string password)
{ {
@ -78,11 +87,13 @@ namespace FoodOrdersClientApp.Controllers
} }
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpGet] [HttpGet]
public IActionResult Register() public IActionResult Register()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Register(string login, string password, string fio) public void Register(string login, string password, string fio)
{ {
@ -93,43 +104,48 @@ namespace FoodOrdersClientApp.Controllers
APIClient.PostRequest("api/client/register", new ClientBindingModel APIClient.PostRequest("api/client/register", new ClientBindingModel
{ {
ClientFIO = fio, ClientFIO = fio,
Email = login, Login = login,
Password = password Password = password
}); });
Response.Redirect("Enter"); Response.Redirect("Enter");
return; return;
} }
[HttpGet] [HttpGet]
public IActionResult Create() public IActionResult Create()
{ {
ViewBag.Foods = APIClient.GetRequest<List<FoodViewModel>>("api/main/getworklist"); ViewBag.Food = APIClient.GetRequest<List<FoodViewModel>>("api/main/get\r\n\t\t\t\tFoodId = food,list");
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Create(int food, int count) public void Create(int food, int count)
{ {
if (APIClient.Client == null) if (APIClient.Client == null)
{ {
throw new Exception("Вход только авторизованным. Пожалуйста, пройдите авторизацию."); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (count <= 0) if (count <= 0)
{ {
throw new Exception("Количество и сумма должны быть больше 0"); throw new Exception("Количество и сумма должны быть больше 0");
} }
var foods = APIClient.GetRequest<List<FoodViewModel>>("api/main/getfoodlist");
APIClient.PostRequest("api/main/createorder", new OrderBindingModel APIClient.PostRequest("api/main/createorder", new OrderBindingModel
{ {
ClientId = APIClient.Client.Id, ClientId = APIClient.Client.Id,
FoodId = food, FoodId = food,
FoodName = (foods.FirstOrDefault(x => x.Id == food)).FoodName,
Count = count, Count = count,
Sum = Calc(count, food) Sum = Calc(count, food)
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public double Calc(int count, int work) public double Calc(int count, int food)
{ {
var wor = APIClient.GetRequest<FoodViewModel>($"api/main/getwork?workId={work}"); var prod = APIClient.GetRequest<FoodViewModel>($"api/main/getfood?foodId={food}");
return count * (wor?.Price ?? 1); return count * (prod?.Price ?? 1);
} }
} }
} }

View File

@ -1,9 +1,12 @@
using FoodOrdersClientApp;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
// Add services to the container. // Add services to the container.
builder.Services.AddControllersWithViews(); builder.Services.AddControllersWithViews();
var app = builder.Build(); var app = builder.Build();
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment()) if (!app.Environment.IsDevelopment())

View File

@ -9,7 +9,7 @@
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Логин:</div> <div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="login" value="@Model.Email" /></div> <div class="col-8"><input type="text" name="login" value="@Model.Login" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Пароль:</div> <div class="col-4">Пароль:</div>

View File

@ -12,7 +12,7 @@ namespace FoodOrdersContracts.BindingModels
public int Id { get; set; } public int Id { get; set; }
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty; public string Login { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
} }

View File

@ -9,7 +9,7 @@ namespace FoodOrdersContracts.ViewModels
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
[DisplayName("логин (эл.почта)")] [DisplayName("логин (эл.почта)")]
public string Email { get; set; } = string.Empty; public string Login { get; set; } = string.Empty;
[DisplayName("Пароль")] [DisplayName("Пароль")]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;

View File

@ -9,7 +9,7 @@ namespace FoodOrdersDataModel.Models
public interface IClientModel public interface IClientModel
{ {
string ClientFIO { get; } string ClientFIO { get; }
string Email { get; } string Login { get; }
string Password { get; } string Password { get; }
} }
} }

View File

@ -31,7 +31,7 @@ namespace FoodOrdersListImplement.Implements
} }
foreach (var client in _source.Clients) foreach (var client in _source.Clients)
{ {
if (client.Email.Contains(model.Email)) if (client.Login.Contains(model.Email))
{ {
result.Add(client.GetViewModel); result.Add(client.GetViewModel);
} }
@ -54,7 +54,7 @@ namespace FoodOrdersListImplement.Implements
{ {
foreach (var client in _source.Clients) foreach (var client in _source.Clients)
{ {
if (client.Email == model.Email && client.Password == model.Password) if (client.Login == model.Email && client.Password == model.Password)
{ {
return client.GetViewModel; return client.GetViewModel;
} }

View File

@ -8,7 +8,7 @@ namespace FoodOrdersListImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
public string ClientFIO { get; private set; } = string.Empty; public string ClientFIO { get; private set; } = string.Empty;
public string Email { get; private set; } = string.Empty; public string Login { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty; public string Password { get; private set; } = string.Empty;
public static Client? Create(ClientBindingModel? model) public static Client? Create(ClientBindingModel? model)
{ {
@ -20,7 +20,7 @@ namespace FoodOrdersListImplement.Models
{ {
Id = model.Id, Id = model.Id,
ClientFIO = model.ClientFIO, ClientFIO = model.ClientFIO,
Email = model.Email, Login = model.Login,
Password = model.Password, Password = model.Password,
}; };
} }
@ -31,14 +31,14 @@ namespace FoodOrdersListImplement.Models
return; return;
} }
ClientFIO = model.ClientFIO; ClientFIO = model.ClientFIO;
Email = model.Email; Login = model.Login;
Password = model.Password; Password = model.Password;
} }
public ClientViewModel GetViewModel => new() public ClientViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
ClientFIO = ClientFIO, ClientFIO = ClientFIO,
Email = Email, Login = Login,
Password = Password Password = Password
}; };
} }

View File

@ -12,36 +12,36 @@ namespace FoodOrdersRestApi.Controllers
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderLogic _order; private readonly IOrderLogic _order;
private readonly IFoodLogic _work; private readonly IFoodLogic _food;
public MainController(ILogger<MainController> logger, IOrderLogic order, IFoodLogic work) public MainController(ILogger<MainController> logger, IOrderLogic order, IFoodLogic food)
{ {
_logger = logger; _logger = logger;
_order = order; _order = order;
_work = work; _food = food;
} }
[HttpGet] [HttpGet]
public List<FoodViewModel>? GetWorkList() public List<FoodViewModel>? GetFoodList()
{ {
try try
{ {
return _work.ReadList(null); return _food.ReadList(null);
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка получения списка работ"); _logger.LogError(ex, "Ошибка получения списка продуктов");
throw; throw;
} }
} }
[HttpGet] [HttpGet]
public FoodViewModel? GetWork(int workId) public FoodViewModel? GetFood(int foodId)
{ {
try try
{ {
return _work.ReadElement(new FoodSearchModel { Id = workId }); return _food.ReadElement(new FoodSearchModel { Id = foodId });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка получения работы по id={Id}", workId); _logger.LogError(ex, "Ошибка получения работы по id={Id}", foodId);
throw; throw;
} }
} }