diff --git a/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs b/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs index b262b07..f1a9ada 100644 --- a/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs +++ b/Canteen/CanteenContracts/BindingModels/TablewareBindingModel.cs @@ -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; } } } diff --git a/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs b/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs index f02cab0..3373526 100644 --- a/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs +++ b/Canteen/CanteenContracts/ViewModels/TablewareViewModel.cs @@ -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; } } diff --git a/Canteen/CanteenDataModels/Models/ITablewareModel.cs b/Canteen/CanteenDataModels/Models/ITablewareModel.cs index 4f5f200..4adc942 100644 --- a/Canteen/CanteenDataModels/Models/ITablewareModel.cs +++ b/Canteen/CanteenDataModels/Models/ITablewareModel.cs @@ -10,5 +10,6 @@ namespace CanteenDataModels.Models { int VisitorId { get; } string TablewareName { get; } + int Count { get; } } } diff --git a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs index ef67be6..278110b 100644 --- a/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs +++ b/Canteen/CanteenDatabaseImplement/CanteenDatabase.cs @@ -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); } diff --git a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs index aa3b507..96b52b1 100644 --- a/Canteen/CanteenDatabaseImplement/Models/Tableware.cs +++ b/Canteen/CanteenDatabaseImplement/Models/Tableware.cs @@ -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 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 }; } diff --git a/Canteen/CanteenRestApi/Controllers/MainController.cs b/Canteen/CanteenRestApi/Controllers/MainController.cs index 33d08d3..29317e1 100644 --- a/Canteen/CanteenRestApi/Controllers/MainController.cs +++ b/Canteen/CanteenRestApi/Controllers/MainController.cs @@ -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 logger, ICookLogic cook, IDishLogic dish, IProductLogic product) + public MainController(ILogger 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? 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; + } + } } } \ No newline at end of file diff --git a/Canteen/CanteenRestApi/Program.cs b/Canteen/CanteenRestApi/Program.cs index 36c3d9a..115a7d2 100644 --- a/Canteen/CanteenRestApi/Program.cs +++ b/Canteen/CanteenRestApi/Program.cs @@ -14,11 +14,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/Canteen/CanteenVisitorApp/APIClient.cs b/Canteen/CanteenVisitorApp/APIClient.cs index b288086..4ba006b 100644 --- a/Canteen/CanteenVisitorApp/APIClient.cs +++ b/Canteen/CanteenVisitorApp/APIClient.cs @@ -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(string requestUrl) { var response = _client.GetAsync(requestUrl); @@ -31,7 +28,6 @@ namespace CanteenVisitorApp throw new Exception(result); } } - public static void PostRequest(string requestUrl, T model) { var json = JsonConvert.SerializeObject(model); diff --git a/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj b/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj index 7e21bbb..7887e5a 100644 --- a/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj +++ b/Canteen/CanteenVisitorApp/CanteenVisitorApp.csproj @@ -17,4 +17,10 @@ + + + PreserveNewest + + + diff --git a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs index c6bc940..efd2193 100644 --- a/Canteen/CanteenVisitorApp/Controllers/HomeController.cs +++ b/Canteen/CanteenVisitorApp/Controllers/HomeController.cs @@ -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>("api/main/getcooklist"); + ViewBag.Cooks = APIClient.GetRequest>("api/main/getcooklist"); ViewBag.Lunches = new List(); return View(); } @@ -35,7 +36,7 @@ namespace CanteenVisitorApp.Controllers [HttpGet] public IActionResult Tablewares() { - ViewBag.Tablewares = new List(); + ViewBag.Tablewares = APIClient.GetRequest>("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() { diff --git a/Canteen/CanteenVisitorApp/Program.cs b/Canteen/CanteenVisitorApp/Program.cs index 0727468..ddb34e8 100644 --- a/Canteen/CanteenVisitorApp/Program.cs +++ b/Canteen/CanteenVisitorApp/Program.cs @@ -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()) diff --git a/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml b/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml index 20c0a84..f0feca5 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/CreateTableware.cshtml @@ -14,7 +14,13 @@
Название прибора:
- + +
+
+
+
Количество:
+
+
diff --git a/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml b/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml index 0bd701a..7aba725 100644 --- a/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml +++ b/Canteen/CanteenVisitorApp/Views/Home/Tablewares.cshtml @@ -18,11 +18,11 @@ @foreach (var cook in ViewBag.Tablewares) { - - @cook.Id - @cook.VisitorId - @cook.TablewareName - + + @cook.Id + @cook.VisitorId + @cook.TablewareName + }