diff --git a/git/JurasicZoo/ZooContracts/BindingModels/CostBindingModel.cs b/git/JurasicZoo/ZooContracts/BindingModels/CostBindingModel.cs index 39a09bd..75191ef 100644 --- a/git/JurasicZoo/ZooContracts/BindingModels/CostBindingModel.cs +++ b/git/JurasicZoo/ZooContracts/BindingModels/CostBindingModel.cs @@ -10,7 +10,8 @@ namespace ZooContracts.BindingModels public class CostBindingModel : ICostModel { public int Id { get; set; } - public string CostName { get; set; } = string.Empty; + public int EmployeeId { get; set; } + public string CostName { get; set; } = string.Empty; public double CostPrice { get; set; } } } diff --git a/git/JurasicZoo/ZooContracts/SearchModels/CostSearchModel.cs b/git/JurasicZoo/ZooContracts/SearchModels/CostSearchModel.cs index b68b9f6..100e7d5 100644 --- a/git/JurasicZoo/ZooContracts/SearchModels/CostSearchModel.cs +++ b/git/JurasicZoo/ZooContracts/SearchModels/CostSearchModel.cs @@ -9,7 +9,8 @@ namespace ZooContracts.SearchModels public class CostSearchModel { public int? Id { get; set; } - public string? CostName { get; set; } + public int EmployeeId { get; set; } + public string? CostName { get; set; } public double CostPrice { get; set; } } } diff --git a/git/JurasicZoo/ZooContracts/ViewModels/CostViewModel.cs b/git/JurasicZoo/ZooContracts/ViewModels/CostViewModel.cs index de5634b..1586946 100644 --- a/git/JurasicZoo/ZooContracts/ViewModels/CostViewModel.cs +++ b/git/JurasicZoo/ZooContracts/ViewModels/CostViewModel.cs @@ -10,7 +10,8 @@ namespace ZooContracts.ViewModels { public class CostViewModel : ICostModel { - public int Id { get; set; } + public int EmployeeId { get; set; } + public int Id { get; set; } [DisplayName("название статьи затрат")] public string CostName { get; set; } = string.Empty; [DisplayName("сумма затраты")] diff --git a/git/JurasicZoo/ZooDataBaseImplement/Implements/CostStorage.cs b/git/JurasicZoo/ZooDataBaseImplement/Implements/CostStorage.cs index 2683ad8..bd9d4bd 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Implements/CostStorage.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Implements/CostStorage.cs @@ -23,16 +23,12 @@ namespace ZooDataBaseImplement.Implements public List GetFilteredList(CostSearchModel model) { - if (string.IsNullOrEmpty(model.CostName)) - { - return new(); - } using var context = new ZooDatabase(); - return context.Costs - .Where(x => x.CostName.Contains(model.CostName)) - .Select(x => x.GetViewModel) - .ToList(); - } + return context.Costs.Where(x => x.EmployeeId == model.EmployeeId) + .Where(x => String.IsNullOrEmpty(model.CostName) || x.CostName.Contains(model.CostName)) + .Select(x => x.GetViewModel) + .ToList(); + } public CostViewModel? GetElement(CostSearchModel model) { if (string.IsNullOrEmpty(model.CostName) && !model.Id.HasValue) diff --git a/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs b/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs index 645b730..c62ca25 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs @@ -14,7 +14,10 @@ namespace ZooDataBaseImplement.Models public class Cost : ICostModel { public int Id { get; set; } - [Required] + [Required] + + public int EmployeeId { get; set; } + [Required] public string CostName { get; set; } = string.Empty; [Required] public double CostPrice { get; set; } @@ -31,7 +34,8 @@ namespace ZooDataBaseImplement.Models Id = model.Id, CostName = model.CostName, CostPrice = model.CostPrice, - }; + EmployeeId = model.EmployeeId + }; } public void Update(CostBindingModel model) { @@ -47,7 +51,8 @@ namespace ZooDataBaseImplement.Models Id = Id, CostName = CostName, CostPrice = CostPrice, - }; + EmployeeId = EmployeeId + }; } } diff --git a/git/JurasicZoo/ZooDataModels/Models/ICostModel.cs b/git/JurasicZoo/ZooDataModels/Models/ICostModel.cs index bb49c96..003e9ac 100644 --- a/git/JurasicZoo/ZooDataModels/Models/ICostModel.cs +++ b/git/JurasicZoo/ZooDataModels/Models/ICostModel.cs @@ -8,7 +8,8 @@ namespace ZooDataModels.Models { public interface ICostModel : IId { - string CostName { get; } + int EmployeeId { get; } + string CostName { get; } double CostPrice { get; } } } diff --git a/git/JurasicZoo/ZooRestApi/Controllers/CostController.cs b/git/JurasicZoo/ZooRestApi/Controllers/CostController.cs index c3b334d..085e0a8 100644 --- a/git/JurasicZoo/ZooRestApi/Controllers/CostController.cs +++ b/git/JurasicZoo/ZooRestApi/Controllers/CostController.cs @@ -4,6 +4,7 @@ using ZooContracts.BuisnessLogicsContracts; using ZooContracts.BusinessLogicsContracts; using ZooContracts.SearchModels; using ZooContracts.ViewModels; +using ZooDataBaseImplement.Models; namespace ZooRestApi.Controllers { @@ -19,7 +20,21 @@ namespace ZooRestApi.Controllers _logger = logger; _cost = cost; } - [HttpGet] + + [HttpGet] + public List GetCosts(int EmployeeId) + { + try + { + return _cost.ReadList(new CostSearchModel { EmployeeId = EmployeeId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения списка животных"); + throw; + } + } + [HttpGet] public List GetAllCosts() { try diff --git a/git/JurasicZoo/ZooRestApi/Program.cs b/git/JurasicZoo/ZooRestApi/Program.cs index 7a5393f..69da5a7 100644 --- a/git/JurasicZoo/ZooRestApi/Program.cs +++ b/git/JurasicZoo/ZooRestApi/Program.cs @@ -15,11 +15,13 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs b/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs index 9726374..6056664 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs +++ b/git/JurasicZoo/ZooShowEmployeeApp/Controllers/HomeController.cs @@ -296,8 +296,8 @@ namespace ZooShowEmployeeApp.Controllers { return Redirect("~/Home/Enter"); } - return View(APIEmployee.GetRequest>($"api/Cost/GetAllCosts?")); - } + return View(APIEmployee.GetRequest>($"api/Cost/getCosts?employeeid={APIEmployee.Employee.Id}")); + } public IActionResult CreateCost() { if (APIEmployee.Employee == null) diff --git a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexCost.cshtml b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexCost.cshtml index 7b18b6c..701f7ba 100644 --- a/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexCost.cshtml +++ b/git/JurasicZoo/ZooShowEmployeeApp/Views/Home/IndexCost.cshtml @@ -1,12 +1,66 @@ -using Microsoft.AspNetCore.Mvc; +@using ZooContracts.ViewModels; -namespace ZooShowEmployeeApp.Views.Home -{ - public class UpdateCost : Controller - { - public IActionResult Index() - { - return View(); - } - } +@model List + +@{ + ViewData["Title"] = "Costs"; } + +
+

Статьи затрат

+
+ + +
+ @{ + if (Model == null) + { +

Авторизируйтесь

+ return; + } +

+ Создать Заповедник + Обновить Заповедник +

+ + + + + + + + + + + @foreach (var item in Model) + { + + + + + + + } + +
+ Номер + + Название + + Сумма + + Удалить статью +
+ @Html.DisplayFor(modelItem => item.Id) + + @Html.DisplayFor(modelItem => item.CostName) + + @Html.DisplayFor(modelItem => item.CostPrice) + +
+ + +
+
+ } +
\ No newline at end of file