Добавление клиента в хранилища + изменения в заказах + API
This commit is contained in:
parent
3f9906b299
commit
be604f06f3
@ -13,9 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "Pi
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaView", "PizzeriaView\PizzeriaView.csproj", "{25FCC09C-88AE-4515-9235-FB9C17972034}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaFileImplement", "PizzeriaFileImplement\PizzeriaFileImplement.csproj", "{BD6EEE24-695A-42BF-BE1C-B4058218A8D9}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "PizzeriaFileImplement\PizzeriaFileImplement.csproj", "{BD6EEE24-695A-42BF-BE1C-B4058218A8D9}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{4CCDEA60-47C3-478E-AE8C-146A8583BAF7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{4CCDEA60-47C3-478E-AE8C-146A8583BAF7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaRestApi", "PizzeriaRestApi\PizzeriaRestApi.csproj", "{58517590-C346-42C0-B669-EA2C90D54A8B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -51,6 +53,10 @@ Global
|
||||
{4CCDEA60-47C3-478E-AE8C-146A8583BAF7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4CCDEA60-47C3-478E-AE8C-146A8583BAF7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4CCDEA60-47C3-478E-AE8C-146A8583BAF7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{58517590-C346-42C0-B669-EA2C90D54A8B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{58517590-C346-42C0-B669-EA2C90D54A8B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{58517590-C346-42C0-B669-EA2C90D54A8B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{58517590-C346-42C0-B669-EA2C90D54A8B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
123
Pizzeria/PizzeriaBusinessLogic/ClientLogic.cs
Normal file
123
Pizzeria/PizzeriaBusinessLogic/ClientLogic.cs
Normal file
@ -0,0 +1,123 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaBusinessLogic
|
||||
{
|
||||
public class ClientLogic : IClientLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
|
||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_clientStorage = clientStorage;
|
||||
}
|
||||
|
||||
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. Id: {Id}. ClientFIO: {ClientFIO}. Email: {Email}.",
|
||||
model?.Id, model?.ClientFIO, model?.Email);
|
||||
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. Id: {Id}. ClientFIO: {ClientFIO}. Email: {Email}.",
|
||||
model?.Id, model?.ClientFIO, model?.Email);
|
||||
var element = _clientStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
|
||||
public bool Create(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Update(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_clientStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Delete(ClientBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
||||
if (_clientStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void CheckModel(ClientBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ClientFIO))
|
||||
{
|
||||
throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
throw new ArgumentNullException("Нет логина клиента", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Client. Id: {Id}. ClientFIO: {ClientFIO}. Email: {Email}.",
|
||||
model?.Id, model?.ClientFIO, model?.Email);
|
||||
var element = _clientStorage.GetElement(new ClientSearchModel { Email = model.Email });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Клиент с таким логином уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using PizzeriaDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaContracts.BindingModels
|
||||
{
|
||||
public class ClientBindingModel : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ namespace PizzeriaContracts.BindingModels
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
public int PizzaId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
|
@ -0,0 +1,21 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IClientLogic
|
||||
{
|
||||
List<ClientViewModel>? ReadList(ClientSearchModel? model);
|
||||
ClientViewModel? ReadElement(ClientSearchModel model);
|
||||
bool Create(ClientBindingModel model);
|
||||
bool Update(ClientBindingModel model);
|
||||
bool Delete(ClientBindingModel model);
|
||||
}
|
||||
|
||||
}
|
19
Pizzeria/PizzeriaContracts/SearchModels/ClientSearchModel.cs
Normal file
19
Pizzeria/PizzeriaContracts/SearchModels/ClientSearchModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaContracts.SearchModels
|
||||
{
|
||||
public class ClientSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
|
||||
public string? ClientFIO { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? Password { get; set; }
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ namespace PizzeriaContracts.SearchModels
|
||||
public class OrderSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? ClientId { get; set; }
|
||||
public DateTime? DateFrom { get; set; }
|
||||
public DateTime? DateTo { get; set; }
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaContracts.StorageContracts
|
||||
{
|
||||
public interface IClientStorage
|
||||
{
|
||||
List<ClientViewModel> GetFullList();
|
||||
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
|
||||
ClientViewModel? GetElement(ClientSearchModel model);
|
||||
ClientViewModel? Insert(ClientBindingModel model);
|
||||
ClientViewModel? Update(ClientBindingModel model);
|
||||
ClientViewModel? Delete(ClientBindingModel model);
|
||||
}
|
||||
|
||||
}
|
22
Pizzeria/PizzeriaContracts/ViewModels/ClientViewModel.cs
Normal file
22
Pizzeria/PizzeriaContracts/ViewModels/ClientViewModel.cs
Normal file
@ -0,0 +1,22 @@
|
||||
using PizzeriaDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaContracts.ViewModels
|
||||
{
|
||||
public class ClientViewModel : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
[DisplayName("Логин (эл. почта)")]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
[DisplayName("Пароль")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
}
|
@ -12,6 +12,10 @@ namespace PizzeriaContracts.ViewModels
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int PizzaId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string PizzaName { get; set; } = string.Empty;
|
||||
|
17
Pizzeria/PizzeriaDataModels/Models/IClientModel.cs
Normal file
17
Pizzeria/PizzeriaDataModels/Models/IClientModel.cs
Normal file
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaDataModels.Models
|
||||
{
|
||||
public interface IClientModel : IId
|
||||
{
|
||||
string ClientFIO { get; }
|
||||
|
||||
string Email { get; }
|
||||
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ namespace PizzeriaDataModels
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int ClientId { get; }
|
||||
int PizzaId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
|
@ -0,0 +1,90 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDatabaseImplement.Models;
|
||||
|
||||
namespace PizzeriaDatabaseImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Clients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Clients
|
||||
.Where(x => (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO.Contains(model.ClientFIO)) ||
|
||||
(!string.IsNullOrEmpty(model.Email) && x.ClientFIO.Contains(model.Email)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Clients
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
|
||||
(!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) ||
|
||||
(!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) && x.Email == model.Email && x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
var newClient = Client.Create(model);
|
||||
if (newClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new PizzeriaDatabase();
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
context.SaveChanges();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Clients.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,7 +12,10 @@ namespace PizzeriaDatabaseImplement.Implements
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Orders.Include(x => x.Pizza).Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders.Include(x => x.Pizza)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
@ -22,7 +25,11 @@ namespace PizzeriaDatabaseImplement.Implements
|
||||
return new();
|
||||
}
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Orders.Include(x => x.Pizza).Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => x.GetViewModel).ToList();
|
||||
return context.Orders.Include(x => x.Pizza)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) ||
|
||||
(model.ClientId.HasValue && x.ClientId == model.ClientId))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
@ -32,7 +39,10 @@ namespace PizzeriaDatabaseImplement.Implements
|
||||
return new();
|
||||
}
|
||||
using var context = new PizzeriaDatabase();
|
||||
return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Pizza)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) || (model.ClientId.HasValue && x.Id == model.ClientId))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
|
214
Pizzeria/PizzeriaDatabaseImplement/Migrations/20230513164515_ClientMigration.Designer.cs
generated
Normal file
214
Pizzeria/PizzeriaDatabaseImplement/Migrations/20230513164515_ClientMigration.Designer.cs
generated
Normal file
@ -0,0 +1,214 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using PizzeriaDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PizzeriaDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PizzeriaDatabase))]
|
||||
[Migration("20230513164515_ClientMigration")]
|
||||
partial class ClientMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.4")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("PizzaId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("PizzaId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("PizzaName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Pizzas");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("PizzaId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("PizzaId");
|
||||
|
||||
b.ToTable("PizzaComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("ClientOrders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("PizzaId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Pizza");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("PizzaComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("PizzaId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Pizza");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("ClientOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("PizzaComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PizzeriaDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class ClientMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.Sql("DELETE FROM [dbo].[Orders]");
|
||||
migrationBuilder.AddColumn<int>(
|
||||
name: "ClientId",
|
||||
table: "Orders",
|
||||
type: "int",
|
||||
nullable: false,
|
||||
defaultValue: 0);
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Clients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.AddForeignKey(
|
||||
name: "FK_Orders_Clients_ClientId",
|
||||
table: "Orders",
|
||||
column: "ClientId",
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropForeignKey(
|
||||
name: "FK_Orders_Clients_ClientId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders");
|
||||
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ClientId",
|
||||
table: "Orders");
|
||||
}
|
||||
}
|
||||
}
|
@ -22,6 +22,31 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ClientFIO")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Password")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Clients");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -50,6 +75,9 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ClientId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
@ -70,6 +98,8 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("PizzaId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
@ -123,12 +153,20 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("PizzeriaDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("ClientOrders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("PizzaId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Pizza");
|
||||
});
|
||||
|
||||
@ -151,6 +189,11 @@ namespace PizzeriaDatabaseImplement.Migrations
|
||||
b.Navigation("Pizza");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("ClientOrders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("PizzaComponents");
|
||||
|
64
Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs
Normal file
64
Pizzeria/PizzeriaDatabaseImplement/Models/Client.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaDatabaseImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Order> ClientOrders { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
@ -13,6 +13,10 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
public class Order
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public virtual Client Client { get; set; } = new();
|
||||
|
||||
[Required]
|
||||
public int PizzaId { get; private set; }
|
||||
@ -38,6 +42,8 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientId = model.ClientId,
|
||||
Client = context.Clients.First(x => model.ClientId == x.Id),
|
||||
PizzaId = model.PizzaId,
|
||||
Pizza = context.Pizzas.First(x => x.Id == model.PizzaId),
|
||||
Count = model.Count,
|
||||
@ -61,6 +67,8 @@ namespace PizzeriaDatabaseImplement.Models
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientId = ClientId,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
PizzaId = PizzaId,
|
||||
PizzaName = Pizza.PizzaName,
|
||||
Count = Count,
|
||||
|
@ -14,6 +14,7 @@ namespace PizzeriaDatabaseImplement
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Pizza> Pizzas { set; get; }
|
||||
public virtual DbSet<PizzaComponent> PizzaComponents { set; get; }
|
||||
|
@ -9,9 +9,11 @@ namespace PizzeriaFileImplement
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string PizzaFileName = "Pizza.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Pizza> Pizzas { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
@ -23,11 +25,13 @@ namespace PizzeriaFileImplement
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
|
93
Pizzeria/PizzeriaFileImplement/Implements/ClientStorage.cs
Normal file
93
Pizzeria/PizzeriaFileImplement/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaFileImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public ClientStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
return source.Clients
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Clients
|
||||
.Where(x => (!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO.Contains(model.ClientFIO)) ||
|
||||
(!string.IsNullOrEmpty(model.Email) && x.ClientFIO.Contains(model.Email)))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Clients
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id) ||
|
||||
(!string.IsNullOrEmpty(model.ClientFIO) && x.ClientFIO == model.ClientFIO) ||
|
||||
(!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) && x.Email == model.Email && x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||
var newClient = Client.Create(model);
|
||||
if (newClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Clients.Add(newClient);
|
||||
source.SaveClients();
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (client == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
client.Update(model);
|
||||
source.SaveClients();
|
||||
return client.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
var element = source.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Clients.Remove(element);
|
||||
source.SaveClients();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -13,22 +13,22 @@ namespace PizzeriaFileImplement.Implements
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachPizzaName(x.GetViewModel)).ToList();
|
||||
public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachOthersNames(x.GetViewModel)).ToList();
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
||||
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => AttachPizzaName(x.GetViewModel)).ToList();
|
||||
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo).Select(x => AttachOthersNames(x.GetViewModel)).ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && !model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return AttachPizzaName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
||||
return AttachOthersNames(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
@ -40,7 +40,7 @@ namespace PizzeriaFileImplement.Implements
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return AttachPizzaName(newOrder.GetViewModel);
|
||||
return AttachOthersNames(newOrder.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
@ -51,7 +51,7 @@ namespace PizzeriaFileImplement.Implements
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return AttachPizzaName(order.GetViewModel);
|
||||
return AttachOthersNames(order.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
@ -60,17 +60,22 @@ namespace PizzeriaFileImplement.Implements
|
||||
{
|
||||
source.Orders.Remove(order);
|
||||
source.SaveOrders();
|
||||
return AttachPizzaName(order.GetViewModel);
|
||||
return AttachOthersNames(order.GetViewModel);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private OrderViewModel? AttachPizzaName(OrderViewModel? model)
|
||||
private OrderViewModel AttachOthersNames(OrderViewModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var clientFIO = source.Clients.FirstOrDefault(x => model.ClientId == x.Id)?.ClientFIO;
|
||||
var pizza = source.Pizzas.FirstOrDefault(x => x.Id == model.PizzaId);
|
||||
if (clientFIO != null)
|
||||
{
|
||||
model.ClientFIO = clientFIO;
|
||||
}
|
||||
if (pizza != null)
|
||||
{
|
||||
model.PizzaName = pizza.PizzaName;
|
||||
|
75
Pizzeria/PizzeriaFileImplement/Models/Client.cs
Normal file
75
Pizzeria/PizzeriaFileImplement/Models/Client.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PizzeriaFileImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public static Client? Create(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public static Client? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ClientFIO = element.Element("ClientFIO")!.Value,
|
||||
Email = element.Element("Email")!.Value,
|
||||
Password = element.Element("Password")!.Value
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Client",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ClientFIO", ClientFIO),
|
||||
new XElement("Email", Email),
|
||||
new XElement("Password", Password));
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ namespace PizzeriaFileImplement.Models
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int PizzaId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
@ -23,6 +24,7 @@ namespace PizzeriaFileImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientId = model.ClientId,
|
||||
PizzaId = model.PizzaId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
@ -41,6 +43,7 @@ namespace PizzeriaFileImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
ClientId= Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||
PizzaId = Convert.ToInt32(element.Element("PizzaId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
@ -62,6 +65,7 @@ namespace PizzeriaFileImplement.Models
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientId = ClientId,
|
||||
PizzaId = PizzaId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
@ -72,6 +76,7 @@ namespace PizzeriaFileImplement.Models
|
||||
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ClientId",ClientId.ToString()),
|
||||
new XElement("PizzaId", PizzaId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
|
@ -13,11 +13,13 @@ namespace PizzeriaListImplement
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Pizza> Pizzas { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Pizzas = new List<Pizza>();
|
||||
Clients = new List<Client>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
115
Pizzeria/PizzeriaListImplement/Implements/ClientStorage.cs
Normal file
115
Pizzeria/PizzeriaListImplement/Implements/ClientStorage.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaListImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
|
||||
public ClientStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ClientViewModel>();
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
result.Add(client.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
{
|
||||
var result = new List<ClientViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.ClientFIO) && client.ClientFIO.Contains(model.ClientFIO)) ||
|
||||
(!string.IsNullOrEmpty(model.Email) && client.ClientFIO.Contains(model.Email)))
|
||||
{
|
||||
result.Add(client.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue && string.IsNullOrEmpty(model.ClientFIO) && string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if ((model.Id.HasValue && client.Id == model.Id) ||
|
||||
(!string.IsNullOrEmpty(model.ClientFIO) && client.ClientFIO == model.ClientFIO) ||
|
||||
(!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) && client.Email == model.Email && client.Password == model.Password))
|
||||
{
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (model.Id <= client.Id)
|
||||
{
|
||||
model.Id = client.Id + 1;
|
||||
}
|
||||
}
|
||||
var newClient = Client.Create(model);
|
||||
if (newClient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Clients.Add(newClient);
|
||||
return newClient.GetViewModel;
|
||||
}
|
||||
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (client.Id == model.Id)
|
||||
{
|
||||
client.Update(model);
|
||||
return client.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Clients.Count; ++i)
|
||||
{
|
||||
if (_source.Clients[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Clients[i];
|
||||
_source.Clients.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -23,22 +23,23 @@ namespace PizzeriaListImplement.Implements
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
result.Add(AttachPizzaName(order.GetViewModel));
|
||||
result.Add(AttachOthersNames(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (model == null || !model.DateFrom.HasValue || !model.DateFrom.HasValue)
|
||||
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||
if ((model.DateFrom.HasValue && model.DateTo.HasValue && order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo) ||
|
||||
(model.ClientId.HasValue && order.ClientId == model.ClientId))
|
||||
{
|
||||
result.Add(AttachPizzaName(order.GetViewModel));
|
||||
result.Add(AttachOthersNames(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -54,7 +55,7 @@ namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
if (model.Id.HasValue && order.Id == model.Id)
|
||||
{
|
||||
return AttachPizzaName(order.GetViewModel);
|
||||
return AttachOthersNames(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -76,7 +77,7 @@ namespace PizzeriaListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
_source.Orders.Add(newOrder);
|
||||
return AttachPizzaName(newOrder.GetViewModel);
|
||||
return AttachOthersNames(newOrder.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
@ -85,7 +86,7 @@ namespace PizzeriaListImplement.Implements
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
order.Update(model);
|
||||
return AttachPizzaName(order.GetViewModel);
|
||||
return AttachOthersNames(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -98,13 +99,21 @@ namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
var element = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
return AttachPizzaName(element.GetViewModel);
|
||||
return AttachOthersNames(element.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
private OrderViewModel AttachPizzaName(OrderViewModel model)
|
||||
private OrderViewModel AttachOthersNames(OrderViewModel model)
|
||||
{
|
||||
foreach (var order in _source.Clients)
|
||||
{
|
||||
if (model.ClientId == order.Id)
|
||||
{
|
||||
model.ClientFIO = order.ClientFIO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (var pizza in _source.Pizzas)
|
||||
{
|
||||
if (pizza.Id == model.PizzaId)
|
||||
|
53
Pizzeria/PizzeriaListImplement/Models/Client.cs
Normal file
53
Pizzeria/PizzeriaListImplement/Models/Client.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PizzeriaListImplement.Models
|
||||
{
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ClientFIO { get; private set; } = string.Empty;
|
||||
public string Email { get; private set; } = string.Empty;
|
||||
public string Password { get; private set; } = string.Empty;
|
||||
|
||||
public static Client? Create(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Client()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientFIO = model.ClientFIO,
|
||||
Email = model.Email,
|
||||
Password = model.Password
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ClientBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientFIO = model.ClientFIO;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientFIO = ClientFIO,
|
||||
Email = Email,
|
||||
Password = Password
|
||||
};
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@ namespace PizzeriaListImplement.Models
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int PizzaId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
@ -27,6 +28,7 @@ namespace PizzeriaListImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientId = model.ClientId,
|
||||
PizzaId = model.PizzaId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
@ -47,6 +49,7 @@ namespace PizzeriaListImplement.Models
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientId = ClientId,
|
||||
PizzaId = PizzaId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
|
65
Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs
Normal file
65
Pizzeria/PizzeriaRestApi/Controllers/ClientController.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
|
||||
namespace PizzeriaRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class ClientController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _logic;
|
||||
public ClientController(IClientLogic logic, ILogger<ClientController>
|
||||
logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
[HttpGet]
|
||||
public ClientViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _logic.ReadElement(new ClientSearchModel
|
||||
{
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void Register(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void UpdateData(ClientBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
85
Pizzeria/PizzeriaRestApi/Controllers/MainController.cs
Normal file
85
Pizzeria/PizzeriaRestApi/Controllers/MainController.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
|
||||
namespace PizzeriaRestApi.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
public class MainController : Controller
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderLogic _order;
|
||||
private readonly IPizzaLogic _pizza;
|
||||
public MainController(ILogger<MainController> logger, IOrderLogic order,IPizzaLogic pizza)
|
||||
{
|
||||
_logger = logger;
|
||||
_order = order;
|
||||
_pizza = pizza;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<PizzaViewModel>? GetPizzaList()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pizza.ReadList(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка пицц");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public PizzaViewModel? GetPizza(int productId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _pizza.ReadElement(new PizzaSearchModel
|
||||
{
|
||||
Id =
|
||||
productId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения пиццы по id={Id}",
|
||||
productId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public List<OrderViewModel>? GetOrders(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _order.ReadList(new OrderSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения списка заказов клиента id ={ Id}", clientId);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_order.CreateOrder(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания заказа");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
19
Pizzeria/PizzeriaRestApi/PizzeriaRestApi.csproj
Normal file
19
Pizzeria/PizzeriaRestApi/PizzeriaRestApi.csproj
Normal file
@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||
<ProjectReference Include="..\PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
51
Pizzeria/PizzeriaRestApi/Program.cs
Normal file
51
Pizzeria/PizzeriaRestApi/Program.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using Microsoft.OpenApi.Models;
|
||||
using PizzeriaBusinessLogic;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaDatabaseImplement.Implements;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
builder.Logging.SetMinimumLevel(LogLevel.Trace);
|
||||
builder.Logging.AddLog4Net("log4net.config");
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
builder.Services.AddTransient<IPizzaStorage, PizzaStorage>();
|
||||
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IPizzaLogic, PizzaLogic>();
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo
|
||||
{
|
||||
Title = "AbstractShopRestApi",
|
||||
Version
|
||||
= "v1"
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json","AbstractShopRestApi v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
31
Pizzeria/PizzeriaRestApi/Properties/launchSettings.json
Normal file
31
Pizzeria/PizzeriaRestApi/Properties/launchSettings.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"iisSettings": {
|
||||
"windowsAuthentication": false,
|
||||
"anonymousAuthentication": true,
|
||||
"iisExpress": {
|
||||
"applicationUrl": "http://localhost:53758",
|
||||
"sslPort": 44380
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"PizzeriaRestApi": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "https://localhost:7245;http://localhost:5245",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
8
Pizzeria/PizzeriaRestApi/appsettings.Development.json
Normal file
8
Pizzeria/PizzeriaRestApi/appsettings.Development.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
Pizzeria/PizzeriaRestApi/appsettings.json
Normal file
9
Pizzeria/PizzeriaRestApi/appsettings.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
16
Pizzeria/PizzeriaRestApi/log4net.config
Normal file
16
Pizzeria/PizzeriaRestApi/log4net.config
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<log4net>
|
||||
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
|
||||
<file value="c:/temp/AbstractShopRestApi.log" />
|
||||
<appendToFile value="true" />
|
||||
<maximumFileSize value="100KB" />
|
||||
<maxSizeRollBackups value="2" />
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="%date %5level %logger.%method [%line] - MESSAGE: %message%newline %exception" />
|
||||
</layout>
|
||||
</appender>
|
||||
<root>
|
||||
<level value="TRACE" />
|
||||
<appender-ref ref="RollingFile" />
|
||||
</root>
|
||||
</log4net>
|
92
Pizzeria/PizzeriaView/FormClients.Designer.cs
generated
Normal file
92
Pizzeria/PizzeriaView/FormClients.Designer.cs
generated
Normal file
@ -0,0 +1,92 @@
|
||||
namespace Pizzeria
|
||||
{
|
||||
partial class FormClients
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
dataGridViewClients = new DataGridView();
|
||||
buttonDel = new Button();
|
||||
buttonRef = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewClients).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// dataGridViewClients
|
||||
//
|
||||
dataGridViewClients.BackgroundColor = SystemColors.ControlLightLight;
|
||||
dataGridViewClients.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridViewClients.Location = new Point(1, 1);
|
||||
dataGridViewClients.Name = "dataGridViewClients";
|
||||
dataGridViewClients.RowHeadersVisible = false;
|
||||
dataGridViewClients.RowHeadersWidth = 51;
|
||||
dataGridViewClients.RowTemplate.Height = 29;
|
||||
dataGridViewClients.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridViewClients.Size = new Size(650, 402);
|
||||
dataGridViewClients.TabIndex = 0;
|
||||
//
|
||||
// buttonDel
|
||||
//
|
||||
buttonDel.Location = new Point(668, 12);
|
||||
buttonDel.Name = "buttonDel";
|
||||
buttonDel.Size = new Size(102, 29);
|
||||
buttonDel.TabIndex = 1;
|
||||
buttonDel.Text = "Удалить";
|
||||
buttonDel.UseVisualStyleBackColor = true;
|
||||
buttonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// buttonRef
|
||||
//
|
||||
buttonRef.Location = new Point(668, 47);
|
||||
buttonRef.Name = "buttonRef";
|
||||
buttonRef.Size = new Size(102, 29);
|
||||
buttonRef.TabIndex = 2;
|
||||
buttonRef.Text = "Обновить";
|
||||
buttonRef.UseVisualStyleBackColor = true;
|
||||
buttonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// FormClients
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(782, 403);
|
||||
Controls.Add(buttonRef);
|
||||
Controls.Add(buttonDel);
|
||||
Controls.Add(dataGridViewClients);
|
||||
Name = "FormClients";
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Text = "Клиенты";
|
||||
Load += FormClients_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridViewClients).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView dataGridViewClients;
|
||||
private Button buttonDel;
|
||||
private Button buttonRef;
|
||||
}
|
||||
}
|
75
Pizzeria/PizzeriaView/FormClients.cs
Normal file
75
Pizzeria/PizzeriaView/FormClients.cs
Normal file
@ -0,0 +1,75 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Pizzeria
|
||||
{
|
||||
public partial class FormClients : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _logic;
|
||||
|
||||
public FormClients(ILogger<FormClients> logger, IClientLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormClients_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var list = _logic.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
dataGridViewClients.DataSource = list;
|
||||
dataGridViewClients.Columns["Id"].Visible = false;
|
||||
dataGridViewClients.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка клиентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки клиентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonDel_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridViewClients.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
|
||||
DialogResult.Yes)
|
||||
{
|
||||
int id = Convert.ToInt32(dataGridViewClients.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление клиента");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ClientBindingModel { Id = id }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления клиента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonRef_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
60
Pizzeria/PizzeriaView/FormClients.resx
Normal file
60
Pizzeria/PizzeriaView/FormClients.resx
Normal file
@ -0,0 +1,60 @@
|
||||
<root>
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
16
Pizzeria/PizzeriaView/FormMain.Designer.cs
generated
16
Pizzeria/PizzeriaView/FormMain.Designer.cs
generated
@ -42,6 +42,7 @@
|
||||
this.buttonOrderReady = new System.Windows.Forms.Button();
|
||||
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||
this.buttonRef = new System.Windows.Forms.Button();
|
||||
this.clientsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -63,7 +64,8 @@
|
||||
//
|
||||
this.bookToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ingridientsToolStripMenuItem,
|
||||
this.pizzasToolStripMenuItem});
|
||||
this.pizzasToolStripMenuItem,
|
||||
this.clientsToolStripMenuItem});
|
||||
this.bookToolStripMenuItem.Name = "bookToolStripMenuItem";
|
||||
this.bookToolStripMenuItem.Size = new System.Drawing.Size(87, 20);
|
||||
this.bookToolStripMenuItem.Text = "Справочник";
|
||||
@ -71,14 +73,14 @@
|
||||
// ingridientsToolStripMenuItem
|
||||
//
|
||||
this.ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem";
|
||||
this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
|
||||
this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.ingridientsToolStripMenuItem.Text = "Ингредиенты";
|
||||
this.ingridientsToolStripMenuItem.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click);
|
||||
//
|
||||
// pizzasToolStripMenuItem
|
||||
//
|
||||
this.pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem";
|
||||
this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
|
||||
this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.pizzasToolStripMenuItem.Text = "Пиццы";
|
||||
this.pizzasToolStripMenuItem.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click);
|
||||
//
|
||||
@ -182,6 +184,13 @@
|
||||
this.buttonRef.UseVisualStyleBackColor = true;
|
||||
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||
//
|
||||
// clientsToolStripMenuItem
|
||||
//
|
||||
this.clientsToolStripMenuItem.Name = "clientsToolStripMenuItem";
|
||||
this.clientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.clientsToolStripMenuItem.Text = "Клиенты";
|
||||
this.clientsToolStripMenuItem.Click += new System.EventHandler(this.ClientsToolStripMenuItem_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
@ -223,5 +232,6 @@
|
||||
private ToolStripMenuItem ингредиентыToolStripMenuItem;
|
||||
private ToolStripMenuItem ингредиентыПоПиццамToolStripMenuItem;
|
||||
private ToolStripMenuItem списокЗаказовToolStripMenuItem;
|
||||
private ToolStripMenuItem clientsToolStripMenuItem;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using Pizzeria;
|
||||
|
||||
namespace PizzeriaView
|
||||
{
|
||||
@ -38,6 +39,7 @@ namespace PizzeriaView
|
||||
{
|
||||
dataGridView.DataSource = list;
|
||||
dataGridView.Columns["PizzaId"].Visible = false;
|
||||
dataGridView.Columns["ClientId"].Visible = false;
|
||||
dataGridView.Columns["PizzaName"].AutoSizeMode =
|
||||
DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
@ -49,6 +51,14 @@ namespace PizzeriaView
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
private void ClientsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
|
||||
if (service is FormClients form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
private void IngridentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||
|
@ -9,6 +9,7 @@ using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaDatabaseImplement.Implements;
|
||||
using System;
|
||||
using Pizzeria;
|
||||
|
||||
namespace PizzeriaView
|
||||
{
|
||||
@ -37,12 +38,15 @@ namespace PizzeriaView
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
option.AddNLog("nlog.config");
|
||||
});
|
||||
services.AddTransient<FormMain>();
|
||||
|
||||
services.AddTransient<IClientStorage, ClientStorage>();
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IPizzaStorage, PizzaStorage>();
|
||||
|
||||
services.AddTransient<IClientLogic, ClientLogic>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IPizzaLogic, PizzaLogic>();
|
||||
services.AddTransient<IReportLogic, ReportLogic>();
|
||||
@ -51,6 +55,7 @@ namespace PizzeriaView
|
||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
|
||||
services.AddTransient<FormClients>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
|
Loading…
Reference in New Issue
Block a user