Compare commits

...

9 Commits

20 changed files with 146 additions and 117 deletions

View File

@ -129,7 +129,6 @@ namespace HardwareShopBusinessLogic.OfficePackage
}
}
rowIndex++;
}
SaveExcel(info);

View File

@ -264,7 +264,7 @@ namespace HardwareShopStorekeeperApp.Controllers
}
[HttpPost]
public void CreateComponent(string name, string cost, DateTime date)
public void CreateComponent(string name, string cost)
{
if (APIClient.User == null)
{
@ -282,8 +282,7 @@ namespace HardwareShopStorekeeperApp.Controllers
{
UserId = APIClient.User.Id,
ComponentName = name,
Cost = Convert.ToDouble(cost.Replace('.', ',')),
DateCreate = date
Cost = Convert.ToDouble(cost.Replace('.', ','))
});
Response.Redirect("Components");
}
@ -443,5 +442,15 @@ namespace HardwareShopStorekeeperApp.Controllers
reportModel.UserEmail = APIClient.User.Email;
APIClient.PostRequest("api/report/componentsreportsendonmail", reportModel);
}
[HttpGet]
public List<CommentViewModel> GetCommentsOnBuild(int buildId)
{
if (APIClient.User == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
return APIClient.GetRequest<List<CommentViewModel>>($"api/comment/GetCommentsOnBuild?buildId={buildId}")!;
}
}
}

View File

@ -16,10 +16,6 @@
<label class="form-label">Стоимость</label>
<input type="number" step="0.01" class="form-control" name="cost" min="0.01" required>
</div>
<div class="col-sm-3">
<label class="form-label">Дата приобретения</label>
<input type="datetime-local" class="form-control" name="date" required>
</div>
<div class="col-sm-2 d-flex justify-content-evenly align-items-baseline">
<button type="submit" class="btn btn-primary mt-3 px-4">Сохранить</button>
</div>

View File

