aaaaaaaaaaaaaaaaaaa

This commit is contained in:
bekodeg 2024-05-29 12:38:52 +04:00
parent 46f93270fe
commit 7d945a26bc
17 changed files with 338 additions and 149 deletions

View File

@ -14,9 +14,6 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreREST", "ComputerHardwareStoreREST\ComputerHardwareStoreREST.csproj", "{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}"
ProjectSection(ProjectDependencies) = postProject
{D32DEB60-AF40-46AF-8914-DC6A19BD66CD} = {D32DEB60-AF40-46AF-8914-DC6A19BD66CD}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VendorClient", "VendorClient\VendorClient.csproj", "{BD0D9FB9-7F73-4011-AAC8-D5508EC5EB53}"
EndProject

View File

@ -76,7 +76,7 @@ namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
throw new ArgumentNullException(nameof(element));
}
model.OrderProduct = element.OrderProduct;
model.OrderProducts = element.OrderProducts;
model.DateCreate = element.DateCreate;
model.Status = element.Status;

View File

@ -7,7 +7,7 @@ namespace ComputerHardwareStoreContracts.BindingModels
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public double Price { get; set; }
public IVendorModel Vendor { get; set; }
public int VendorId { get; set; }
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
public List<ICommentModel> Comments { get; set; } = new();
}

View File

@ -10,8 +10,9 @@ namespace ComputerHardwareStoreContracts.ViewModels
public string Name { get; set; } = string.Empty;
[DisplayName("Стоимость")]
public double Price { get; set; }
public IVendorModel Vendor { get; set; }
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
public List<ICommentModel> Comments { get; set; } = new();
public int VendorId { get; set; }
}
}

View File

@ -4,7 +4,7 @@
{
string Name { get; }
double Price { get; }
IVendorModel Vendor { get; }
public int VendorId { get; }
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
public List<ICommentModel> Comments { get; }
}

View File

