RestApi fix v1.0

This commit is contained in:
vladimir_zinovev 2024-04-30 22:43:00 +04:00
parent 7d1cc0916a
commit 95aca7fd0f
4 changed files with 19 additions and 5 deletions

View File

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EntityFramework" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.1">

View File

@ -28,9 +28,10 @@ namespace AutoRepairShopDatabaseImplement.Implements
public ManagerViewModel? GetElement(ManagerSearchModel model)
{
using var context = new AutoRepairShopDatabase();
var manager = context.Managers.FirstOrDefault(x =>
x.Login.Equals(model.Login, StringComparison.OrdinalIgnoreCase));
return manager != null ? manager.GetViewModel : null;
return context.Managers.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Login) && x.Login == model.Login) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
}
public List<ManagerViewModel> GetFilteredList(ManagerSearchModel model)
{

View File

@ -37,5 +37,17 @@ namespace AutoRepairShopRestApi.Controllers
}
}
[HttpPost]
public void AddWork(WorkBindingModel workModel)
{
try
{
_work.AddWork(workModel);
}
catch (Exception ex)
{
_logger.LogError(ex, "Error adding work");
}
}
}
}

View File

@ -36,7 +36,7 @@ namespace AutoRepairShopRestApi.Controllers
throw;
}
}
[HttpPost]
[HttpPost("register")]
public void Register(ManagerBindingModel model)
{
try
@ -49,7 +49,7 @@ namespace AutoRepairShopRestApi.Controllers
throw;
}
}
[HttpPost]
[HttpPost("update")]
public void UpdateData(ManagerBindingModel model)
{
try