@ -41,6 +41,9 @@
<div class="modal-body">
<label class="form-label">Сборка</label>
<select id="build" name="build" class="form-control" asp-items="@(new SelectList(@ViewBag.Builds, "Id", "BuildName"))" required></select>
<table class="table table-hover">
<thead><tr><th scope="col">Комментарии</th></tr></thead>
<tbody id="comments"></tbody>
<label class="form-label">Количество</label>
<input type="number" class="form-control" name="count" id="count" min="1" value="1" required>
</div>
@ -62,6 +65,21 @@
const saveBtn = document.getElementById("linkbuilds");
const countElem = document.getElementById("count");
const resultTable = document.getElementById("result");
const selectBuilds = document.getElementById("build");
const comments = document.getElementById("comments");
selectBuilds.addEventListener('change', function() { getCommentsOnBuild() });
function getCommentsOnBuild() {
$.ajax({
method: "GET",
url: `/Storekeeper/GetCommentsOnBuild`,
data: { buildId: selectBuilds.value },
success: function (result) {
reloadCommentsTable(result)
}
});
}
submitBuildBtn.addEventListener("click", () => {
console.log('try to add build')
@ -121,13 +139,19 @@
})
}
function reloadCommentsTable(result) {
comments.innerHTML = ''
result.forEach((elem) => {
comments.innerHTML += `<tr><td>${elem.text}</td></tr>`
})
}
function deleteBuild(id) {
list = list.filter(value => value.build.buildName != resultTable.rows[id].cells[0].innerText)
reloadTable()
}
function getComponentBuilds() {
console.log(componentid)
if (componentid) {
$.ajax({
method: "GET",
@ -142,7 +166,6 @@
url: "/Storekeeper/GetComponentBuilds",
data: { componentid: componentid },
success: function (result) {
console.log(result)
if (result) {
result.forEach(elem => {
list.push({ build: elem.item1, count: elem.item2 })
@ -154,6 +177,7 @@
};
}
getComponentBuilds();
getCommentsOnBuild();
</script>
}

View File

@ -1,19 +0,0 @@
using HardwareShopDataModels.Models;
namespace HardwareShopContracts.BindingModels
{
public class MessageInfoBindingModel : IMessageInfoModel
{
public string MessageId { get; set; } = string.Empty;
public int? UserId { get; set; }
public string SenderName { get; set; } = string.Empty;
public string Subject { get; set; } = string.Empty;
public string Body { get; set; } = string.Empty;
public DateTime DateDelivery { get; set; }
}
}

View File

@ -1,17 +0,0 @@
namespace HardwareShopDataModels.Models
{
public interface IMessageInfoModel
{
string MessageId { get; }
int? UserId { get; }
string SenderName { get; }
DateTime DateDelivery { get; }
string Subject { get; }
string Body { get; }
}
}

View File

@ -3,6 +3,7 @@ using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDatabaseImplement.Models.Storekeeper;
using HardwareShopDatabaseImplement.Models.Worker;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options;
namespace HardwareShopDatabaseImplement
{
@ -10,8 +11,8 @@ namespace HardwareShopDatabaseImplement
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=Computer_Hardware_Store1;Username=user;Password=12345");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store5;Username=postgres;Password=1234");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)

View File

@ -4,6 +4,7 @@ using HardwareShopContracts.StoragesContracts;
using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.Storekeeper;
using HardwareShopDatabaseImplement.Models.Worker;
using HardwareShopDataModels.Enums;
using Microsoft.EntityFrameworkCore;
namespace HardwareShopDatabaseImplement.Implements.Worker
@ -89,8 +90,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var build = context.Builds
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
.FirstOrDefault(x => x.Id == model.Id);
if (build == null || build.UserId != build.UserId)
.FirstOrDefault(x => x.Id == model.Id && x.UserId == model.UserId);
if (build == null)
{
return null;
}
@ -116,7 +117,17 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
context.Builds.Remove(element);
var buildPurchases = context.PurchasesBuilds.Where(x => x.BuildId == element.Id).ToList();
buildPurchases.ForEach(x =>
{
var purchase = context.Purchases.Include(x => x.Builds).FirstOrDefault(rec => rec.Id == x.PurchaseId && rec.PurchaseStatus != PurchaseStatus.Выдан);
if (purchase != null)
{
purchase.Sum -= element.Price * x.Count;
purchase.Sum = Math.Round(purchase.Sum, 2);
}
});
context.Builds.Remove(element);
context.SaveChanges();
return element.GetViewModel;
}

View File

@ -22,7 +22,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
public List<PurchaseViewModel> GetFilteredList(PurchaseSearchModel model)
{
using var context = new HardwareShopDatabase();
if (model.UserId.HasValue && !model.PurchaseStatus.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
if (model.UserId.HasValue && model.DateFrom.HasValue && model.DateTo.HasValue)
{
return context.Purchases
.Include(x => x.Builds)
@ -36,21 +36,28 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Select(x => x.GetViewModel)
.ToList();
}
if (model.UserId.HasValue)
if (model.UserId.HasValue && model.PurchaseStatus.HasValue)
{
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Where(x => x.PurchaseStatus == model.PurchaseStatus && x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
}
if (model.UserId.HasValue)
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Where(x => x.UserId == model.UserId)
.Select(x => x.GetViewModel)
.ToList();
}
return context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Where(x => x.PurchaseStatus == model.PurchaseStatus)
.Select(x => x.GetViewModel)
.ToList();
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.Where(x => x.PurchaseStatus == model.PurchaseStatus)
.Select(x => x.GetViewModel)
.ToList();
}
public List<PurchaseViewModel> GetReportFilteredList(PurchaseSearchModel model)
@ -117,8 +124,8 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
var purchase = context.Purchases
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.FirstOrDefault(x => x.Id == model.Id);
if (purchase == null || purchase.UserId != model.UserId)
.FirstOrDefault(x => x.Id == model.Id && x.UserId == model.UserId);
if (purchase == null)
{
return null;
}

View File

@ -202,6 +202,7 @@ namespace HardwareShopRestApi.Controllers
PurchaseStatus = purchase.PurchaseStatus,
DatePurchase = purchase.DatePurchase,
PurchaseGoods = purchase.PurchaseGoods,
UserId = purchase.UserId
});
return true;
}

View File

@ -37,7 +37,24 @@ namespace HardwareShopRestApi.Controllers
}
}
[HttpGet]
[HttpGet]
public List<CommentViewModel>? GetCommentsOnBuild(int buildId)
{
try
{
return _commentLogic.ReadList(new CommentSearchModel
{
BuildId = buildId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка комментариев пользоватля");
throw;
}
}
[HttpGet]
public CommentViewModel? GetComment(int commentId)
{
try

View File

@ -49,12 +49,12 @@ namespace HardwareShopRestApi.Controllers
}
}
[HttpGet]
public List<PurchaseViewModel>? GetPurchases(int userId)
[HttpPost]
public List<PurchaseViewModel>? GetPurchases(PurchaseSearchModel model)
{
try
{
return _purchaseLogic.ReadList(new() { UserId = userId });
return _purchaseLogic.ReadList(model);
}
catch (Exception ex)
{
@ -63,7 +63,21 @@ namespace HardwareShopRestApi.Controllers
}
}
[HttpGet]
[HttpGet]
public List<PurchaseViewModel>? GetPurchasesNotDelivery(int userId)
{
try
{
return _purchaseLogic.ReadList(new() { UserId = userId, PurchaseStatus = PurchaseStatus.Выполняется });
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка товаров");
throw;
}
}
[HttpGet]
public PurchaseViewModel? GetPurchase(int purchaseId)
{
try

View File

@ -327,7 +327,7 @@ namespace HardwareShopWorkerApp.Controllers
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<PurchaseViewModel>>($"api/purchase/getpurchases?userId={APIClient.User.Id}"));
return View(APIClient.PostRequestWithResult<PurchaseSearchModel, List<PurchaseViewModel>>($"api/purchase/getpurchases", new() { UserId = APIClient.User.Id }));
}
[HttpPost]
@ -358,7 +358,8 @@ namespace HardwareShopWorkerApp.Controllers
{
return Redirect("~/Home/Enter");
}
ViewBag.Purchases = APIClient.GetRequest<List<PurchaseViewModel>>($"api/purchase/getpurchases?userId={APIClient.User.Id}");
ViewBag.Purchases = APIClient.PostRequestWithResult<PurchaseSearchModel, List<PurchaseViewModel>> ($"api/purchase/getpurchases", new() {UserId = APIClient.User.Id });
return View();
}
@ -438,7 +439,8 @@ namespace HardwareShopWorkerApp.Controllers
APIClient.PostRequest("api/purchase/UpdateStatusPurchase", new PurchaseBindingModel
{
Id = id,
PurchaseStatus = (PurchaseStatus)status
PurchaseStatus = (PurchaseStatus)status,
UserId = APIClient.User.Id
});
}
@ -520,8 +522,8 @@ namespace HardwareShopWorkerApp.Controllers
if (buildId <= 0)
{
throw new Exception($"Идентификтаор сборки не может быть ниже или равен 0");
}
ViewBag.Purchase = APIClient.GetRequest<List<PurchaseViewModel>>($"api/purchase/getpurchases?userId={APIClient.User.Id}");
}
ViewBag.Purchases = APIClient.PostRequestWithResult<PurchaseSearchModel, List<PurchaseViewModel>>($"api/purchase/getpurchases", new() { UserId = APIClient.User.Id, PurchaseStatus = PurchaseStatus.Выполняется });
return View(APIClient.GetRequest<List<Tuple<PurchaseViewModel, int>>>($"api/build/GetBuildPurchase?buildId={buildId}"));
}

