Ничего не работает)

This commit is contained in:
goblinrf 2024-04-25 23:52:14 +04:00
parent 8d3c75cdf9
commit f86f0a91e3
7 changed files with 324 additions and 157 deletions

View File

@ -1,152 +1,226 @@
using Microsoft.AspNetCore.Mvc;
using VetClinicAdminApp.Models;
using System.Diagnostics;
using VetClinicContracts.BindingModels;
using VetClinicContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
namespace VetClinicAdminApp.Controllers
{
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}
public IActionResult Index()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
public IActionResult Index()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
return
View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/visit/getvisits?vistId={APIAdmin.Admin.Id}"));
return View(APIAdmin.GetRequest<List<VisitViewModel>>($"api/main/getorders?clientId={APIAdmin.Admin.Id}"));
}
}
[HttpGet]
public IActionResult Privacy()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
[HttpGet]
public IActionResult Privacy()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
return View(APIAdmin.Admin);
}
return View(APIAdmin.Admin);
}
[HttpPost]
public void Privacy(string login, string password, string fio)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñóäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå email, ïàðîëü è ÔÈÎ");
}
APIAdmin.PostRequest("api/admin/updatedata", new
AdminBindingModel
{
Id = APIAdmin.Admin.Id,
AdminFIO = fio,
Email = login,
Password = password
});
APIAdmin.Admin.AdminFIO = fio;
APIAdmin.Admin.Email = login;
APIAdmin.Admin.Password = password;
Response.Redirect("Index");
}
[HttpPost]
public void Privacy(string login, string password, string fio)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå email è ïàðîëü");
}
APIAdmin.Admin =
APIAdmin.GetRequest<AdminViewModel>($"api/admin/login?login={login}&password={password}");
if (APIAdmin.Admin == null)
{
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string fio)
{
if (string.IsNullOrEmpty(login) ||
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
}
APIAdmin.PostRequest("api/admin/register", new
AdminBindingModel
{
AdminFIO = fio,
Email = login,
Password = password
});
Response.Redirect("Enter");
return;
}
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
}
public IActionResult Create()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
APIAdmin.PostRequest("api/admin/updatedata", new AdminBindingModel
{
Id = APIAdmin.Admin.Id,
AdminFIO = fio,
Email = login,
Password = password
});
APIAdmin.Admin.AdminFIO = fio;
APIAdmin.Admin.Email = login;
APIAdmin.Admin.Password = password;
Response.Redirect("Index");
}
[HttpPost]
public void CreateVisit(string name, DateTime visitdate)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name))
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
APIAdmin.PostRequest("api/visit/createvisit", new VisitBindingModel
{
NameVisit = name,
DateVisit = visitdate,
AdminId = APIAdmin.Admin.Id
});
Response.Redirect("Index");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel
{
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier
});
}
public IActionResult DeleteMedicine()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Visits = APIAdmin.GetRequest<List<VisitViewModel>>("api/visit/getvisits");
return View();
}
[HttpGet]
public IActionResult Enter()
{
return View();
}
[HttpPost]
public void DeleteVisit(int shop)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
APIAdmin.PostRequest("api/visit/deletevisit", new VisitBindingModel
{
Id = shop
});
Response.Redirect("Index");
}
[HttpPost]
public void Enter(string login, string password)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
{
throw new Exception("Ââåäèòå ëîãèí è ïàðîëü");
}
public IActionResult Update()
{
if (APIAdmin.Admin == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Medicines = APIAdmin.GetRequest<List<MedicineViewModel>>("api/shop/getvisits");
return View();
}
APIAdmin.Admin = APIAdmin.GetRequest<AdminViewModel>($"api/admin/login?login={login}&password={password}");
[HttpPost]
public void Update(int visit, string name, DateTime vistdate)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
if (string.IsNullOrEmpty(name) )
{
throw new Exception("Îøèáêà â ââåäåííûõ äàííûõ");
}
APIAdmin.PostRequest("api/visit/updatevisit", new VisitBindingModel
{
Id = visit,
NameVisit = name,
DateVisit = vistdate,
});
Response.Redirect("Index");
}
if (APIAdmin.Admin == null)
{
throw new Exception("Íåâåðíûé ëîãèí/ïàðîëü");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
Response.Redirect("Index");
}
[HttpGet]
public IActionResult Register()
{
return View();
}
[HttpPost]
public void Register(string login, string password, string fio)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Ââåäèòå ëîãèí, ïàðîëü è ÔÈÎ");
}
APIAdmin.PostRequest("api/admin/register", new AdminBindingModel
{
AdminFIO = fio,
Email = login,
Password = password
});
Response.Redirect("Enter");
return;
}
// [HttpGet]
// public IActionResult Create()
// {
// ViewBag.Snacks = APIAdmin.GetRequest<List<AnimalViewModel>>("api/main/getanimallist");
// return View();
// }
[HttpPost]
public void Create(int animal)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñóäà âõîä òîëüêî àâòîðèçîâàííûì");
}
//APIAdmin.PostRequest("api/main/createorder", new VisitBindingModel
//{
// AdminId = APIAdmin.Admin.Id,
// AnimalId = animal,
// });
Response.Redirect("Index");
}
}
}
[HttpGet]
public Tuple<VisitViewModel, string>? GetMedicine(int visitId)
{
if (APIAdmin.Admin == null)
{
throw new Exception("Âû êàê ñþäà ïîïàëè? Ñþäà âõîä òîëüêî àâòîðèçîâàííûì");
}
var result = APIAdmin.GetRequest<Tuple<VisitViewModel, List<string>>>($"api/visit/getvisit?visitid={visitId}");
if (result == null)
{
return default;
}
string table = "";
result.Item1.VisitAnimals.Clear();
for (int i = 0; i < result.Item2.Count; i++)
{
var animal = result.Item2[i];
table += "<tr>";
table += $"<td>{animal}</td>";
table += "</tr>";
}
return Tuple.Create(result.Item1, table);
}
}
}

