обновление политки конфиденциальности

This commit is contained in:
dasha 2023-05-19 16:49:20 +04:00
parent 2f80dcf920
commit 60c507bb4b
9 changed files with 39 additions and 156 deletions

View File

@ -10,7 +10,7 @@ namespace HardwareShopDatabaseImplement
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=Computer_Hardware_Store4;Username=postgres;Password=1234");
optionsBuilder.UseNpgsql("Host=localhost;Port=5433;Database=Computer_Hardware_Store;Username=user;Password=12345");
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
}

View File

@ -2,6 +2,7 @@
using HardwareShopContracts.SearchModels;
using HardwareShopContracts.StoragesContracts;
using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.Storekeeper;
using HardwareShopDatabaseImplement.Models.Worker;
using Microsoft.EntityFrameworkCore;
@ -89,7 +90,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Include(x => x.Purchases)
.ThenInclude(x => x.Purchase)
.FirstOrDefault(x => x.Id == model.Id);
if (build == null)
if (build == null || build.UserId != build.UserId)
{
return null;
}

View File

@ -118,7 +118,7 @@ namespace HardwareShopDatabaseImplement.Implements.Worker
.Include(x => x.Goods)
.ThenInclude(x => x.Good)
.FirstOrDefault(x => x.Id == model.Id);
if (purchase == null)
if (purchase == null || purchase.UserId != model.UserId)
{
return null;
}

View File