View File

@ -30,7 +30,7 @@
Текст
</th>
<th>
Название сборки к которой относится комментарий
Сборка
</th>
<th>
Действия
@ -101,10 +101,6 @@
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
</div>
<div class="modal-body">
<div>
<label class="form-label">Сборка</label>
<select id="buildId" name="buildId" class="form-control" asp-items="@(new SelectList(@ViewBag.Builds,"Id", "BuildName"))"></select>
</div>
<div>
<label class="form-label">Текст</label>
<input type="text" class="form-control" required="required" id="text" name="text" />

View File

@ -21,8 +21,9 @@
<thead>
<tr>
<th scope="col">Товар</th>
<th scope="col">Количество</th>
<th scope="col">Цена</th>
<th scope="col">Количество</th>
<th scope="col">Сумма</th>
<th scope="col">Действие</th>
</tr>
</thead>
@ -70,6 +71,7 @@
console.log('try to add good')
var count = $('#count').val();
var good = $('#good').val();
if (count > 0 && good > 0){
$.ajax({
method: "GET",
url: `/Home/GetGood`,
@ -89,6 +91,7 @@
countElem.value = '1'
}
});
}
})
saveBtn.addEventListener("click", () => {
@ -126,7 +129,8 @@
let price = 0;
let count = 0;
list.forEach((elem) => {
resultTable.innerHTML += `<tr><td>${elem.good.goodName}</td><td>${elem.count}</td><td>${Math.round(elem.good.price * elem.count * 100) / 100}</td><td> \
console.log(elem);
resultTable.innerHTML += `<tr><td>${elem.good.goodName}</td><td>${elem.good.price}</td><td>${elem.count}</td><td>${Math.round(elem.good.price * elem.count * 100) / 100}</td><td> \
<div> \
<button onclick="deleteGood(${count})" type="button" class="btn btn-danger"> \
<i class="fa fa-trash" aria-hidden="true"></i> \

View File

@ -2,7 +2,7 @@
@model List<Tuple<PurchaseViewModel, int>>
@{
ViewData["Title"] = "Привязка сборок";
ViewData["Title"] = "Link purchase";
Layout = "~/Views/Shared/_LayoutWorker.cshtml";
}
@ -79,7 +79,7 @@
</div>
<div class="modal-body">
<label class="form-label">Покупка</label>
<select id="purchaseId" name="purchaseId" class="form-control" asp-items="@(new SelectList(@ViewBag.Purchase, "Id","Id"))"></select>
<select id="purchaseId" name="purchaseId" class="form-control" asp-items="@(new SelectList(@ViewBag.Purchases, "Id","Id"))"></select>
<div class="form-group">
<label>Количество</label>
<input type="number" class="form-control" required="required" name="count" />

View File

@ -82,22 +82,16 @@
@section Scripts
{
<script>
// get selected row
// display selected row data in text input
var table = document.getElementById("table");
var remove = document.getElementById("delete");
var done = document.getElementById("done");
var purchase = 0;
for (var i = 1; i < table.rows.length; i++) {
table.rows[i].onclick = function () {
// remove the background from the previous selected row
if (typeof index !== "undefined") {
table.rows[index].classList.toggle("selected");
}
// get the selected row index
index = this.rowIndex;
// add class selected to the row
this.classList.toggle("selected");
purchase = parseInt(this.cells[0].innerText);
remove.addEventListener("click", () => {

View File

@ -72,25 +72,27 @@
console.log('try to add good')
var count = $('#count').val();
var good = $('#good').val();
$.ajax({
method: "GET",
url: `/Home/GetGood`,
data: { Id: good },
success: function (result) {
let flag = false
if (list.length > 0) {
list.forEach((elem) => {
if (elem.good.id === parseInt(result.id)) {
console.log('good already added')
flag = true
}
})
if (count > 0 && good > 0) {
$.ajax({
method: "GET",
url: `/Home/GetGood`,
data: { Id: good },
success: function (result) {
let flag = false
if (list.length > 0) {
list.forEach((elem) => {
if (elem.good.id === parseInt(result.id)) {
console.log('good already added')
flag = true
}
})
}
if (!flag) list.push({ good: result, count: count })
reloadTable()
countElem.value = '1'
}
if (!flag) list.push({ good: result, count: count })
reloadTable()
countElem.value = '1'
}
});
});
}
})
saveBtn.addEventListener("click", () => {

View File

@ -48,8 +48,6 @@
const errorP = document.getElementById("error-p");
const errorDivShell = document.getElementById("error-div-shell");
// [Event listeners]
generateButton.addEventListener("click", () => {
const dateFrom = new Date(dateFromInput.value);
const dateTo = new Date(dateToInput.value);
@ -85,10 +83,6 @@
});
});
// ![Event listeners]
// [HTML gen]
const renderTable = function (reportData) {
tbody.innerHTML = "";
reportData.forEach((record) => {
@ -134,10 +128,6 @@
return td;
}
// ![HTML gen]
// [Other]
const getDate = function (iso) {
const year = iso.substring(0, 4);
const month = iso.substring(5, 7);
@ -146,7 +136,5 @@
return date;
}
// ![Other]
</script>
}

View File

@ -1,6 +1,6 @@
@using HardwareShopContracts.ViewModels
@{
ViewData["Title"] = "Получение списка";
ViewData["Title"] = "List components";
Layout = "~/Views/Shared/_LayoutWorker.cshtml";
}