фикс
This commit is contained in:
parent
d0ac7218a4
commit
67d4a78a39
@ -10,7 +10,7 @@ namespace FoodOrdersDatabaseImplement
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ namespace FoodOrderDatabaseImplement.Implements
|
||||
using var context = new FoodOrdersDataBase();
|
||||
return context.Clients
|
||||
.Include(x => x.Orders)
|
||||
.Where(x => x.Email.Contains(model.Email))
|
||||
.Where(x => x.Login.Contains(model.Email))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -51,7 +51,7 @@ namespace FoodOrderDatabaseImplement.Implements
|
||||
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace FoodOrderDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FoodOrdersDataBase))]
|
||||
[Migration("20230416163421_InitMigration")]
|
||||
partial class InitMigration
|
||||
[Migration("20231119073616_InitialCreature")]
|
||||
partial class InitialCreature
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -25,6 +25,31 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
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 =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -99,6 +124,9 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@ -123,6 +151,8 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("FoodId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
@ -149,15 +179,28 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
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")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("FoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Food");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodOrderDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("FoodComponents");
|
@ -7,12 +7,26 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
namespace FoodOrderDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitMigration : Migration
|
||||
public partial class InitialCreature : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
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(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
@ -76,6 +90,7 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
FoodId = table.Column<int>(type: "integer", 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),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
@ -85,6 +100,12 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
constraints: table =>
|
||||
{
|
||||
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(
|
||||
name: "FK_Orders_Foods_FoodId",
|
||||
column: x => x.FoodId,
|
||||
@ -103,6 +124,11 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
table: "FoodComponents",
|
||||
column: "FoodId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_FoodId",
|
||||
table: "Orders",
|
||||
@ -121,6 +147,9 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Foods");
|
||||
}
|
@ -22,6 +22,31 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
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 =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -96,6 +121,9 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
@ -120,6 +148,8 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("FoodId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
@ -146,15 +176,28 @@ namespace FoodOrderDatabaseImplement.Migrations
|
||||
|
||||
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")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("FoodId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Food");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodOrderDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FoodOrdersDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("FoodComponents");
|
||||
|
@ -13,7 +13,7 @@ namespace FoodOrderDatabaseImplement.Models
|
||||
[Required]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty;
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[ForeignKey("ClientId")]
|
||||
@ -28,7 +28,7 @@ namespace FoodOrderDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Login = model.Login,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
@ -39,14 +39,14 @@ namespace FoodOrderDatabaseImplement.Models
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
}
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
|
@ -10,12 +10,13 @@ namespace FoodOrdersDatabaseImplement.Models
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int FoodId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int FoodId { get; private set; }
|
||||
public string FoodName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -30,8 +31,8 @@ namespace FoodOrdersDatabaseImplement.Models
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public virtual Food Food { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
public virtual Food Food { get; private set; }
|
||||
public virtual Client Client { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
|
@ -29,7 +29,7 @@ namespace FoodOrderFileImplement.Implements
|
||||
if (!string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return source.Clients
|
||||
.Where(x => x.Email.Contains(model.Email))
|
||||
.Where(x => x.Login.Contains(model.Email))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -45,7 +45,7 @@ namespace FoodOrderFileImplement.Implements
|
||||
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace FoodOrderFileImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
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 static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
@ -26,7 +26,7 @@ namespace FoodOrderFileImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
@ -40,7 +40,7 @@ namespace FoodOrderFileImplement.Models
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ClientFIO = element.Element("ClientFIO")!.Value,
|
||||
Email = element.Element("Email")!.Value,
|
||||
Login = element.Element("Email")!.Value,
|
||||
Password = element.Element("Password")!.Value
|
||||
};
|
||||
}
|
||||
@ -51,20 +51,20 @@ namespace FoodOrderFileImplement.Models
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
}
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
public XElement GetXElement => new("Client",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ClientFIO", ClientFIO),
|
||||
new XElement("Email", Email),
|
||||
new XElement("Email", Login),
|
||||
new XElement("Password", Password));
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ namespace FoodOrderBusinessLogic.BusinessLogic
|
||||
{
|
||||
throw new ArgumentNullException("Нет имени клиента", nameof(model.ClientFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
if (string.IsNullOrEmpty(model.Login))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина клиента", nameof(model.ClientFIO));
|
||||
}
|
||||
@ -97,10 +97,10 @@ namespace FoodOrderBusinessLogic.BusinessLogic
|
||||
{
|
||||
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
|
||||
{
|
||||
Email = model.Email
|
||||
Email = model.Login
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
|
@ -1,18 +1,22 @@
|
||||
using FoodOrdersClientApp.Models;
|
||||
|
||||
using FoodOrdersClientApp.Models;
|
||||
using FoodOrdersClientApp;
|
||||
using FoodOrdersContracts.BindingModels;
|
||||
using FoodOrdersContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace FoodOrdersClientApp.Controllers
|
||||
namespace AutoPlantClientApp.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
private readonly ILogger<HomeController> _logger;
|
||||
|
||||
public HomeController(ILogger<HomeController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
@ -21,6 +25,7 @@ namespace FoodOrdersClientApp.Controllers
|
||||
}
|
||||
return View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
@ -30,12 +35,13 @@ namespace FoodOrdersClientApp.Controllers
|
||||
}
|
||||
return View(APIClient.Client);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Privacy(string login, string password, string fio)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вход только авторизованным. Пожалуйста, пройдите авторизацию.");
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||
{
|
||||
@ -45,25 +51,28 @@ namespace FoodOrdersClientApp.Controllers
|
||||
{
|
||||
Id = APIClient.Client.Id,
|
||||
ClientFIO = fio,
|
||||
Email = login,
|
||||
Login = login,
|
||||
Password = password
|
||||
});
|
||||
|
||||
APIClient.Client.ClientFIO = fio;
|
||||
APIClient.Client.Email = login;
|
||||
APIClient.Client.Login = 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 });
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Enter()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Enter(string login, string password)
|
||||
{
|
||||
@ -78,11 +87,13 @@ namespace FoodOrdersClientApp.Controllers
|
||||
}
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Register()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(string login, string password, string fio)
|
||||
{
|
||||
@ -93,43 +104,48 @@ namespace FoodOrdersClientApp.Controllers
|
||||
APIClient.PostRequest("api/client/register", new ClientBindingModel
|
||||
{
|
||||
ClientFIO = fio,
|
||||
Email = login,
|
||||
Login = login,
|
||||
Password = password
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
return;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
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();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Create(int food, int count)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вход только авторизованным. Пожалуйста, пройдите авторизацию.");
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
throw new Exception("Количество и сумма должны быть больше 0");
|
||||
}
|
||||
var foods = APIClient.GetRequest<List<FoodViewModel>>("api/main/getfoodlist");
|
||||
APIClient.PostRequest("api/main/createorder", new OrderBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
FoodId = food,
|
||||
FoodName = (foods.FirstOrDefault(x => x.Id == food)).FoodName,
|
||||
Count = count,
|
||||
Sum = Calc(count, food)
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
|
||||
[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}");
|
||||
return count * (wor?.Price ?? 1);
|
||||
var prod = APIClient.GetRequest<FoodViewModel>($"api/main/getfood?foodId={food}");
|
||||
return count * (prod?.Price ?? 1);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,9 +1,12 @@
|
||||
using FoodOrdersClientApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
|
@ -9,7 +9,7 @@
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<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 class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
|
@ -12,7 +12,7 @@ namespace FoodOrdersContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
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;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace FoodOrdersContracts.ViewModels
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("логин (эл.почта)")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Login { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
@ -9,7 +9,7 @@ namespace FoodOrdersDataModel.Models
|
||||
public interface IClientModel
|
||||
{
|
||||
string ClientFIO { get; }
|
||||
string Email { get; }
|
||||
string Login { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace FoodOrdersListImplement.Implements
|
||||
}
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (client.Email.Contains(model.Email))
|
||||
if (client.Login.Contains(model.Email))
|
||||
{
|
||||
result.Add(client.GetViewModel);
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace FoodOrdersListImplement.Implements
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace FoodOrdersListImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
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 static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
@ -20,7 +20,7 @@ namespace FoodOrdersListImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
@ -31,14 +31,14 @@ namespace FoodOrdersListImplement.Models
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Login = model.Login;
|
||||
Password = model.Password;
|
||||
}
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Login = Login,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
|
@ -12,36 +12,36 @@ namespace FoodOrdersRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _order;
|
||||
private readonly IFoodLogic _work;
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, IFoodLogic work)
|
||||
private readonly IFoodLogic _food;
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order, IFoodLogic food)
|
||||
{
|
||||
_logger = logger;
|
||||
_order = order;
|
||||
_work = work;
|
||||
_food = food;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<FoodViewModel>? GetWorkList()
|
||||
public List<FoodViewModel>? GetFoodList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _work.ReadList(null);
|
||||
return _food.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка работ");
|
||||
_logger.LogError(ex, "Ошибка получения списка продуктов");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public FoodViewModel? GetWork(int workId)
|
||||
public FoodViewModel? GetFood(int foodId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _work.ReadElement(new FoodSearchModel { Id = workId });
|
||||
return _food.ReadElement(new FoodSearchModel { Id = foodId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения работы по id={Id}", workId);
|
||||
_logger.LogError(ex, "Ошибка получения работы по id={Id}", foodId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user