сделал отображение сборок на стрнаице и их создание, нужно реализовать выделение строк таблицы и их последующее удаление и изменение
This commit is contained in:
parent
70e9005df6
commit
190968e7b5
@ -1,5 +1,5 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BuisnessLogicsContracts;
|
||||
using HardwareShopContracts.BusinessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.StoragesContracts;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
|
@ -96,10 +96,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия сборки", nameof(model.BuildName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
if (model.UserId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.UserId));
|
||||
|
@ -2,7 +2,7 @@
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
|
||||
namespace HardwareShopContracts.BuisnessLogicsContracts
|
||||
namespace HardwareShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
|
@ -10,7 +10,7 @@ namespace HardwareShopContracts.ViewModels
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
[DisplayName("Стоимость")]
|
||||
public double Cost { get; set; }
|
||||
[DisplayName("Дата приобретения")]
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public int UserId { get; set; }
|
||||
public Dictionary<int, (IBuildModel, int)> ComponentBuilds
|
||||
|
@ -5,6 +5,7 @@
|
||||
string ComponentName { get; }
|
||||
double Cost { get; }
|
||||
int UserId { get; }
|
||||
DateTime DateCreate { get; }
|
||||
Dictionary<int, (IBuildModel, int)> ComponentBuilds { get; }
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store;Username=postgres;Password=1234");
|
||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store4;Username=postgres;Password=1234");
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
return context.Builds
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.BuildName.Contains(model.BuildName))
|
||||
.Where(x => x.BuildName.Contains(model.BuildName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -40,7 +40,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
|
||||
return context.Builds
|
||||
.Include(x => x.Purchases)
|
||||
.ThenInclude(x => x.Purchase)
|
||||
.Include(x => x.UserId == model.UserId)
|
||||
.Where(x => x.UserId == model.UserId)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
|
@ -1,63 +1,81 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.BusinessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models.Worker;
|
||||
using HardwareShopDataModels.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class UserController : Controller
|
||||
public class BuildController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IBuildLogic _buildLogic;
|
||||
private readonly IComponentLogic _componentLogic;
|
||||
|
||||
private readonly IUserLogic _logic;
|
||||
|
||||
public UserController(IUserLogic logic, ILogger<UserController> logger)
|
||||
public BuildController(IBuildLogic buildLogic, IComponentLogic componentLogic, ILogger<UserController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_buildLogic = buildLogic;
|
||||
_componentLogic = componentLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public UserViewModel? Login(string email, string password)
|
||||
public List<BuildViewModel>? GetBuilds(int userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new UserSearchModel
|
||||
return _buildLogic.ReadList(new BuildSearchModel
|
||||
{
|
||||
Email = email,
|
||||
Password = password
|
||||
UserId = userId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
_logger.LogError(ex, "Ошибка получения списка сборок");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(UserBindingModel model)
|
||||
[HttpGet]
|
||||
public BuildViewModel? GetBuild(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
return _buildLogic.ReadElement(new() { Id = id });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
_logger.LogError(ex, "Ошибка сборки");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateData(UserBindingModel model)
|
||||
public void Create(BuildBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
_buildLogic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сборки");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Update(BuildBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_buildLogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -65,5 +83,33 @@ namespace HardwareShopRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void DeleteShop(BuildBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_buildLogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления сборки");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void AddDishInShop(ComponentBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_componentLogic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка компонента в сборку");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,62 +8,16 @@ namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class UserController : Controller
|
||||
public class CommentController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IUserLogic _logic;
|
||||
private readonly ICommentLogic _commentLogic;
|
||||
|
||||
public UserController(IUserLogic logic, ILogger<UserController> logger)
|
||||
public CommentController(ICommentLogic commentLogic, ILogger<UserController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public UserViewModel? Login(string email, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new UserSearchModel
|
||||
{
|
||||
Email = email,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateData(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
_commentLogic = commentLogic;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,68 +2,26 @@
|
||||
using HardwareShopContracts.BusinessLogicsContracts;
|
||||
using HardwareShopContracts.SearchModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopRestApi.Controllers;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class UserController : Controller
|
||||
public class PurchaseController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IUserLogic _logic;
|
||||
private readonly IPurchaseLogic _purchaseLogic;
|
||||
|
||||
public UserController(IUserLogic logic, ILogger<UserController> logger)
|
||||
public PurchaseController(IPurchaseLogic purchaseLogic, ILogger<UserController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_purchaseLogic = purchaseLogic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public UserViewModel? Login(string email, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new UserSearchModel
|
||||
{
|
||||
Email = email,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateData(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,62 +8,16 @@ namespace HardwareShopRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class UserController : Controller
|
||||
public class WorkerReport : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IUserLogic _logic;
|
||||
private readonly IWorkerReportLogic _workerReportLogic;
|
||||
|
||||
public UserController(IUserLogic logic, ILogger<UserController> logger)
|
||||
public WorkerReport(IWorkerReportLogic workerReportLogic, ILogger<UserController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public UserViewModel? Login(string email, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new UserSearchModel
|
||||
{
|
||||
Email = email,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void Register(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateData(UserBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
_workerReportLogic = workerReportLogic;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDatabaseImplement.Models;
|
||||
using HardwareShopDataModels.Enums;
|
||||
using HardwareShopWorkerApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -41,6 +42,10 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
@ -75,6 +80,44 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
Response.Redirect("MainWorker");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateBuild(string name)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception($"Имя магазина не должно быть пустым");
|
||||
}
|
||||
APIClient.PostRequest("api/build/create", new BuildBindingModel
|
||||
{
|
||||
BuildName = name,
|
||||
UserId = APIClient.User.Id
|
||||
});
|
||||
Response.Redirect("Builds");
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void UpdateBuild(string name)
|
||||
{
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
throw new Exception($"Имя магазина не должно быть пустым");
|
||||
}
|
||||
APIClient.PostRequest("api/build/update", new BuildBindingModel
|
||||
{
|
||||
BuildName = name,
|
||||
UserId = APIClient.User.Id
|
||||
});
|
||||
Response.Redirect("Builds");
|
||||
}
|
||||
|
||||
public IActionResult MainWorker()
|
||||
{
|
||||
return View();
|
||||
@ -117,7 +160,11 @@ namespace HardwareShopWorkerApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Builds()
|
||||
{
|
||||
return View();
|
||||
if (APIClient.User == null)
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIClient.GetRequest<List<BuildViewModel>>($"api/build/getbuilds?userId={APIClient.User.Id}"));
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
|
@ -1,9 +1,17 @@
|
||||
@{
|
||||
@using HardwareShopContracts.ViewModels
|
||||
@model List<BuildViewModel>
|
||||
@{
|
||||
ViewData["Title"] = "Builds";
|
||||
Layout = "~/Views/Shared/_LayoutWorker.cshtml";
|
||||
}
|
||||
|
||||
<form method="post" class="d-flex justify-content-evenly">
|
||||
<div class="d-flex justify-content-evenly">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Введите пароль</h3>
|
||||
return;
|
||||
}
|
||||
<div class=" col-sm-8">
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Сборки</h2>
|
||||
@ -24,35 +32,75 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Price)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.BuildName)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center d-flex flex-column mt-5">
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Добавить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#createModal">Добавить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Удалить</button>
|
||||
<button type="button" class="btn btn-primary btn-lg mb-5">Обновить</button>
|
||||
<button type="submit" class="btn btn-primary btn-lg mb-5">Привязать сборку</button>
|
||||
</div>
|
||||
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="post" asp-controller="home" asp-action="CreateBuild">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Сборка</h5>
|
||||
<h5 class="modal-title" id="exampleModalLabel">Создание сборку</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<label class="form-label">Название</label>
|
||||
<input type="text" class="form-control">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" required="required" name="name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<button type="button" class="btn btn-primary">Добавить</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input type="submit" class="btn btn-primary" value="Сохранить">
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<form method="post" asp-controller="home" asp-action="update">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="exampleModalLabel">Обновление сборки</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<label>Name</label>
|
||||
<input type="text" class="form-control" required="required" name="name" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
|
||||
<input type="submit" class="btn btn-primary" value="Сохранить">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user