Починили Contracts, Specializations.

This commit is contained in:
Артём Алейкин 2023-05-19 13:20:14 +04:00
parent f3652285b9
commit 4bea770d99
23 changed files with 180 additions and 45 deletions

View File

@ -69,7 +69,7 @@ namespace CaseAccountingCustomerView.Controllers
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.Lawyers = APIUser.GetRequest<List<LawyerViewModel>> ViewBag.Lawyers = APIUser.GetRequest<List<LawyerViewModel>>
($"api/lawyer/getmany?userId={APIUser.User.Id}"); ($"api/lawyer/getallbyuser?userId={APIUser.User.Id}");
return View(); return View();
} }
@ -80,7 +80,7 @@ namespace CaseAccountingCustomerView.Controllers
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.Specializations = APIUser.GetRequest<List<SpecializationViewModel>> ViewBag.Specializations = APIUser.GetRequest<List<SpecializationViewModel>>
($"api/specialization/getmany?userId={APIUser.User.Id}"); ($"api/specialization/getallbyuser?userId={APIUser.User.Id}");
return View(); return View();
} }
@ -91,7 +91,7 @@ namespace CaseAccountingCustomerView.Controllers
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
ViewBag.Contracts = APIUser.GetRequest<List<ContractViewModel>> ViewBag.Contracts = APIUser.GetRequest<List<ContractViewModel>>
($"api/contract/getmany?userId={APIUser.User.Id}"); ($"api/contract/getallbyuser?userId={APIUser.User.Id}");
return View(); return View();
} }

View File

@ -21,4 +21,4 @@
Создать Создать
</button> </button>
<script src="~/js/contract/contract-create.js" asp-append-version="true"></script> <script src="~/js/Contracts/contract-create.js" asp-append-version="true"></script>

View File

@ -31,4 +31,4 @@
</button> </button>
} }
<script src="~/js/contract/contract-update.js" asp-append-version="true"></script> <script src="~/js/Contracts/contract-update.js" asp-append-version="true"></script>

View File

@ -0,0 +1,72 @@
@using CaseAccountingContracts.ViewModels
@{
ViewData["Title"] = "Контракты";
}
<div class="text-center">
<h1 class="display-4">Контракты</h1>
</div>
<div class="text-center">
@{
if (ViewBag.Contracts == null)
{
<h3 class="display-4">Войдите в аккаунт</h3>
return;
}
<div>
<a class="btn btn-secondary" asp-controller="Contracts" asp-action="Create">Добавить контракт</a>
</div>
<div class="d-flex mb-2 gap-1">
<a href="/Home/Contracts" id="go-button" class="button-primary text-button">
Перейти
</a>
</div>
<table class="table">
<thead>
<tr>
<th>
Услуга
</th>
<th>
Цена
</th>
<th>
Дата
</th>
<th>
Изменить запись
</th>
<th>
Удалить запись
</th>
</tr>
</thead>
<tbody>
@foreach (var item in ViewBag.Contracts)
{
<tr class="d-table-row">
<td>
@item.Service
</td>
<td>
@item.Coast
</td>
<td>
@item.Date
</td>
<td>
<a id="update-button-@item.Id" class="btn btn-secondary" asp-controller="Contracts" asp-action="Update" asp-route-id="@item.Id">Изменить</a>
</td>
<td>
<a id="remove-button-@item.Id" class="btn btn-secondary remove-btn" data-id="@item.Id">Удалить</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>
<script src="~/js/Contracts/contracts.js" asp-append-version="true"></script>

View File

@ -18,15 +18,6 @@
<div> <div>
<a class="btn btn-secondary" asp-controller="Lawyer" asp-action="Create">Добавить юриста</a> <a class="btn btn-secondary" asp-controller="Lawyer" asp-action="Create">Добавить юриста</a>
</div> </div>
<div class="d-flex mb-2 gap-1">
<div class="input-group" style="width: auto;">
<input id="page-input" type="number" min="1" value="@ViewBag.Page" max="@ViewBag.NumberOfPages" class="form-control" style="max-width: 5em">
<span class="input-group-text">/ @ViewBag.NumberOfPages</span>
</div>
<a href="/Home/Lawyers?page=@ViewBag.Page" id="go-button" class="button-primary text-button">
Перейти
</a>
</div>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>

View File

@ -0,0 +1,60 @@
@using CaseAccountingContracts.ViewModels
@{
ViewData["Title"] = "Специализации";
}
<div class="text-center">
<h1 class="display-4">Специализации</h1>
</div>
<div class="text-center">
@{
if (ViewBag.Specializations == null)
{
<h3 class="display-4">Войдите в аккаунт</h3>
return;
}
<div>
<a class="btn btn-secondary" asp-controller="Specializations" asp-action="Create">Добавить специализацию</a>
</div>
<div class="d-flex mb-2 gap-1">
<a href="/Home/Specializations" id="go-button" class="button-primary text-button">
Перейти
</a>
</div>
<table class="table">
<thead>
<tr>
<th>
Название
</th>
<th>
Изменить запись
</th>
<th>
Удалить запись
</th>
</tr>
</thead>
<tbody>
@foreach (var item in ViewBag.Specializations)
{
<tr class="d-table-row">
<td>
@item.Name
</td>
<td>
<a id="update-button-@item.Id" class="btn btn-secondary" asp-controller="Specialization" asp-action="Update" asp-route-id="@item.Id">Изменить</a>
</td>
<td>
<a id="remove-button-@item.Id" class="btn btn-secondary remove-btn" data-id="@item.Id">Удалить</a>
</td>
</tr>
}
</tbody>
</table>
}
</div>
<script src="~/js/specialization/specializations.js" asp-append-version="true"></script>

View File

@ -20,10 +20,19 @@
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between"> <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1"> <ul class="navbar-nav flex-grow-1">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Contracts">Контракты</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a> <a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Lawyers">Юристы</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Specializations">Специализации</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="HearingLawyerList">Получить список</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="GetReport">Получить отчёт</a>
</li> </li>
</ul> </ul>
</div> </div>

View File

@ -54,4 +54,4 @@
</div> </div>
} }
<script src="~/js/specialization/specialization-add-student.js" asp-append-version="true"></script> <script src="~/js/Specializations/specialization-add-student.js" asp-append-version="true"></script>

