сделал отображение сборок на стрнаице и их создание, нужно реализовать выделение строк таблицы и их последующее удаление и изменение

This commit is contained in:
Николай 2023-05-15 22:33:12 +04:00 committed by dasha
parent 70e9005df6
commit 190968e7b5
13 changed files with 209 additions and 205 deletions

View File

@ -1,5 +1,5 @@
using HardwareShopContracts.BindingModels; using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BuisnessLogicsContracts; using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.StoragesContracts; using HardwareShopContracts.StoragesContracts;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;

View File

@ -96,10 +96,6 @@ namespace HardwareShopContracts.BusinessLogicsContracts
{ {
throw new ArgumentNullException("Нет названия сборки", nameof(model.BuildName)); throw new ArgumentNullException("Нет названия сборки", nameof(model.BuildName));
} }
if (model.Price <= 0)
{
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Price));
}
if (model.UserId < 0) if (model.UserId < 0)
{ {
throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.UserId)); throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.UserId));

View File

@ -2,7 +2,7 @@
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
namespace HardwareShopContracts.BuisnessLogicsContracts namespace HardwareShopContracts.BusinessLogicsContracts
{ {
public interface IComponentLogic public interface IComponentLogic
{ {

View File

@ -10,7 +10,7 @@ namespace HardwareShopContracts.ViewModels
public string ComponentName { get; set; } = string.Empty; public string ComponentName { get; set; } = string.Empty;
[DisplayName("Стоимость")] [DisplayName("Стоимость")]
public double Cost { get; set; } public double Cost { get; set; }
[DisplayName("Дата приобретения")] [DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
public int UserId { get; set; } public int UserId { get; set; }
public Dictionary<int, (IBuildModel, int)> ComponentBuilds public Dictionary<int, (IBuildModel, int)> ComponentBuilds

View File

@ -5,6 +5,7 @@
string ComponentName { get; } string ComponentName { get; }
double Cost { get; } double Cost { get; }
int UserId { get; } int UserId { get; }
DateTime DateCreate { get; }
Dictionary<int, (IBuildModel, int)> ComponentBuilds { get; } Dictionary<int, (IBuildModel, int)> ComponentBuilds { get; }
} }
} }

View File

@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement
{ {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 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); AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
} }

View File

@ -32,7 +32,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds return context.Builds
.Include(x => x.Purchases) .Include(x => x.Purchases)
.ThenInclude(x => x.Purchase) .ThenInclude(x => x.Purchase)
.Include(x => x.BuildName.Contains(model.BuildName)) .Where(x => x.BuildName.Contains(model.BuildName))
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
@ -40,7 +40,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
return context.Builds return context.Builds
.Include(x => x.Purchases) .Include(x => x.Purchases)
.ThenInclude(x => x.Purchase) .ThenInclude(x => x.Purchase)
.Include(x => x.UserId == model.UserId) .Where(x => x.UserId == model.UserId)
.ToList() .ToList()
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();

View File

@ -1,63 +1,81 @@
using HardwareShopContracts.BindingModels; using HardwareShopBusinessLogic.BusinessLogics.Storekeeper;
using HardwareShopContracts.BindingModels;
using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.Worker;
using HardwareShopDataModels.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
namespace HardwareShopRestApi.Controllers namespace HardwareShopRestApi.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public class UserController : Controller public class BuildController : Controller
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IBuildLogic _buildLogic;
private readonly IComponentLogic _componentLogic;
private readonly IUserLogic _logic; public BuildController(IBuildLogic buildLogic, IComponentLogic componentLogic, ILogger<UserController> logger)
public UserController(IUserLogic logic, ILogger<UserController> logger)
{ {
_logger = logger; _logger = logger;
_logic = logic; _buildLogic = buildLogic;
_componentLogic = componentLogic;
} }
[HttpGet] [HttpGet]
public UserViewModel? Login(string email, string password) public List<BuildViewModel>? GetBuilds(int userId)
{ {
try try
{ {
return _logic.ReadElement(new UserSearchModel return _buildLogic.ReadList(new BuildSearchModel
{ {
Email = email, UserId = userId
Password = password
}); });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка входа в систему"); _logger.LogError(ex, "Ошибка получения списка сборок");
throw; throw;
} }
} }
[HttpPost] [HttpGet]
public void Register(UserBindingModel model) public BuildViewModel? GetBuild(int id)
{ {
try try
{ {
_logic.Create(model); return _buildLogic.ReadElement(new() { Id = id });
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка регистрации"); _logger.LogError(ex, "Ошибка сборки");
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void UpdateData(UserBindingModel model) public void Create(BuildBindingModel model)
{ {
try 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) catch (Exception ex)
{ {
@ -65,5 +83,33 @@ namespace HardwareShopRestApi.Controllers
throw; 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;
}
}
} }
} }

View File

@ -8,62 +8,16 @@ namespace HardwareShopRestApi.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public class UserController : Controller public class CommentController : Controller
{ {
private readonly ILogger _logger; 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; _logger = logger;
_logic = logic; _commentLogic = commentLogic;
}
[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;
}
} }
} }
} }