View File

@ -16,7 +16,6 @@
<ItemGroup>
<ProjectReference Include="..\VetClinicContracts\VetClinicContracts.csproj" />
<ProjectReference Include="..\VetClinicDataBaseImplement\VetClinicDataBaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -21,16 +21,18 @@ namespace VetClinicBusinessLogic.BusinessLogics
_logger = logger;
_visitStorage = visitStorage;
}
public List<VisitViewModel>? ReadList(VisitSearchModel? model)
{
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
var list = model == null ? _visitStorage.GetFullList() : _visitStorage.GetFilteredList(model);
_logger.LogInformation("ReadList. NameVisit:{NameVisit}. Id:{ Id}", model?.NameVisit, model?.Id);
var list = model == null ? _visitStorage.GetFullList() :
_visitStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
return list;
}
public VisitViewModel? ReadElement(VisitSearchModel model)
@ -39,8 +41,7 @@ namespace VetClinicBusinessLogic.BusinessLogics
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadList. NameVisit:{NameVisit}. DateVisit {DateVisit}. Id:{Id}", model.NameVisit, model.DateVisit, model?.Id);
_logger.LogInformation("ReadElement. NameVisit:{NameVisit}.Id:{ Id}", model.NameVisit, model.Id);
var element = _visitStorage.GetElement(model);
if (element == null)
{
@ -54,7 +55,6 @@ namespace VetClinicBusinessLogic.BusinessLogics
public bool Create(VisitBindingModel model)
{
CheckModel(model);
if (_visitStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
@ -73,7 +73,6 @@ namespace VetClinicBusinessLogic.BusinessLogics
}
return true;
}
public bool Delete(VisitBindingModel model)
{
CheckModel(model, false);
@ -85,7 +84,9 @@ namespace VetClinicBusinessLogic.BusinessLogics
}
return true;
}
private void CheckModel(VisitBindingModel model, bool withParams = true)
private void CheckModel(VisitBindingModel model, bool withParams =
true)
{
if (model == null)
{
@ -95,24 +96,21 @@ namespace VetClinicBusinessLogic.BusinessLogics
{
return;
}
if (model.NameVisit == "")
if (string.IsNullOrEmpty(model.NameVisit))
{
throw new ArgumentNullException("Имя не должно быть пустым", nameof(model.NameVisit));
throw new ArgumentNullException("Нет названия визита",
nameof(model.NameVisit));
}
if (model.AdminId < 0)
{
throw new ArgumentNullException("Некорректный идентификатор у клиента", nameof(model.AdminId));
}
if (model.DateVisit == new DateTime())
{
throw new ArgumentNullException("Укажите Время", nameof(model.DateVisit));
}
_logger.LogInformation("Medicine. Medicine:{NameVisit}. Id: { Id}", model.NameVisit, model.Id);
var element = _visitStorage.GetElement(new VisitSearchModel
{
Id = model.Id
NameVisit = model.NameVisit
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Визит с таким названием уже есть");
}
}
}
}