View File

@ -17,4 +17,4 @@
Создать Создать
</button> </button>
<script src="~/js/specialization/specialization-create.js" asp-append-version="true"></script> <script src="~/js/Specializations/specialization-create.js" asp-append-version="true"></script>

View File

@ -27,4 +27,4 @@
</button> </button>
} }
<script src="~/js/specialization/specialization-update.js" asp-append-version="true"></script> <script src="~/js/Specializations/specialization-update.js" asp-append-version="true"></script>

View File

@ -7,5 +7,5 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"IPAddress": "http://localhost:5146/" "IPAddress": "http://localhost:5146"
} }

View File

@ -30,7 +30,7 @@ createBtn.addEventListener("click", () => {
}; };
console.log(contract) console.log(contract)
$.ajax({ $.ajax({
url: "/contract/create", url: "/contracts/create",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(contract) data: JSON.stringify(contract)

View File

@ -21,15 +21,15 @@ const validate = function () {
}; };
createBtn.addEventListener("click", () => { createBtn.addEventListener("click", () => {
let specialization = { let specializationModel = {
"Name": nameInput.value, "Name": nameInput.value,
}; };
console.log(specialization) console.log(specializationModel)
$.ajax({ $.ajax({
url: "/specialization/create", url: "/specializations/create",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(specialization) data: JSON.stringify(specializationModel)
}).done(() => { }).done(() => {
window.location.href = "/Home/Specializations"; window.location.href = "/Home/Specializations";
}); });

View File

@ -28,7 +28,7 @@ updateBtn.addEventListener("click", () => {
}; };
console.log(specialization) console.log(specialization)
$.ajax({ $.ajax({
url: "/specialization/update", url: "/specializations/update",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(specialization) data: JSON.stringify(specialization)

View File

@ -10,7 +10,7 @@ var specialization = null;
window.addEventListener("load", async () => { window.addEventListener("load", async () => {
try { try {
const lawyersResponse = await $.ajax({ const lawyersResponse = await $.ajax({
url: `/lawyer/getallbyuserandspecialization?specialization=${specializationId}`, url: `/lawyers/getallbyuserandspecialization?specialization=${specializationId}`,
type: "GET", type: "GET",
contentType: "json" contentType: "json"
}); });
@ -21,7 +21,7 @@ window.addEventListener("load", async () => {
}); });
const specializationResponse = await $.ajax({ const specializationResponse = await $.ajax({
url: `/specialization/get?id=${specializationId}`, url: `/specializations/get?id=${specializationId}`,
type: 'GET', type: 'GET',
contentType: 'json' contentType: 'json'
}); });
@ -42,7 +42,7 @@ updateBtn.addEventListener("click", () => {
lawyer.specializationId = specialization.id; lawyer.specializationId = specialization.id;
$.ajax({ $.ajax({
url: "/lawyer/update", url: "/lawyers/update",
type: "POST", type: "POST",
contentType: "application/json", contentType: "application/json",
data: JSON.stringify(lawyer) data: JSON.stringify(lawyer)

View File

@ -8,7 +8,7 @@ removeButtons.forEach(function (button) {
var result = confirm("Вы уверены, что хотите удалить эту запись?"); var result = confirm("Вы уверены, что хотите удалить эту запись?");
if (result) { if (result) {
$.ajax({ $.ajax({
url: "/specialization/delete", url: "/specializations/delete",
type: "POST", type: "POST",
data: { Id: id } data: { Id: id }
}).done(() => { }).done(() => {

View File

@ -18,8 +18,8 @@ namespace CaseAccountingDataBaseImplement
Host=localhost; Host=localhost;
Port=5432; Port=5432;
Database=CaseAccountingDatabase; Database=CaseAccountingDatabase;
Username=courseuser; Username=postgres;
Password=courseuser"); Password=postgres");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -86,14 +86,13 @@ namespace CaseAccountingDataBaseImplement.Implements
public ContractViewModel? Insert(ContractBindingModel model) public ContractViewModel? Insert(ContractBindingModel model)
{ {
var newContract = Contract.Create(model); using var context = new CaseAccountingDatabase();
var newContract = Contract.Create(context, model);
if (newContract == null) if (newContract == null)
{ {
return null; return null;
} }
using var context = new CaseAccountingDatabase();
context.Contracts.Add(newContract); context.Contracts.Add(newContract);
context.SaveChanges(); context.SaveChanges();
return context.Contracts return context.Contracts

View File

@ -91,13 +91,13 @@ namespace CaseAccountingDataBaseImplement.Implements
public LawyerViewModel? Insert(LawyerBindingModel model) public LawyerViewModel? Insert(LawyerBindingModel model)
{ {
var newLawyer = Lawyer.Create(model); using var context = new CaseAccountingDatabase();
var newLawyer = Lawyer.Create(context, model);
if (newLawyer == null) if (newLawyer == null)
{ {
return null; return null;
} }
using var context = new CaseAccountingDatabase();
context.Lawyers.Add(newLawyer); context.Lawyers.Add(newLawyer);
context.SaveChanges(); context.SaveChanges();

View File

@ -85,14 +85,14 @@ namespace CaseAccountingDataBaseImplement.Implements
public SpecializationViewModel? Insert(SpecializationBindingModel model) public SpecializationViewModel? Insert(SpecializationBindingModel model)
{ {
var newSpecialization = Specialization.Create(model); using var context = new CaseAccountingDatabase();
var newSpecialization = Specialization.Create(context, model);
if (newSpecialization == null) if (newSpecialization == null)
{ {
return null; return null;
} }
using var context = new CaseAccountingDatabase();
context.Specializations.Add(newSpecialization); context.Specializations.Add(newSpecialization);
context.SaveChanges(); context.SaveChanges();
return context.Specializations return context.Specializations

View File

@ -53,7 +53,7 @@ namespace CaseAccountingDataBaseImplement.Models
} }
} }
public static Contract? Create(ContractBindingModel? model) public static Contract? Create(CaseAccountingDatabase context, ContractBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
@ -65,7 +65,8 @@ namespace CaseAccountingDataBaseImplement.Models
Service = model.Service, Service = model.Service,
Coast = model.Coast, Coast = model.Coast,
Date = model.Date, Date = model.Date,
UserId = model.UserId UserId = model.UserId,
User = context.Users.FirstOrDefault(x => x.Id == model.UserId) ?? throw new Exception("Not found user")
}; };
} }

View File

@ -57,7 +57,7 @@ namespace CaseAccountingDataBaseImplement.Models
} }
} }
public static Lawyer? Create(LawyerBindingModel? model) public static Lawyer? Create(CaseAccountingDatabase context, LawyerBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
@ -71,7 +71,9 @@ namespace CaseAccountingDataBaseImplement.Models
Patronymic = model.Patronymic, Patronymic = model.Patronymic,
Experience = model.Experience, Experience = model.Experience,
SpecializationId = model.SpecializationId, SpecializationId = model.SpecializationId,
UserId = model.UserId Specialization = context.Specializations.FirstOrDefault(x => x.Id == model.SpecializationId) ?? throw new Exception("specialization not found"),
UserId = model.UserId,
User = context.Users.FirstOrDefault(x => x.Id == model.UserId) ?? throw new Exception("User not found")
}; };
} }

View File

@ -30,7 +30,7 @@ namespace CaseAccountingDataBaseImplement.Models
[ForeignKey("SpecializationId")] [ForeignKey("SpecializationId")]
public virtual List<Case> Cases { get; set; } = new(); public virtual List<Case> Cases { get; set; } = new();
public static Specialization? Create (SpecializationBindingModel? model) public static Specialization? Create (CaseAccountingDatabase context, SpecializationBindingModel? model)
{ {
if (model == null) if (model == null)
{ {
@ -41,6 +41,7 @@ namespace CaseAccountingDataBaseImplement.Models
Id = model.Id, Id = model.Id,
Name = model.Name, Name = model.Name,
UserId = model.UserId, UserId = model.UserId,
User = context.Users.FirstOrDefault(x => x.Id == model.UserId) ?? throw new Exception("User not found"),
}; };
} }