@ -93,7 +93,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.Where(b => b.Vendor.Id == model.VendorId)
.FirstOrDefault(p => p.Id == model.Id);
if (build == null)
{
@ -111,7 +111,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.Where(b => b.Vendor.Id == model.VendorId)
.FirstOrDefault(p => p.Id == model.Id);
if (build == null)
{

View File

@ -14,6 +14,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
public string Name { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
public int VendorId { get; set; }
[NotMapped]
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
[NotMapped]
@ -39,7 +41,6 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
List<ICommentModel> IBuildModel.Comments => Comments.Select(c => c as ICommentModel).ToList();
public virtual Vendor Vendor { get; private set; } = new();
IVendorModel IBuildModel.Vendor => Vendor as IVendorModel;
public static Build? Create(ComputerHardwareStoreDBContext context, BuildBindingModel model)
{
@ -52,7 +53,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Id = model.Id,
Name = model.Name,
Price = model.Price,
Vendor = context.Vendors.First(v => v.Id == model.Vendor.Id),
VendorId = model.VendorId,
Components = context.Components
.Where(c => model.BuildComponents.ContainsKey(c.Id))
.Select(c => new BuildComponent()
@ -80,7 +81,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Id = Id,
Name = Name,
Price = Price,
Vendor = Vendor,
VendorId = VendorId,
Comments = Comments.Select(c => c as ICommentModel).ToList(),
BuildComponents = BuildComponents
};

View File

@ -21,6 +21,7 @@
<ItemGroup>
<ProjectReference Include="..\ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj" />
<ProjectReference Include="..\ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj" />
<ProjectReference Include="..\ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj" />
</ItemGroup>

View File

@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using System.Globalization;
namespace ComputerHardwareStoreREST.Controllers
{
public class ReportsController : Controller
{
public IActionResult Index()
{
return View();
}
}
}

View File

@ -136,7 +136,7 @@ namespace StoreKeeperClient.Controllers
public IActionResult Mails()
{
if (APIClient.Client == null)
if (APIClient.StoreKeeper == null)
{
return Redirect("~/Home/Enter");
}

View File

@ -1,57 +0,0 @@
@using ComputerHardwareStoreContracts.ViewModels
@model List<OrderForProductsViewModel>
@{
ViewData["Title"] = "Orders";
}
<div class="text-center">
<h1 class="display-4">Заказы на товары</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Надо войти!</h3>
return;
}
<p>
<a class="text-decoration-none me-3 text-black h5" asp-action="CreateOrder">Создать заказ</a>
<a class="text-decoration-none me-3 text-black h5" asp-action="UpdateOrder">Изменить заказ</a>
<a class="text-decoration-none text-black h5" asp-action="DeleteOrder">Удалить заказе</a>
</p>
<table class="OrderTable">
<thead>
<tr>
<th>
Номер
</th>
<th>
Дата создания
</th>
<th>
Дата выполнения
</th>
</tr>
</thead>
<tbody>
<tbody>
@foreach (var order in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => order.Id)
</td>
<td>
@Html.DisplayFor(modelItem => order.DateCreate)
</td>
<td>
@Html.DisplayFor(modelItem => order.DateImplemet)
</td>
</tr>
}
</tbody>
</tbody>
</table>
}
</div>

View File

@ -1,3 +1,3 @@
@using FishFactoryClientApp
@using FishFactoryClientApp.Models
@using StoreKeeperClient
@using StoreKeeperClient.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@ -0,0 +1,96 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
namespace VendorClient.Controllers
{
[Route("[action]")]
public class BuildController : Controller
{
private readonly ILogger _logger;
private const string API_ROUTE = "api/builds";
public BuildController(ILogger<BuildController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult AddBuildToPurchase()
{
return View();
}
[HttpGet]
public IActionResult Builds()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Enter");
}
return View(APIClient.GetRequest<List<BuildViewModel>>($"{API_ROUTE}/getbuilds?userId={APIClient.Vendor.Id}"));
}
[HttpGet]
public void BuildCreate(string buildName)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(buildName))
{
throw new Exception($"Имя сборки не должно быть пустым");
}
APIClient.PostRequest($"{API_ROUTE}/create", new BuildBindingModel
{
Name = buildName,
VendorId = APIClient.Vendor.Id
});
Response.Redirect("Builds");
}
[HttpGet]
public void BuildDelete(int id)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (id <= 0)
{
throw new Exception($"Идентификатор сборки не может быть ниже или равен 0");
}
APIClient.PostRequest("api/build/DeleteBuild", new BuildBindingModel
{
Id = id
});
Response.Redirect("Builds");
}
[HttpGet]
public void BuildUpdate(string buildName, int buildId)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(buildName))
{
throw new Exception($"Имя сборки не должно быть пустым");
}
if (buildId <= 0)
{
throw new Exception($"Идентификатор сборки не может быть ниже или равен 0");
}
APIClient.PostRequest($"{API_ROUTE}/update", new BuildBindingModel
{
Id = buildId,
Name = buildName
});
Response.Redirect("Builds");
}
}
}

View File

