ik
This commit is contained in:
parent
e579c33a24
commit
a77846b9bf
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
@ -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("сумма затраты")]
|
||||
|
@ -23,16 +23,12 @@ namespace ZooDataBaseImplement.Implements
|
||||
public List<CostViewModel> 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)
|
||||
|
@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,8 @@ namespace ZooDataModels.Models
|
||||
{
|
||||
public interface ICostModel : IId
|
||||
{
|
||||
string CostName { get; }
|
||||
int EmployeeId { get; }
|
||||
string CostName { get; }
|
||||
double CostPrice { get; }
|
||||
}
|
||||
}
|
||||
|
@ -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<CostViewModel> GetCosts(int EmployeeId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _cost.ReadList(new CostSearchModel { EmployeeId = EmployeeId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка животных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<CostViewModel> GetAllCosts()
|
||||
{
|
||||
try
|
||||
|
@ -15,11 +15,13 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IPreserveStorage, PreserveStorage>();
|
||||
builder.Services.AddTransient<IEmployeeStorage, EmployeeStorage>();
|
||||
builder.Services.AddTransient<IRouteStorage, RouteStorage>();
|
||||
builder.Services.AddTransient<ICostStorage, CostStorage>();
|
||||
|
||||
builder.Services.AddTransient<IPreserveLogic, PreserveLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IEmployeeLogic, EmployeeLogic>();
|
||||
builder.Services.AddTransient<IRouteLogic, RouteLogic>();
|
||||
builder.Services.AddTransient<ICostStorage, CostStorage>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
@ -296,8 +296,8 @@ namespace ZooShowEmployeeApp.Controllers
|
||||
{
|
||||
return Redirect("~/Home/Enter");
|
||||
}
|
||||
return View(APIEmployee.GetRequest<List<CostViewModel>>($"api/Cost/GetAllCosts?"));
|
||||
}
|
||||
return View(APIEmployee.GetRequest<List<CostViewModel>>($"api/Cost/getCosts?employeeid={APIEmployee.Employee.Id}"));
|
||||
}
|
||||
public IActionResult CreateCost()
|
||||
{
|
||||
if (APIEmployee.Employee == null)
|
||||
|
@ -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<CostViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Costs";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Статьи затрат</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<a asp-action="CreateCost">Создать Заповедник</a>
|
||||
<a asp-action="UpdateCost">Обновить Заповедник</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Название
|
||||
</th>
|
||||
<th>
|
||||
Сумма
|
||||
</th>
|
||||
<th>
|
||||
Удалить статью
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.CostName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.CostPrice)
|
||||
</td>
|
||||
<td>
|
||||
<form method="post">
|
||||
<input type="text" title="id" name="id" value="@item.Id" hidden="hidden" />
|
||||
<input type="submit" class="btn btn-danger" value="Удалить" />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user