View File

@ -7,8 +7,15 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.NETCore.App" Version="2.1.30" />
<PackageReference Include="NPOI" Version="2.7.0" />
</ItemGroup>
<ItemGroup>

View File

@ -28,7 +28,7 @@ namespace VetClinicDataBaseImplement.Implements
using var context = new VetClinicDatabase();
return context.Medicines.Include(x => x.Pharmacist).Include(x => x.Animals)
.ThenInclude(x => x.Animal)
.Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName)
.Where(x => (string.IsNullOrEmpty(model.MedicineName) || x.MedicineName.Contains(model.MedicineName)
&& (!model.PharmacistId.HasValue || x.PharmacistId == model.PharmacistId)))
.ToList()
.Select(x => x.GetViewModel)

View File

@ -0,0 +1,94 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using VetClinicContracts.BindingModels;
using VetClinicContracts.BusinessLogicsContracts;
using VetClinicContracts.SearchModels;
using VetClinicContracts.ViewModels;
namespace VetClinicRestApi.Controllers
{
[Route("api/[controller]/[action]")]
[ApiController]
public class VisitController : Controller
{
private readonly ILogger _logger;
private readonly IVisitLogic _visit;
public VisitController(ILogger<VisitController> logger, IVisitLogic visit)
{
_logger = logger;
_visit = visit;
}
[HttpGet]
public Tuple<VisitViewModel, List<string>>? GetVisit(int VisitId)
{
try
{
var elem = _visit.ReadElement(new VisitSearchModel { Id = VisitId });
if (elem == null)
return null;
return Tuple.Create(elem, elem.VisitAnimals.Select(x => x.Value.AnimalName).ToList());
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения визита по id={Id}", VisitId);
throw;
}
}
[HttpGet]
public List<VisitViewModel> GetVisits(int adminId)
{
try
{
return _visit.ReadList(new VisitSearchModel { AdminId = adminId});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения списка визитовв");
throw;
}
}
[HttpPost]
public bool CreateVisit(VisitBindingModel model)
{
try
{
return _visit.Create(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось создать визит");
throw;
}
}
[HttpPost]
public bool UpdateVisit(VisitBindingModel model)
{
try
{
model.VisitAnimals = null!;
return _visit.Update(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Не удалось обновить визит");
throw;
}
}
[HttpPost]
public bool DeleteVisit(VisitBindingModel model)
{
try
{
return _visit.Delete(model);
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления визита");
throw;
}
}
}
}

View File

@ -7,16 +7,11 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DinerDataBaseImplement\VetClinicDataBaseImplement.csproj" />
<ProjectReference Include="..\VetClinicBusinessLogic\VetClinicBusinessLogic.csproj" />
<ProjectReference Include="..\VetClinicContracts\VetClinicContracts.csproj" />
<ProjectReference Include="..\VetClinicDataBaseImplement\VetClinicDataBaseImplement.csproj" />