@ -1,10 +1,12 @@
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using VendorClient.Models;
namespace VendorClient.Controllers
{
[Route("[action]")]
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
@ -17,56 +19,56 @@ namespace VendorClient.Controllers
[HttpGet]
public IActionResult Index()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpGet]
public IActionResult Privacy()
{
return View();
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.Vendor);
}
[HttpGet]
public IActionResult Enter()
public void Enter(string email, string password)
{
return View();
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите почту и пароль");
}
APIClient.Vendor = APIClient.GetRequest<VendorViewModel>($"api/vendor/login?email={email}&password={password}");
if (APIClient.Vendor == null)
{
throw new Exception("Неверные почта и/или пароль");
}
Response.Redirect("MainWorker");
}
[HttpGet]
public IActionResult Register()
public void Register(string email, string password, string fio)
{
return View();
}
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/pharmacist/register", new VendorBindingModel
{
Name = fio,
Login = email,
Password = password
});
Response.Redirect("Enter");
return;
}
[HttpGet]
public IActionResult AddBuildToPurchase()
{
return View();
}
[HttpGet]
public IActionResult Builds()
{
return View(new List<BuildViewModel>());
}
[HttpGet]
public IActionResult BuildCreate()
{
return View();
}
[HttpGet]
public IActionResult BuildDelete()
{
return View();
}
[HttpGet]
public IActionResult BuildUpdate()
{
return View();
}
[HttpGet]
public IActionResult CommentCreate()
@ -92,47 +94,6 @@ namespace VendorClient.Controllers
return View(new List<CommentViewModel>());
}
[HttpGet]
public IActionResult ProductsList()
{
return View(new List<BuildViewModel>());
}
[HttpGet]
public IActionResult PurchaseCreate()
{
return View();
}
[HttpGet]
public IActionResult PurchaseDelete()
{
return View();
}
[HttpGet]
public IActionResult Purchases()
{
return View(new List<PurchaseViewModel>());
}
[HttpGet]
public IActionResult PurchaseUpdate()
{
return View();
}
[HttpGet]
public IActionResult Report()
{
return View(new List<PurchaseViewModel>());
}
[HttpPost]
public void Report(string password)
{
Response.Redirect("ReportOnly");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()

View File

@ -0,0 +1,99 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDataModels.Models;
using Microsoft.AspNetCore.Mvc;
namespace VendorClient.Controllers
{
[Route("[action]")]
public class PurchaseController : Controller
{
private readonly ILogger<PurchaseController> _logger;
private const string API_ROUTE = "api/purchases";
public PurchaseController(ILogger<PurchaseController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult Products()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Enter");
}
ViewBag.Goods = APIClient.GetRequest<List<ProductViewModel>>($"api/products/GetAllProducts");
return View();
}
[HttpPost]
public void PurchaseCreate([FromBody] PurchaseBindingModel purchaseModel)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (purchaseModel.Cost <= 0)
{
throw new Exception("Цена должна быть больше 0");
}
purchaseModel.VendorId = APIClient.Vendor.Id;
APIClient.PostRequest($"{API_ROUTE}/createpurchase", purchaseModel);
}
[HttpGet]
public void PurchaseDelete(int id)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (id <= 0)
{
throw new Exception("Некорректный идентификатор");
}
var purchase = APIClient.GetRequest<PurchaseViewModel>($"api/purchase/getpurchase?purchaseId={id}");
APIClient.PostRequest($"{API_ROUTE}/DeletePurchase", new PurchaseBindingModel
{
Id = id,
});
}
[HttpGet]
public IActionResult Purchases()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Enter");
}
ViewBag.Purchases = APIClient.PostRequestWithResult<PurchaseSearchModel, List<PurchaseViewModel>>(
$"{API_ROUTE}/getpurchases", new() { VendorId = APIClient.Vendor.Id });
return View();
}
[HttpGet]
public void PurchaseUpdate([FromBody] PurchaseBindingModel purchaseModel)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
purchaseModel.VendorId = APIClient.Vendor.Id;
APIClient.PostRequest("api/purchase/update", purchaseModel);
}
[HttpGet]
public string Report(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
return "NotImplement";
}
}
}

View File

@ -0,0 +1,65 @@
@{
ViewData["Title"] = "Report";
}
<div class="container">
<div class="text-center mb-4">
<h2 class="text-custom-color-1">отчёт по покупкам за период</h2>
</div>
<form method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="dateFrom" class="form-label text-custom-color-1">Начало периода:</label>
<input type="datetime-local" id="dateFrom" name="dateFrom" class="form-control" placeholder="Выберите дату начала периода">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="dateTo" class="form-label text-custom-color-1">Окончание периода:</label>
<input type="datetime-local" id="dateTo" name="dateTo" class="form-control" placeholder="Выберите дату окончания периода">
</div>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Отправить на почту</button>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="button" id="demonstrate" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Продемонстрировать</button>
</div>
</div>
<div id="report"></div>
</form>
</div>
@section Scripts {
<script>
function check() {
var dateFrom = $('#dateFrom').val();
var dateTo = $('#dateTo').val();
if (dateFrom && dateTo) {
$.ajax({
method: "GET",
url: "/GetPurchaseReport",
data: { dateFrom: dateFrom, dateTo: dateTo },
success: function (result) {
if (result != null) {
$('#report').html(result);
}
}
});
};
}
check();
$('#demonstrate').on('click', (e) => check());
</script>
}

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace VendorClient.Views.Home
{
public class ReportModel : PageModel
{
public void OnGet()
{
}
}
}