Enter fix
This commit is contained in:
parent
9d0bccb2f8
commit
6048105937
@ -1,9 +1,9 @@
|
|||||||
using DinerContracts.ViewModels;
|
using Azure.Core;
|
||||||
|
using DinerContracts.ViewModels;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace DinerClientApp {
|
namespace DinerClientApp {
|
||||||
public class APIClient {
|
public class APIClient {
|
||||||
@ -11,16 +11,16 @@ namespace DinerClientApp {
|
|||||||
|
|
||||||
public static ClientViewModel? Client { get; set; } = null;
|
public static ClientViewModel? Client { get; set; } = null;
|
||||||
|
|
||||||
public static void Connetc(IConfiguration configuration) {
|
public static void Connect(IConfiguration configuration) {
|
||||||
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||||
_client.DefaultRequestHeaders.Accept.Clear();
|
_client.DefaultRequestHeaders.Accept.Clear();
|
||||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static T? GetRequest<T>(string requsetUrl) {
|
public static T? GetRequest<T>(string requestUrl) {
|
||||||
var responce = _client.GetAsync(requsetUrl);
|
var response = _client.GetAsync(requestUrl);
|
||||||
var result = responce.Result.Content.ReadAsStringAsync().Result;
|
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||||
if (responce.Result.IsSuccessStatusCode) {
|
if (response.Result.IsSuccessStatusCode) {
|
||||||
return JsonConvert.DeserializeObject<T>(result);
|
return JsonConvert.DeserializeObject<T>(result);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -28,11 +28,11 @@ namespace DinerClientApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void PostRequset<T>(string requsetUrl, T model) {
|
public static void PostRequset<T>(string requestUrl, T model) {
|
||||||
var json = JsonConvert.SerializeObject(model);
|
var json = JsonConvert.SerializeObject(model);
|
||||||
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
var data = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
var response = _client.PostAsync(requsetUrl, data);
|
var response = _client.PostAsync(requestUrl, data);
|
||||||
|
|
||||||
var result = response.Result.Content.ReadAsStringAsync().Result;
|
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||||
if (!response.Result.IsSuccessStatusCode) {
|
if (!response.Result.IsSuccessStatusCode) {
|
||||||
|
@ -105,7 +105,7 @@ namespace DinerClientApp.Controllers {
|
|||||||
}
|
}
|
||||||
APIClient.PostRequset("api/main/createorder", new OrderBindingModel {
|
APIClient.PostRequset("api/main/createorder", new OrderBindingModel {
|
||||||
ClientID = APIClient.Client.ID,
|
ClientID = APIClient.Client.ID,
|
||||||
ProductID = product,
|
SnackID = product,
|
||||||
Count = count,
|
Count = count,
|
||||||
Sum = Cal(count, product)
|
Sum = Cal(count, product)
|
||||||
});
|
});
|
||||||
@ -113,7 +113,7 @@ namespace DinerClientApp.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double Cal(int count, int product) {
|
private double Cal(int count, int product) {
|
||||||
var prod = APIClient.GetRequest<SnackViewModel>($"api/main/getproduct?productID={product}");
|
var prod = APIClient.GetRequest<SnackViewModel>($"api/main/getproduct?productId={product}");
|
||||||
return count * (prod?.Price ?? 1);
|
return count * (prod?.Price ?? 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\DinerContracts\DinerContracts.csproj" />
|
<ProjectReference Include="..\DinerContracts\DinerContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\DinerDataBaseImplement\DinerDataBaseImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\DinerRestAPI\DinerRestApi.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -7,7 +7,7 @@ namespace DinerClientApp {
|
|||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
APIClient.Connect(builder.Configuration);
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment()) {
|
if (!app.Environment.IsDevelopment()) {
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
@ -24,7 +24,7 @@ namespace DinerClientApp {
|
|||||||
|
|
||||||
app.MapControllerRoute(
|
app.MapControllerRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
pattern: "{controller=Home}/{action=Index}/{Id?}");
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"IPAddress": "http://localhost:7254/"
|
"IPAddress": "http://localhost:5023/"
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ namespace DinerContracts.BindingModels
|
|||||||
{
|
{
|
||||||
public class OrderBindingModel : IOrderModel
|
public class OrderBindingModel : IOrderModel
|
||||||
{
|
{
|
||||||
public int ProductID { get; set; }
|
public int SnackID { get; set; }
|
||||||
|
|
||||||
public int ClientID { get; set; }
|
public int ClientID { get; set; }
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ namespace DinerContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? ID { get; set; }
|
public int? ID { get; set; }
|
||||||
public DateTime? DateFrom { get; set; }
|
public DateTime? DateFrom { get; set; }
|
||||||
|
public int? ClientID { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime? DateTo { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ namespace DinerContracts.ViewModels
|
|||||||
{
|
{
|
||||||
public class OrderViewModel : IOrderModel
|
public class OrderViewModel : IOrderModel
|
||||||
{
|
{
|
||||||
public int ProductID { get; set; }
|
public int SnackID { get; set; }
|
||||||
|
|
||||||
[DisplayName("Количество")]
|
[DisplayName("Количество")]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
@ -3,6 +3,7 @@ using DinerContracts.SearchModels;
|
|||||||
using DinerContracts.StoragesContracts;
|
using DinerContracts.StoragesContracts;
|
||||||
using DinerContracts.ViewModels;
|
using DinerContracts.ViewModels;
|
||||||
using DinerDataBaseImplement.Models;
|
using DinerDataBaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -46,13 +47,20 @@ namespace DinerDataBaseImplement.Implements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ClientViewModel? GetElement(ClientSearchModel model) {
|
public ClientViewModel? GetElement(ClientSearchModel model) {
|
||||||
if (string.IsNullOrEmpty(model.ClientFIO) && !model.ID.HasValue) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new DinerDataBase();
|
using var context = new DinerDataBase();
|
||||||
return context.Clients.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ClientFIO) &&
|
if (model.ID.HasValue) {
|
||||||
x.ClientFIO == model.ClientFIO) || model.ID.HasValue &&
|
return context.Clients
|
||||||
x.ID == model.ID)?.GetViewModel;
|
.Include(x => x.Orders)
|
||||||
|
.FirstOrDefault(x => model.ID.HasValue && x.ID == model.ID)
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
else if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password)) {
|
||||||
|
return context.Clients
|
||||||
|
.Include(x => x.Orders)
|
||||||
|
.FirstOrDefault(x => (x.Email == model.Email && x.Password == model.Password))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
return new();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) {
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel model) {
|
||||||
|
@ -82,7 +82,7 @@ namespace DinerDataBaseImplement.Implements
|
|||||||
using var context = new DinerDataBase();
|
using var context = new DinerDataBase();
|
||||||
var viewModel = order.GetViewModel;
|
var viewModel = order.GetViewModel;
|
||||||
foreach (var pr in context.Products) {
|
foreach (var pr in context.Products) {
|
||||||
if (pr.ID == order.ProductID) {
|
if (pr.ID == order.SnackID) {
|
||||||
viewModel.ProductName = pr.ProductName;
|
viewModel.ProductName = pr.ProductName;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|||||||
namespace DinerDataBaseImplement.Migrations
|
namespace DinerDataBaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(DinerDataBase))]
|
[DbContext(typeof(DinerDataBase))]
|
||||||
[Migration("20240501160144_InitMigration")]
|
[Migration("20240502170545_InitMigration")]
|
||||||
partial class InitMigration
|
partial class InitMigration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -90,10 +90,7 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
b.Property<DateTime?>("DateImplement")
|
b.Property<DateTime?>("DateImplement")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
b.Property<int>("ProductID")
|
b.Property<int>("SnackID")
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int?>("SnackID")
|
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
@ -145,14 +142,14 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
b.Property<int>("Count")
|
b.Property<int>("Count")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("ProductID")
|
b.Property<int>("SnackID")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("ID");
|
b.HasKey("ID");
|
||||||
|
|
||||||
b.HasIndex("ComponentID");
|
b.HasIndex("ComponentID");
|
||||||
|
|
||||||
b.HasIndex("ProductID");
|
b.HasIndex("SnackID");
|
||||||
|
|
||||||
b.ToTable("ProductComponents");
|
b.ToTable("ProductComponents");
|
||||||
});
|
});
|
||||||
@ -165,7 +162,9 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
|
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("SnackID");
|
.HasForeignKey("SnackID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Snack");
|
b.Navigation("Snack");
|
||||||
});
|
});
|
||||||
@ -180,7 +179,7 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasOne("DinerDataBaseImplement.Models.Snack", "Product")
|
b.HasOne("DinerDataBaseImplement.Models.Snack", "Product")
|
||||||
.WithMany("Components")
|
.WithMany("Components")
|
||||||
.HasForeignKey("ProductID")
|
.HasForeignKey("SnackID")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
@ -60,13 +60,12 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
ID = table.Column<int>(type: "int", nullable: false)
|
ID = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
ProductID = table.Column<int>(type: "int", nullable: false),
|
SnackID = table.Column<int>(type: "int", nullable: false),
|
||||||
Count = table.Column<int>(type: "int", nullable: false),
|
Count = table.Column<int>(type: "int", nullable: false),
|
||||||
Sum = table.Column<double>(type: "float", nullable: false),
|
Sum = table.Column<double>(type: "float", nullable: false),
|
||||||
Status = table.Column<int>(type: "int", nullable: false),
|
Status = table.Column<int>(type: "int", nullable: false),
|
||||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true),
|
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||||
SnackID = table.Column<int>(type: "int", nullable: true),
|
|
||||||
ClientID = table.Column<int>(type: "int", nullable: true)
|
ClientID = table.Column<int>(type: "int", nullable: true)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
@ -81,7 +80,8 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
name: "FK_Orders_Products_SnackID",
|
name: "FK_Orders_Products_SnackID",
|
||||||
column: x => x.SnackID,
|
column: x => x.SnackID,
|
||||||
principalTable: "Products",
|
principalTable: "Products",
|
||||||
principalColumn: "ID");
|
principalColumn: "ID",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
@ -90,7 +90,7 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
{
|
{
|
||||||
ID = table.Column<int>(type: "int", nullable: false)
|
ID = table.Column<int>(type: "int", nullable: false)
|
||||||
.Annotation("SqlServer:Identity", "1, 1"),
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
ProductID = table.Column<int>(type: "int", nullable: false),
|
SnackID = table.Column<int>(type: "int", nullable: false),
|
||||||
ComponentID = table.Column<int>(type: "int", nullable: false),
|
ComponentID = table.Column<int>(type: "int", nullable: false),
|
||||||
Count = table.Column<int>(type: "int", nullable: false)
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
},
|
},
|
||||||
@ -104,8 +104,8 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
principalColumn: "ID",
|
principalColumn: "ID",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "FK_ProductComponents_Products_ProductID",
|
name: "FK_ProductComponents_Products_SnackID",
|
||||||
column: x => x.ProductID,
|
column: x => x.SnackID,
|
||||||
principalTable: "Products",
|
principalTable: "Products",
|
||||||
principalColumn: "ID",
|
principalColumn: "ID",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
@ -127,9 +127,9 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
column: "ComponentID");
|
column: "ComponentID");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
migrationBuilder.CreateIndex(
|
||||||
name: "IX_ProductComponents_ProductID",
|
name: "IX_ProductComponents_SnackID",
|
||||||
table: "ProductComponents",
|
table: "ProductComponents",
|
||||||
column: "ProductID");
|
column: "SnackID");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
@ -87,10 +87,7 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
b.Property<DateTime?>("DateImplement")
|
b.Property<DateTime?>("DateImplement")
|
||||||
.HasColumnType("datetime2");
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
b.Property<int>("ProductID")
|
b.Property<int>("SnackID")
|
||||||
.HasColumnType("int");
|
|
||||||
|
|
||||||
b.Property<int?>("SnackID")
|
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("Status")
|
b.Property<int>("Status")
|
||||||
@ -142,14 +139,14 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
b.Property<int>("Count")
|
b.Property<int>("Count")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.Property<int>("ProductID")
|
b.Property<int>("SnackID")
|
||||||
.HasColumnType("int");
|
.HasColumnType("int");
|
||||||
|
|
||||||
b.HasKey("ID");
|
b.HasKey("ID");
|
||||||
|
|
||||||
b.HasIndex("ComponentID");
|
b.HasIndex("ComponentID");
|
||||||
|
|
||||||
b.HasIndex("ProductID");
|
b.HasIndex("SnackID");
|
||||||
|
|
||||||
b.ToTable("ProductComponents", (string)null);
|
b.ToTable("ProductComponents", (string)null);
|
||||||
});
|
});
|
||||||
@ -162,7 +159,9 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
|
b.HasOne("DinerDataBaseImplement.Models.Snack", "Snack")
|
||||||
.WithMany()
|
.WithMany()
|
||||||
.HasForeignKey("SnackID");
|
.HasForeignKey("SnackID")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Snack");
|
b.Navigation("Snack");
|
||||||
});
|
});
|
||||||
@ -177,7 +176,7 @@ namespace DinerDataBaseImplement.Migrations
|
|||||||
|
|
||||||
b.HasOne("DinerDataBaseImplement.Models.Snack", "Product")
|
b.HasOne("DinerDataBaseImplement.Models.Snack", "Product")
|
||||||
.WithMany("Components")
|
.WithMany("Components")
|
||||||
.HasForeignKey("ProductID")
|
.HasForeignKey("SnackID")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired();
|
.IsRequired();
|
||||||
|
|
||||||
|
@ -39,6 +39,15 @@ namespace DinerDataBaseImplement.Models {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Client Create(ClientViewModel model) {
|
||||||
|
return new Client {
|
||||||
|
ID = model.ID,
|
||||||
|
ClientFIO = model.ClientFIO,
|
||||||
|
Email = model.Email,
|
||||||
|
Password = model.Password
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public void Update(ClientBindingModel? model) {
|
public void Update(ClientBindingModel? model) {
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
return;
|
return;
|
||||||
|
@ -11,7 +11,7 @@ namespace DinerDataBaseImplement.Models
|
|||||||
public class Order : IOrderModel
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public int ProductID { get; set; }
|
public int SnackID { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
@ -37,7 +37,7 @@ namespace DinerDataBaseImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
ID = model.ID,
|
ID = model.ID,
|
||||||
ProductID = model.ProductID,
|
SnackID = model.SnackID,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -54,7 +54,7 @@ namespace DinerDataBaseImplement.Models
|
|||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
ID = ID,
|
ID = ID,
|
||||||
ProductID = ProductID,
|
SnackID = SnackID,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
@ -17,12 +17,12 @@ namespace DinerDataBaseImplement.Models
|
|||||||
public class Snack : ISnackModel
|
public class Snack : ISnackModel
|
||||||
{
|
{
|
||||||
[Required]
|
[Required]
|
||||||
public string ProductName { get; private set; } = string.Empty;
|
public string ProductName { get; set; } = string.Empty;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public double Price { get; private set; }
|
public double Price { get; set; }
|
||||||
|
|
||||||
public int ID { get; private set; }
|
public int ID { get; set; }
|
||||||
|
|
||||||
private Dictionary<int, (IFoodModel, int)>? _productComponents = null;
|
private Dictionary<int, (IFoodModel, int)>? _productComponents = null;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ namespace DinerDataBaseImplement.Models
|
|||||||
return _productComponents;
|
return _productComponents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[ForeignKey("ProductID")]
|
[ForeignKey("SnackID")]
|
||||||
public virtual List<SnackFood> Components { get; set; } = new();
|
public virtual List<SnackFood> Components { get; set; } = new();
|
||||||
public static Snack? Create(DinerDataBase context,SnackBindingModel model)
|
public static Snack? Create(DinerDataBase context,SnackBindingModel model)
|
||||||
{
|
{
|
||||||
@ -70,7 +70,7 @@ namespace DinerDataBaseImplement.Models
|
|||||||
};
|
};
|
||||||
|
|
||||||
public void UpdateComponents(DinerDataBase context, SnackBindingModel model) {
|
public void UpdateComponents(DinerDataBase context, SnackBindingModel model) {
|
||||||
var productComponents = context.ProductComponents.Where(rec => rec.ProductID == model.ID).ToList();
|
var productComponents = context.ProductComponents.Where(rec => rec.SnackID == model.ID).ToList();
|
||||||
if (ProductComponents != null && ProductComponents.Count > 0) {
|
if (ProductComponents != null && ProductComponents.Count > 0) {
|
||||||
context.ProductComponents.RemoveRange(productComponents.Where(rec => !model.ProductComponents.ContainsKey(rec.ComponentID)));
|
context.ProductComponents.RemoveRange(productComponents.Where(rec => !model.ProductComponents.ContainsKey(rec.ComponentID)));
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
@ -7,7 +7,7 @@ namespace DinerDataBaseImplement.Models
|
|||||||
public int ID { get; set; }
|
public int ID { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int ProductID { get; set; }
|
public int SnackID { get; set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int ComponentID { get; set; }
|
public int ComponentID { get; set; }
|
||||||
|
@ -9,7 +9,7 @@ namespace DinerDataModels.Models
|
|||||||
{
|
{
|
||||||
public interface IOrderModel : IID
|
public interface IOrderModel : IID
|
||||||
{
|
{
|
||||||
int ProductID { get; }
|
int SnackID { get; }
|
||||||
int Count { get; }
|
int Count { get; }
|
||||||
double Sum { get; }
|
double Sum { get; }
|
||||||
OrderStatus Status { get; }
|
OrderStatus Status { get; }
|
||||||
|
@ -67,7 +67,7 @@ namespace DinerListImplement.Implements
|
|||||||
var viewModel = order.GetViewModel;
|
var viewModel = order.GetViewModel;
|
||||||
foreach (var product in _source.Snacks)
|
foreach (var product in _source.Snacks)
|
||||||
{
|
{
|
||||||
if (product.ID == order.ProductID)
|
if (product.ID == order.SnackID)
|
||||||
{
|
{
|
||||||
viewModel.ProductName = product.ProductName;
|
viewModel.ProductName = product.ProductName;
|
||||||
break;
|
break;
|
||||||
|
@ -12,7 +12,7 @@ namespace DinerListImplement.Models
|
|||||||
{
|
{
|
||||||
internal class Order : IOrderModel
|
internal class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int ProductID { get; private set; }
|
public int SnackID { get; private set; }
|
||||||
|
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ namespace DinerListImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
ID = model.ID,
|
ID = model.ID,
|
||||||
ProductID = model.ProductID,
|
SnackID = model.SnackID,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -47,7 +47,7 @@ namespace DinerListImplement.Models
|
|||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
ID = ID,
|
ID = ID,
|
||||||
ProductID = ProductID,
|
SnackID = SnackID,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
|
@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
|||||||
|
|
||||||
namespace DinerRestApi.Controllers {
|
namespace DinerRestApi.Controllers {
|
||||||
|
|
||||||
[Route("Api/[controller]/[action]")]
|
[Route("api/[controller]/[action]")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
|
||||||
public class ClientController : Controller {
|
public class ClientController : Controller {
|
||||||
@ -20,7 +20,6 @@ namespace DinerRestApi.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|
||||||
public ClientViewModel? Login(string login, string password) {
|
public ClientViewModel? Login(string login, string password) {
|
||||||
try {
|
try {
|
||||||
return _logic.ReadELement(new ClientSearchModel {
|
return _logic.ReadELement(new ClientSearchModel {
|
||||||
|
@ -31,12 +31,12 @@ namespace DinerRestApi.Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public SnackViewModel? GetProduct(int ProductID) {
|
public SnackViewModel? GetProduct(int SnackID) {
|
||||||
try {
|
try {
|
||||||
return _product.ReadElement(new SnackSearchModel { ID = ProductID });
|
return _product.ReadElement(new SnackSearchModel { ID = SnackID });
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
_logger.LogError(ex, $"Ошибка получения продуктапо ID={ProductID}");
|
_logger.LogError(ex, $"Ошибка получения продуктапо ID={SnackID}");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ namespace DinerRestApi.Controllers {
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<OrderViewModel>? GetOrders(int ClientID) {
|
public List<OrderViewModel>? GetOrders(int ClientID) {
|
||||||
try {
|
try {
|
||||||
return _order.ReadList(new OrderSearchModel { ID = ClientID });
|
return _order.ReadList(new OrderSearchModel { ClientID = ClientID });
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
_logger.LogError(ex, $"Ошибка получения списка закаозов клиента ID={ClientID}");
|
_logger.LogError(ex, $"Ошибка получения списка закаозов клиента ID={ClientID}");
|
||||||
|
@ -32,9 +32,9 @@ namespace DinerRestAPI {
|
|||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment()) {
|
if(app.Environment.IsDevelopment()) {
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI(x => x.SwaggerEndpoint("/swagger/v1/swagger.json", "DinerRestApi v1"));
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "DinerRestApi v1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
@ -54,7 +54,7 @@ namespace DinerFileImplement.Implements
|
|||||||
{
|
{
|
||||||
var viewModel = order.GetViewModel;
|
var viewModel = order.GetViewModel;
|
||||||
var tmp = from p in _source.Snacks
|
var tmp = from p in _source.Snacks
|
||||||
where p.ID == order.ProductID
|
where p.ID == order.SnackID
|
||||||
select p.ProductName;
|
select p.ProductName;
|
||||||
viewModel.ProductName = tmp.FirstOrDefault(string.Empty);
|
viewModel.ProductName = tmp.FirstOrDefault(string.Empty);
|
||||||
return viewModel;
|
return viewModel;
|
||||||
|
@ -13,7 +13,7 @@ namespace DinerFileImplement.Models
|
|||||||
{
|
{
|
||||||
internal class Order : IOrderModel
|
internal class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int ProductID { get; private set; }
|
public int SnackID { get; private set; }
|
||||||
|
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ namespace DinerFileImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
ID = model.ID,
|
ID = model.ID,
|
||||||
ProductID = model.ProductID,
|
SnackID = model.SnackID,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -47,7 +47,7 @@ namespace DinerFileImplement.Models
|
|||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
|
ID = Convert.ToInt32(element.Attribute("ID")!.Value),
|
||||||
ProductID = Convert.ToInt32(element.Element("ProductID")!.Value),
|
SnackID = Convert.ToInt32(element.Element("SnackID")!.Value),
|
||||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||||
@ -65,7 +65,7 @@ namespace DinerFileImplement.Models
|
|||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
ID = ID,
|
ID = ID,
|
||||||
ProductID = ProductID,
|
SnackID = SnackID,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
@ -73,7 +73,7 @@ namespace DinerFileImplement.Models
|
|||||||
DateImplement = DateImplement,
|
DateImplement = DateImplement,
|
||||||
};
|
};
|
||||||
public XElement GetXElement => new("Order", new XAttribute("ID", ID),
|
public XElement GetXElement => new("Order", new XAttribute("ID", ID),
|
||||||
new XElement("ProductID", ProductID),
|
new XElement("SnackID", SnackID),
|
||||||
new XElement("Count", Count.ToString()),
|
new XElement("Count", Count.ToString()),
|
||||||
new XElement("Sum", Sum.ToString()),
|
new XElement("Sum", Sum.ToString()),
|
||||||
new XElement("Status", Status.ToString()),
|
new XElement("Status", Status.ToString()),
|
||||||
|
@ -77,7 +77,7 @@ namespace DinerView
|
|||||||
{
|
{
|
||||||
var operationResult = _logicOrder.CreateOrder(new OrderBindingModel
|
var operationResult = _logicOrder.CreateOrder(new OrderBindingModel
|
||||||
{
|
{
|
||||||
ProductID = Convert.ToInt32(comboBoxProduct.SelectedValue),
|
SnackID = Convert.ToInt32(comboBoxProduct.SelectedValue),
|
||||||
Count = Convert.ToInt32(textBoxCount.Text),
|
Count = Convert.ToInt32(textBoxCount.Text),
|
||||||
Sum = Convert.ToDouble(textBoxSum.Text),
|
Sum = Convert.ToDouble(textBoxSum.Text),
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ namespace DinerView
|
|||||||
var list = _orderLogic.ReadList(null);
|
var list = _orderLogic.ReadList(null);
|
||||||
if (list != null) {
|
if (list != null) {
|
||||||
dataGridView.DataSource = list;
|
dataGridView.DataSource = list;
|
||||||
dataGridView.Columns["ProductID"].Visible = false;
|
dataGridView.Columns["SnackID"].Visible = false;
|
||||||
dataGridView.Columns["Sum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
dataGridView.Columns["Sum"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Загрузка заказов");
|
_logger.LogInformation("Загрузка заказов");
|
||||||
|
@ -66,7 +66,7 @@ namespace DineryBusinessLogic.BusinessLogic {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<ClientViewModel>? ReadList(ClientSearchModel? model) {
|
public List<ClientViewModel>? ReadList(ClientSearchModel? model) {
|
||||||
_logger.LogInformation($"ReadList. CLiendID:{model?.ID}");
|
_logger.LogInformation($"ReadList. CLientID:{model?.ID}");
|
||||||
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
|
var list = model == null ? _storage.GetFullList() : _storage.GetFilteredList(model);
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
_logger.LogWarning("ReadList. return nell list");
|
_logger.LogWarning("ReadList. return nell list");
|
||||||
|
@ -69,9 +69,9 @@ namespace DineryBusinessLogic.BusinessLogic
|
|||||||
throw new ArgumentNullException("Нет ID заказа", nameof(model.ID));
|
throw new ArgumentNullException("Нет ID заказа", nameof(model.ID));
|
||||||
if (model.Sum <= 0)
|
if (model.Sum <= 0)
|
||||||
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||||
_logger.LogInformation("Order. ProductID:{ProductID}. Count:{Count}. Sum:{Sum}. Status:{Status}. " +
|
_logger.LogInformation("Order. SnackID:{SnackID}. Count:{Count}. Sum:{Sum}. Status:{Status}. " +
|
||||||
"DateCreate:{DateCreate}. DateImplement:{DateImplement}. ID:{ID}",
|
"DateCreate:{DateCreate}. DateImplement:{DateImplement}. ID:{ID}",
|
||||||
model.ProductID, model.Count, model.Sum, model.Status, model.DateCreate, model.DateImplement, model.ID);
|
model.SnackID, model.Count, model.Sum, model.Status, model.DateCreate, model.DateImplement, model.ID);
|
||||||
}
|
}
|
||||||
private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) {
|
private bool StatusUpdate(OrderBindingModel model, OrderStatus newOrderStatus) {
|
||||||
CheckModel(model, false);
|
CheckModel(model, false);
|
||||||
|
@ -38,15 +38,19 @@ namespace DineryBusinessLogic.OfficePackage.Implements
|
|||||||
fontTittle.Append(new FontName() { Val = "Times New Roman" });
|
fontTittle.Append(new FontName() { Val = "Times New Roman" });
|
||||||
fontTittle.Append(new FontFamilyNumbering() { Val = 2 });
|
fontTittle.Append(new FontFamilyNumbering() { Val = 2 });
|
||||||
fontTittle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
fontTittle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
|
||||||
|
|
||||||
fonts.Append(fontUsual);
|
fonts.Append(fontUsual);
|
||||||
fonts.Append(fontTittle);
|
fonts.Append(fontTittle);
|
||||||
|
|
||||||
var fills = new Fills() { Count = 2U };
|
var fills = new Fills() { Count = 2U };
|
||||||
var fill1 = new Fill();
|
var fill1 = new Fill();
|
||||||
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
|
||||||
var fill2 = new Fill();
|
var fill2 = new Fill();
|
||||||
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
|
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
|
||||||
|
|
||||||
fills.Append(fill1);
|
fills.Append(fill1);
|
||||||
fills.Append(fill2);
|
fills.Append(fill2);
|
||||||
|
|
||||||
var borders = new Borders() { Count = 2U };
|
var borders = new Borders() { Count = 2U };
|
||||||
var borderNoBorder = new Border();
|
var borderNoBorder = new Border();
|
||||||
borderNoBorder.Append(new LeftBorder());
|
borderNoBorder.Append(new LeftBorder());
|
||||||
@ -55,6 +59,7 @@ namespace DineryBusinessLogic.OfficePackage.Implements
|
|||||||
borderNoBorder.Append(new BottomBorder());
|
borderNoBorder.Append(new BottomBorder());
|
||||||
borderNoBorder.Append(new DiagonalBorder());
|
borderNoBorder.Append(new DiagonalBorder());
|
||||||
var borderThin = new Border();
|
var borderThin = new Border();
|
||||||
|
|
||||||
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
|
||||||
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||||
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
|
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
|
||||||
@ -63,6 +68,7 @@ namespace DineryBusinessLogic.OfficePackage.Implements
|
|||||||
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||||
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
|
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
|
||||||
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
|
||||||
|
|
||||||
borderThin.Append(leftBorder);
|
borderThin.Append(leftBorder);
|
||||||
borderThin.Append(rightBorder);
|
borderThin.Append(rightBorder);
|
||||||
borderThin.Append(topBorder);
|
borderThin.Append(topBorder);
|
||||||
@ -70,6 +76,7 @@ namespace DineryBusinessLogic.OfficePackage.Implements
|
|||||||
borderThin.Append(new DiagonalBorder());
|
borderThin.Append(new DiagonalBorder());
|
||||||
borders.Append(borderNoBorder);
|
borders.Append(borderNoBorder);
|
||||||
borders.Append(borderThin);
|
borders.Append(borderThin);
|
||||||
|
|
||||||
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
|
||||||
var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U };
|
var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U };
|
||||||
cellStyleFormats.Append(cellFormatStyle);
|
cellStyleFormats.Append(cellFormatStyle);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user