View File

@ -2,68 +2,26 @@
using HardwareShopContracts.BusinessLogicsContracts; using HardwareShopContracts.BusinessLogicsContracts;
using HardwareShopContracts.SearchModels; using HardwareShopContracts.SearchModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopRestApi.Controllers;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
namespace HardwareShopRestApi.Controllers namespace HardwareShopRestApi.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public class UserController : Controller public class PurchaseController : Controller
{ {
private readonly ILogger _logger; 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; _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;
}
} }
} }
} }

View File

@ -8,62 +8,16 @@ namespace HardwareShopRestApi.Controllers
{ {
[Route("api/[controller]/[action]")] [Route("api/[controller]/[action]")]
[ApiController] [ApiController]
public class UserController : Controller public class WorkerReport : Controller
{ {
private readonly ILogger _logger; 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; _logger = logger;
_logic = logic; _workerReportLogic = workerReportLogic;
}
[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;
}
} }
} }
} }

View File

@ -1,5 +1,6 @@
using HardwareShopContracts.BindingModels; using HardwareShopContracts.BindingModels;
using HardwareShopContracts.ViewModels; using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models;
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Enums;
using HardwareShopWorkerApp.Models; using HardwareShopWorkerApp.Models;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -41,6 +42,10 @@ namespace HardwareShopWorkerApp.Controllers
public IActionResult Index() public IActionResult Index()
{ {
if (APIClient.User == null)
{
return Redirect("~/Home/Enter");
}
return View(); return View();
} }
@ -75,6 +80,44 @@ namespace HardwareShopWorkerApp.Controllers
Response.Redirect("MainWorker"); 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() public IActionResult MainWorker()
{ {
return View(); return View();
@ -117,7 +160,11 @@ namespace HardwareShopWorkerApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Builds() 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] [HttpPost]

View File

@ -1,9 +1,17 @@
@{ @using HardwareShopContracts.ViewModels
@model List<BuildViewModel>
@{
ViewData["Title"] = "Builds"; ViewData["Title"] = "Builds";
Layout = "~/Views/Shared/_LayoutWorker.cshtml"; 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=" col-sm-8">
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Сборки</h2> <h2 class="display-4">Сборки</h2>
@ -24,35 +32,75 @@
</tr> </tr>
</thead> </thead>
<tbody> <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> </tbody>
</table> </table>
</div> </div>
</div> </div>
<div class="text-center d-flex flex-column mt-5"> <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" 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="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> <button type="submit" class="btn btn-primary btn-lg mb-5">Привязать сборку</button>
</div> </div>
<div class="modal fade" id="createModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
<form method="post" asp-controller="home" asp-action="CreateBuild">
<div class="modal-header"> <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> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<label class="form-label">Название</label> <div class="form-group">
<input type="text" class="form-control"> <label>Name</label>
<input type="text" class="form-control" required="required" name="name" />
</div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
<button type="button" class="btn btn-primary">Добавить</button> <input type="submit" class="btn btn-primary" value="Сохранить">
</div>
</form>
</div> </div>
</div> </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>
</form> <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>