fix
This commit is contained in:
parent
5f5c290acf
commit
d4e4e44d4c
@ -12,5 +12,6 @@ namespace CanteenContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public int VisitorId { get; set; }
|
||||
public string TablewareName { get; set; } = string.Empty;
|
||||
public int Count { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ namespace CanteenContracts.View
|
||||
|
||||
[DisplayName("Название прибора")]
|
||||
public string TablewareName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
[DisplayName("ID прибора")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ namespace CanteenDataModels.Models
|
||||
{
|
||||
int VisitorId { get; }
|
||||
string TablewareName { get; }
|
||||
int Count { get; }
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace CanteenDatabaseImplement
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-AOSK1F5\SQLEXPRESS;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-A68O3K0;Initial Catalog=CanteenDataBase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -19,6 +19,8 @@ namespace CanteenDatabaseImplement.Models
|
||||
public int VisitorId { get; private set; }
|
||||
[Required]
|
||||
public string TablewareName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[ForeignKey("TablewareId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public virtual Visitor Visitor { get; set; }
|
||||
@ -33,7 +35,8 @@ namespace CanteenDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
VisitorId = model.VisitorId,
|
||||
TablewareName = model.TablewareName
|
||||
TablewareName = model.TablewareName,
|
||||
Count = model.Count
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
using CanteenContracts.BindingModels;
|
||||
using CanteenContracts.BusinessLogicsContracts;
|
||||
using CanteenContracts.View;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@ -12,13 +13,15 @@ namespace CanteenRestApi.Controllers
|
||||
private readonly ICookLogic _cook;
|
||||
private readonly IDishLogic _dish;
|
||||
private readonly IProductLogic _product;
|
||||
private readonly ITablewareLogic _tableware;
|
||||
|
||||
public MainController(ILogger<MainController> logger, ICookLogic cook, IDishLogic dish, IProductLogic product)
|
||||
public MainController(ILogger<MainController> logger, ICookLogic cook, IDishLogic dish, IProductLogic product, ITablewareLogic tableware)
|
||||
{
|
||||
_logger = logger;
|
||||
_cook = cook;
|
||||
_dish = dish;
|
||||
_product = product;
|
||||
_tableware = tableware;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -34,5 +37,31 @@ namespace CanteenRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<TablewareViewModel>? GetTablewareList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _tableware.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading list of bouquets");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateTableware(TablewareBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_tableware.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error during loading list of bouquets");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -14,11 +14,13 @@ builder.Services.AddTransient<IManagerStorage, ManagerStorage>();
|
||||
builder.Services.AddTransient<ICookStorage, CookStorage>();
|
||||
builder.Services.AddTransient<IProductStorage, ProductStorage>();
|
||||
builder.Services.AddTransient<IDishStorage, DishStorage>();
|
||||
builder.Services.AddTransient<ITablewareStorage, TablewareStorage>();
|
||||
|
||||
builder.Services.AddTransient<IManagerLogic, ManagerLogic>();
|
||||
builder.Services.AddTransient<ICookLogic, CookLogic>();
|
||||
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||
builder.Services.AddTransient<IDishLogic, DishLogic>();
|
||||
builder.Services.AddTransient<ITablewareLogic, TablewareLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
|
@ -8,8 +8,6 @@ namespace CanteenVisitorApp
|
||||
public static class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
public static VisitorViewModel? Manager { get; set; } = null;
|
||||
|
||||
public static void Connect(IConfiguration configuration)
|
||||
{
|
||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||
@ -17,7 +15,6 @@ namespace CanteenVisitorApp
|
||||
_client.DefaultRequestHeaders.Accept.Add(new
|
||||
MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
@ -31,7 +28,6 @@ namespace CanteenVisitorApp
|
||||
throw new Exception(result);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PostRequest<T>(string requestUrl, T model)
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
|
@ -17,4 +17,10 @@
|
||||
<ProjectReference Include="..\CanteenDataModels\CanteenDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using CanteenContracts.View;
|
||||
using CanteenContracts.BindingModels;
|
||||
using CanteenContracts.View;
|
||||
using CanteenVisitorApp.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Diagnostics;
|
||||
@ -27,7 +28,7 @@ namespace CanteenVisitorApp.Controllers
|
||||
public IActionResult Lunches()
|
||||
{
|
||||
|
||||
//ViewBag.Cooks = APIClient.GetRequest<List<LunchViewModel>>("api/main/getcooklist");
|
||||
ViewBag.Cooks = APIClient.GetRequest<List<LunchViewModel>>("api/main/getcooklist");
|
||||
ViewBag.Lunches = new List<LunchViewModel>();
|
||||
return View();
|
||||
}
|
||||
@ -35,7 +36,7 @@ namespace CanteenVisitorApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Tablewares()
|
||||
{
|
||||
ViewBag.Tablewares = new List<TablewareViewModel>();
|
||||
ViewBag.Tablewares = APIClient.GetRequest<List<TablewareViewModel>>("api/main/gettablewarelist");
|
||||
return View();
|
||||
}
|
||||
|
||||
@ -60,6 +61,18 @@ namespace CanteenVisitorApp.Controllers
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void CreateTableware(string TablewareName, int TablewareCount)
|
||||
{
|
||||
APIClient.PostRequest("api/main/CreateTableware", new TablewareBindingModel
|
||||
{
|
||||
VisitorId = 1,
|
||||
TablewareName = TablewareName,
|
||||
Count = TablewareCount
|
||||
});
|
||||
Response.Redirect("Tablewares");
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreateTableware()
|
||||
{
|
||||
|
@ -1,9 +1,12 @@
|
||||
using CanteenVisitorApp;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddControllersWithViews();
|
||||
|
||||
var app = builder.Build();
|
||||
APIClient.Connect(builder.Configuration);
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (!app.Environment.IsDevelopment())
|
||||
|
@ -14,7 +14,13 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Название прибора:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="OrderName" id="OrderName" />
|
||||
<input type="text" name="TablewareName" id="TablewareName" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8">
|
||||
<input type="number" name="TablewareCount" id="TablewareCount" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
|
@ -18,11 +18,11 @@
|
||||
<tbody>
|
||||
@foreach (var cook in ViewBag.Tablewares)
|
||||
{
|
||||
<tr>
|
||||
<td>@cook.Id</td>
|
||||
<td>@cook.VisitorId</td>
|
||||
<td>@cook.TablewareName</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>@cook.Id</td>
|
||||
<td>@cook.VisitorId</td>
|
||||
<td>@cook.TablewareName</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
Loading…
Reference in New Issue
Block a user