dont work

This commit is contained in:
Илья Федотов 2024-05-27 17:35:14 +04:00
parent dab4a0980f
commit 4f4ca4e948
12 changed files with 47 additions and 26 deletions

View File

@ -39,7 +39,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic {
return true;
}
public EmployeeViewModel? ReadElemet(EmployeeSearchModel model) {
public EmployeeViewModel? ReadElement(EmployeeSearchModel model) {
if (model == null) {
throw new ArgumentNullException(nameof(model));
}

View File

@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts {
public interface IEmployeeLogic {
List<EmployeeViewModel>? ReadList(EmployeeSearchModel model);
EmployeeViewModel? ReadElemet(EmployeeSearchModel model);
EmployeeViewModel? ReadElement(EmployeeSearchModel model);
bool Create(EmployeeBindingModel model);
bool Update(EmployeeBindingModel model);

View File

@ -3,6 +3,7 @@ using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
namespace ElectronicsShopDataBaseImplement.Implements
@ -46,15 +47,17 @@ namespace ElectronicsShopDataBaseImplement.Implements
public EmployeeViewModel? GetElement(EmployeeSearchModel model)
{
if (string.IsNullOrEmpty(model.Login) && !model.ID.HasValue)
{
return null;
}
using var context = new Database();
return context.Employees
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Login) &&
x.EmployeeFIO == model.EmployeFIO ||
(model.ID.HasValue && x.ID == model.ID)))?.GetViewModel;
if (model.ID.HasValue) {
return context.Employees
.FirstOrDefault(x => model.ID.HasValue && x.ID == model.ID)?.GetViewModel;
}
else if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password)) {
return context.Employees
.FirstOrDefault(x => (x.Login == model.Login && x.Password == model.Password))
?.GetViewModel;
}
return new();
}
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)

View File

@ -16,7 +16,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
if (APIEmployee.Employee == null) {
return Redirect("~/Home/Enter");
}
return View(APIEmployee.GetRequset<List<ProductViewModel>>($"api/main/getproducts"));
return View(APIEmployee.GetRequset<List<ProductViewModel>>($"api/main/getproducts?_employeeid={APIEmployee.Employee.ID}"));
}
[HttpGet]
@ -58,11 +58,12 @@ namespace ElectronicsShopEmployeeApp.Controllers {
return View();
}
[HttpPost]
public void Enter(string login, string password) {
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) {
throw new Exception("Ââåäèòå ëîãèí è ïàðîëü");
}
APIEmployee.Employee = APIEmployee.GetRequset<EmployeeViewModel>($"api/employee/login/login={login}&password={password}");
APIEmployee.Employee = APIEmployee.GetRequset<EmployeeViewModel>($"api/employee/login?login={login}&password={password}");
if (APIEmployee.Employee == null) {
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
@ -74,6 +75,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
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("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
@ -95,7 +97,6 @@ namespace ElectronicsShopEmployeeApp.Controllers {
public void Create(OrderBindingModel order) {
throw new NotImplementedException();
}
}
}

View File

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

View File

@ -7,7 +7,7 @@
</div>
<form method="post">
<div class="row">
<div class="col-4">Почта:</div>
<div class="col-4">Логин:</div>
<div class="col-8"><input type="text" name="Login" /></div>
</div>
<div class="row">

View File

@ -22,7 +22,7 @@ namespace ElectronicsShopRestAPI.Controllers {
[HttpGet]
public EmployeeViewModel? Login(string login, string password) {
try {
return _logic.ReadElemet(new EmployeeSearchModel {
return _logic.ReadElement(new EmployeeSearchModel {
Login = login,
Password = password
});

View File

@ -1,17 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace ElectronicsShopResrAPI.Controllers {
namespace ElectronicsShopRestAPI.Controllers {
[Route("api/[controller]/[action]")]
[ApiController]
public class MainController : Controller {
private readonly ILogger _logger;
private readonly IProductLogic _product;
public MainController(ILogger<MainController> logger) {
public MainController(ILogger<MainController> logger, IProductLogic product) {
_logger = logger;
_product = product;
}
[HttpGet]
@ -29,10 +33,21 @@ namespace ElectronicsShopResrAPI.Controllers {
// клиент должен получать свои заказы
// сотрудник должен получать все заказы
[HttpGet]
public List<OrderViewModel>? GetOrders(int? userID = null) {
public List<OrderViewModel>? GetOrders(int _clientID) {
return null;
}
[HttpGet]
public List<ProductViewModel>? GetProducts() {
try {
return _product.ReadList(new ProductSearchModel {});
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения данных");
throw;
}
}
[HttpPost]
public void CreateOrder(OrderBindingModel model) {
return;

View File

@ -1,6 +0,0 @@
@ElectronicsShopResrAPI_HostAddress = http://localhost:5176
GET {{ElectronicsShopResrAPI_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -0,0 +1,6 @@
@ElectronicsShopRestAPI_HostAddress = http://localhost:5176
GET {{ElectronicsShopRestAPI_HostAddress}}/weatherforecast/
Accept: application/json
###

View File

@ -11,8 +11,10 @@ var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IEmployeeStorage, EmployeeStorage>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle

View File

@ -20,7 +20,7 @@
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Продукты</a>
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Заказы</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>