@ -108,6 +108,8 @@ namespace HardwareShopRestApi.Controllers
{
try
{
var build = _buildLogic.ReadElement(new() { Id = model.Id });
model.Price = build.Price;
_buildLogic.Update(model);
}
catch (Exception ex)
@ -117,46 +119,6 @@ namespace HardwareShopRestApi.Controllers
}
}
[HttpGet]
public bool LinkPurchase(int buildId, int purchaseId, int count)
{
try
{
var build = GetBuild(buildId);//APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
if (build.BuildPurchases.ContainsKey(purchaseId))
{
build.BuildPurchases[purchaseId] = (purchase, build.BuildPurchases[purchaseId].Item2 + count);
}
else
{
build.BuildPurchases.Add(purchaseId, (purchase as IPurchaseModel, count));
}
Update(new BuildBindingModel
{
Id = buildId,
Price = build.Price,
BuildName = build.BuildName,
BuildPurchases = build.BuildPurchases
});
purchase.Sum = Calc(purchase.Id);
_purchaseLogic.Update(new PurchaseBindingModel
{
Id = purchase.Id,
Sum = purchase.Sum,
PurchaseStatus = purchase.PurchaseStatus,
PurchaseGoods = purchase.PurchaseGoods,
});
return true;
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка обновления данных");
throw;
}
}
private double Calc(int purchaseId)
{
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
@ -173,16 +135,17 @@ namespace HardwareShopRestApi.Controllers
}
[HttpGet]
public bool DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId)
public bool DeleteLinkPurchase(int deleteBuildId, int deletePurchaseId, int userId)
{
try
{
var build = GetBuild(deleteBuildId);//APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
var build = _buildLogic.ReadElement(new() { Id = deleteBuildId });
var purchase = _purchaseLogic.ReadElement(new() { Id = deletePurchaseId });
if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
build.BuildPurchases.Remove(deletePurchaseId);//Add(purchaseId, (purchase as IPurchaseModel, count));
if (purchase == null || build == null || build.UserId != userId || purchase.UserId != userId
|| purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
build.BuildPurchases.Remove(deletePurchaseId);
Update(new BuildBindingModel
_buildLogic.Update(new BuildBindingModel
{
Id = deleteBuildId,
Price = build.Price,
@ -208,24 +171,25 @@ namespace HardwareShopRestApi.Controllers
}
[HttpGet]
public bool UpdateLinkPurchase(int updateBuildId, int updatePurchaseId, int count)
public bool UpdateLinkPurchase(int buildId, int purchaseId, int count, int userId)
{
try
{
var build = GetBuild(updateBuildId);//APIClient.GetRequest<BuildViewModel>($"api/build/getBuild?buildId={buildId}");
var purchase = _purchaseLogic.ReadElement(new() { Id = updatePurchaseId });
if (purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
if (build.BuildPurchases.ContainsKey(updatePurchaseId))
var build = _buildLogic.ReadElement(new() { Id = buildId });
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
if (purchase == null || build == null || build.UserId != userId || purchase.UserId != userId
|| purchase.PurchaseStatus == PurchaseStatus.Выдан) return false;
if (build.BuildPurchases.ContainsKey(purchaseId))
{
build.BuildPurchases[updatePurchaseId] = (build.BuildPurchases[updatePurchaseId].Item1, count);
build.BuildPurchases[purchaseId] = (build.BuildPurchases[purchaseId].Item1, count);
}
else
{
return false;
build.BuildPurchases.Add(purchaseId, (purchase, count));
}
Update(new BuildBindingModel
_buildLogic.Update(new BuildBindingModel
{
Id = updateBuildId,
Id = buildId,
Price = build.Price,
BuildName = build.BuildName,
BuildPurchases = build.BuildPurchases

View File

@ -26,12 +26,12 @@ namespace HardwareShopRestApi.Controllers
}
[HttpGet]
public Tuple<PurchaseViewModel, List<Tuple<GoodViewModel, int>>>? GetPurchaseUpdate(int purchaseId)
public Tuple<PurchaseViewModel, List<Tuple<GoodViewModel, int>>>? GetPurchaseUpdate(int purchaseId, int userId)
{
try
{
var purchase = _purchaseLogic.ReadElement(new() { Id = purchaseId });
if (purchase == null)
if (purchase == null || purchase.UserId != userId)
return null;
var tuple = Tuple.Create(purchase,
purchase.PurchaseGoods.Select(x => Tuple.Create(new GoodViewModel

View File

@ -198,7 +198,7 @@ namespace HardwareShopWorkerApp.Controllers
{
throw new Exception($"Количество сборок в покупке не может быть ниже или равен 0");
}
APIClient.GetRequest<bool>($"api/build/linkPurchase?buildId={buildId}&purchaseId={purchaseId}&count={count}");
APIClient.GetRequest<bool>($"api/build/UpdateLinkPurchase?buildId={buildId}&purchaseId={purchaseId}&count={count}&userId={APIClient.User.Id}");
Response.Redirect($"LinkPurchase?buildId={buildId}");
}
@ -490,7 +490,7 @@ namespace HardwareShopWorkerApp.Controllers
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
var result = APIClient.GetRequest<Tuple<PurchaseViewModel, List<Tuple<GoodViewModel?, int>>>?>($"api/purchase/getpurchaseupdate?purchaseId={purchaseId}");
var result = APIClient.GetRequest<Tuple<PurchaseViewModel, List<Tuple<GoodViewModel?, int>>>?>($"api/purchase/getpurchaseupdate?purchaseId={purchaseId}&userId={APIClient.User.Id}");
return result;
}
@ -541,7 +541,7 @@ namespace HardwareShopWorkerApp.Controllers
{
throw new Exception($"Идентификтаор покупки не может быть ниже или равен 0");
}
APIClient.GetRequest<bool>($"api/build/deleteLinkPurchase?deleteBuildId={deleteBuildId}&deletePurchaseId={deletePurchaseId}");
APIClient.GetRequest<bool>($"api/build/deleteLinkPurchase?deleteBuildId={deleteBuildId}&deletePurchaseId={deletePurchaseId}&userId={APIClient.User.Id}");
Response.Redirect($"LinkPurchase?buildId={deleteBuildId}");
}
@ -560,7 +560,7 @@ namespace HardwareShopWorkerApp.Controllers
{
throw new Exception($"Идентификтаор покупки не может быть ниже или равен 0");
}
APIClient.GetRequest<bool>($"api/build/UpdateLinkPurchase?updateBuildId={updateBuildId}&updatePurchaseId={updatePurchaseId}&count={count}");
APIClient.GetRequest<bool>($"api/build/UpdateLinkPurchase?updateBuildId={updateBuildId}&updatePurchaseId={updatePurchaseId}&count={count}&userId={APIClient.User.Id}");
Response.Redirect($"LinkPurchase?buildId={updateBuildId}");
}

View File

@ -98,7 +98,7 @@
</div>
<div class="modal-body">
<div class="form-group">
<label>Name</label>
<label>Название</label>
<input type="text" class="form-control" required="required" id="name" name="name" />
</div>
</div>

View File

@ -74,16 +74,16 @@
<div class="modal-content">
<form method="get" asp-controller="home" asp-action="LinkBuildPurchase">
<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>
<select id="purchaseId" name="purchaseId" class="form-control" asp-items="@(new SelectList(@ViewBag.Purchase, "Id","Id"))"></select>
<div class="form-group">
<label>Количество</label>
<input type="number" class="form-control" required="required" name="count" />
</div>
<label class="form-label">Сборка</label>
<select id="purchaseId" name="purchaseId" class="form-control" asp-items="@(new SelectList(@ViewBag.Purchase, "Id","Id"))"></select>
</div>
<input type="hidden" id="buildId" name="buildId" />
<div class="modal-footer">
@ -122,9 +122,9 @@
<div class="modal fade" id="updateModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="get" asp-controller="home" asp-action="UpdateLinkPurchase">
<form method="get" asp-controller="home" asp-action="LinkBuildPurchase">
<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">
@ -133,8 +133,8 @@
<input type="number" class="form-control" required="required" name="count" />
</div>
</div>
<input type="hidden" id="updateBuildId" name="updateBuildId" />
<input type="hidden" id="updatePurchaseId" name="updatePurchaseId" />
<input type="hidden" id="updateBuildId" name="buildId" />
<input type="hidden" id="updatePurchaseId" name="purchaseId" />
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Закрыть</button>
<input type="submit" class="btn btn-primary" value="Сохранить">
@ -177,85 +177,4 @@
console.log(purchaseId);
}
</script>
}
@*
@{
ViewData["Title"] = "LinkPurchase";
Layout = "~/Views/Shared/_LayoutWorker.cshtml";
}
<form class="d-flex justify-content-evenly">
<div class=" col-sm-8">
<div class="text-center">
<h2 class="display-4">Выбранные покупки</h2>
</div>
<div>
<label class="form-label">Сборка</label>
<select class="form-select" name="role">
<option value="1">Сборка 1</option>
<option value="2">Сборка 2</option>
</select>
</div>
<div class="text-center" name="id">
<table class="table">
<thead>
<tr>
<th>
Номер
</th>
<th>
Дата оплаты
</th>
<th>
Сумма
</th>
<th>
Статус
</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
<div class="text-center d-flex flex-column mt-5">
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">Добавить</button>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal">Изменить</button>
<button type="button" class="btn btn-primary">Удалить</button>
<button type="button" class="btn btn-primary">Обновить</button>
<button type="submit" class="btn btn-primary">Сохранить</button>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<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>
<label class="form-label">Покупка</label>
<select class="form-select">
<option value="1">Покупка 1</option>
<option value="2">Покупка 2</option>
</select>
</div>
<div>
<label class="form-label">Количество</label>
<input type="number" class="form-control">
</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>
</div>
</form>*@
}

View File

@ -63,7 +63,6 @@
let list = [];
let status;
const submitGoodBtn = document.getElementById("savegood");
//const editBtn = document.getElementById("editcomponent");
const saveBtn = document.getElementById("createpurchase");
const countElem = document.getElementById("count");
const resultTable = document.getElementById("result");
@ -98,7 +97,7 @@
console.log('try to add purchase')
console.log(list)
if (list.length == 0) {
alert('failed add good. components are empty')
alert('failed add purchase. goods are empty')
return
}
let goods = []
@ -165,7 +164,7 @@
reloadTable()
}
else
alert("Ошибка получения товара")
alert("Ошибка получения покупки")
}
})
.fail(function (xhr, textStatus, errorThrown) {