diff --git a/TypographyBusinessLogic/BusinessLogics/ClientLogic.cs b/TypographyBusinessLogic/BusinessLogics/ClientLogic.cs new file mode 100644 index 0000000..de9356c --- /dev/null +++ b/TypographyBusinessLogic/BusinessLogics/ClientLogic.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using Microsoft.Extensions.Logging; + + + +namespace TypographyBusinessLogic.BusinessLogics +{ + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + private readonly IClientStorage _clientStorage; + public ClientLogic(ILogger logger, IClientStorage clientStorage) + { + _logger = logger; + _clientStorage = clientStorage; + } + + 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; + } + + public ClientViewModel? ReadElement(ClientSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Email:{Email}.Id:{ Id}", model.Email, model.Id); + 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 List? ReadList(ClientSearchModel? model) + { + _logger.LogInformation("ReadList. Email:{Email}.Id:{ Id} ", model?.Email, model?.Id); + 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; + } + + 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)); + } + _logger.LogInformation("Client. Id: {Id}, FIO: {fio}, 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("Клиент с таким логином(почтой) уже есть"); + } + } + } +} diff --git a/TypographyContracts/BindingModels/ClientBindingModel.cs b/TypographyContracts/BindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..f03cc69 --- /dev/null +++ b/TypographyContracts/BindingModels/ClientBindingModel.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; + +namespace TypographyContracts.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; + } +} diff --git a/TypographyContracts/BindingModels/OrderBindingModel.cs b/TypographyContracts/BindingModels/OrderBindingModel.cs index 4708a3d..7f8e468 100644 --- a/TypographyContracts/BindingModels/OrderBindingModel.cs +++ b/TypographyContracts/BindingModels/OrderBindingModel.cs @@ -12,6 +12,7 @@ namespace TypographyContracts.BindingModels { public int Id { get; set; } public int PrintedId { get; set; } + public int ClientId { get; set; } public int Count { get; set; } public double Sum { get; set; } public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; diff --git a/TypographyContracts/BusinessLogicsContracts/IClientLogic.cs b/TypographyContracts/BusinessLogicsContracts/IClientLogic.cs new file mode 100644 index 0000000..5579d8d --- /dev/null +++ b/TypographyContracts/BusinessLogicsContracts/IClientLogic.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyContracts.SearchModels; + +namespace TypographyContracts.BusinessLogicsContracts +{ + public interface IClientLogic + { + List? ReadList(ClientSearchModel? model); + ClientViewModel? ReadElement(ClientSearchModel model); + bool Create(ClientBindingModel model); + bool Update(ClientBindingModel model); + bool Delete(ClientBindingModel model); + + } +} diff --git a/TypographyContracts/SearchModels/ClientSearchModel.cs b/TypographyContracts/SearchModels/ClientSearchModel.cs new file mode 100644 index 0000000..f8f2428 --- /dev/null +++ b/TypographyContracts/SearchModels/ClientSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyContracts.SearchModels +{ + public class ClientSearchModel + { + public int? Id { get; set; } + public string? ClientFIO { get; set; } + public string? Email { get; set; } + public string? Password { get; set; } + } +} diff --git a/TypographyContracts/SearchModels/OrderSearchModel.cs b/TypographyContracts/SearchModels/OrderSearchModel.cs index 6e5e8d6..f050363 100644 --- a/TypographyContracts/SearchModels/OrderSearchModel.cs +++ b/TypographyContracts/SearchModels/OrderSearchModel.cs @@ -11,5 +11,6 @@ namespace TypographyContracts.SearchModels public int? Id { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public int? ClientId { get; set; } } } diff --git a/TypographyContracts/StoragesContracts/IClientStorage.cs b/TypographyContracts/StoragesContracts/IClientStorage.cs new file mode 100644 index 0000000..514b2eb --- /dev/null +++ b/TypographyContracts/StoragesContracts/IClientStorage.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyContracts.SearchModels; + +namespace TypographyContracts.StoragesContracts +{ + public interface IClientStorage + { + List GetFullList(); + List GetFilteredList(ClientSearchModel model); + ClientViewModel? GetElement(ClientSearchModel model); + ClientViewModel? Insert(ClientBindingModel model); + ClientViewModel? Update(ClientBindingModel model); + ClientViewModel? Delete(ClientBindingModel model); + } +} diff --git a/TypographyContracts/ViewModels/ClientViewModel.cs b/TypographyContracts/ViewModels/ClientViewModel.cs new file mode 100644 index 0000000..61918a6 --- /dev/null +++ b/TypographyContracts/ViewModels/ClientViewModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyDataModels.Models; + +namespace TypographyContracts.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; + } +} diff --git a/TypographyContracts/ViewModels/OrderViewModel.cs b/TypographyContracts/ViewModels/OrderViewModel.cs index 847ebde..f1e18ce 100644 --- a/TypographyContracts/ViewModels/OrderViewModel.cs +++ b/TypographyContracts/ViewModels/OrderViewModel.cs @@ -17,6 +17,9 @@ namespace TypographyContracts.ViewModels public int PrintedId { get; set; } [DisplayName("Изделие")] public string PrintedName { get; set; } = string.Empty; + public int ClientId { get; set; } + [DisplayName("Client's FIO")] + public string ClientFIO { get; set; } = string.Empty; [DisplayName("Количество")] public int Count { get; set; } [DisplayName("Сумма")] diff --git a/TypographyDataModels/OrderStatus.cs b/TypographyDataModels/Enums/OrderStatus.cs similarity index 100% rename from TypographyDataModels/OrderStatus.cs rename to TypographyDataModels/Enums/OrderStatus.cs diff --git a/TypographyDataModels/Models/IClientModel.cs b/TypographyDataModels/Models/IClientModel.cs new file mode 100644 index 0000000..74dc64d --- /dev/null +++ b/TypographyDataModels/Models/IClientModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace TypographyDataModels.Models +{ + public interface IClientModel : IId + { + string ClientFIO { get; } + string Email { get; } + string Password { get; } + + } +} diff --git a/TypographyDataModels/IComponentModel.cs b/TypographyDataModels/Models/IComponentModel.cs similarity index 100% rename from TypographyDataModels/IComponentModel.cs rename to TypographyDataModels/Models/IComponentModel.cs diff --git a/TypographyDataModels/IOrderModel.cs b/TypographyDataModels/Models/IOrderModel.cs similarity index 83% rename from TypographyDataModels/IOrderModel.cs rename to TypographyDataModels/Models/IOrderModel.cs index 3358942..5a282aa 100644 --- a/TypographyDataModels/IOrderModel.cs +++ b/TypographyDataModels/Models/IOrderModel.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using TypographyDataModels.Enums; -namespace TypographyDataModels.Enums +namespace TypographyDataModels.Models { public interface IOrderModel : IId { diff --git a/TypographyDataModels/IPrintedModel.cs b/TypographyDataModels/Models/IPrintedModel.cs similarity index 100% rename from TypographyDataModels/IPrintedModel.cs rename to TypographyDataModels/Models/IPrintedModel.cs diff --git a/TypographyRestApi/Controllers/WeatherForecastController.cs b/TypographyRestApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..815c0b2 --- /dev/null +++ b/TypographyRestApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace TypographyRestApi.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/TypographyRestApi/Program.cs b/TypographyRestApi/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/TypographyRestApi/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/TypographyRestApi/Properties/launchSettings.json b/TypographyRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..29ba07f --- /dev/null +++ b/TypographyRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:17882", + "sslPort": 44325 + } + }, + "profiles": { + "TypographyRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7034;http://localhost:5007", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/TypographyRestApi/TypographyRestApi.csproj b/TypographyRestApi/TypographyRestApi.csproj new file mode 100644 index 0000000..b8b1c4b --- /dev/null +++ b/TypographyRestApi/TypographyRestApi.csproj @@ -0,0 +1,19 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + diff --git a/TypographyRestApi/WeatherForecast.cs b/TypographyRestApi/WeatherForecast.cs new file mode 100644 index 0000000..51325e3 --- /dev/null +++ b/TypographyRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace TypographyRestApi +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/TypographyRestApi/appsettings.Development.json b/TypographyRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/TypographyRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/TypographyRestApi/appsettings.json b/TypographyRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/TypographyRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/TypographyShopDatabaseImplements/Implements/ClientStorage.cs b/TypographyShopDatabaseImplements/Implements/ClientStorage.cs new file mode 100644 index 0000000..ab2c1ac --- /dev/null +++ b/TypographyShopDatabaseImplements/Implements/ClientStorage.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.SearchModels; +using TypographyContracts.StoragesContracts; +using TypographyContracts.ViewModels; +using TypographyDatabaseImplements.Models; + +namespace TypographyDatabaseImplements.Implements +{ + public class ClientStorage : IClientStorage + { + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + using var context = new TypographyDatabase(); + return context.Clients.FirstOrDefault(x => + (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) + || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email)) + { + return new(); + } + using var context = new TypographyDatabase(); + return context.Clients + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new TypographyDatabase(); + return context.Clients.Select(x => x.GetViewModel).ToList(); + } + + public ClientViewModel? Insert(ClientBindingModel model) + { + var newClient = Client.Create(model); + if (newClient == null) + { + return null; + } + using var context = new TypographyDatabase(); + context.Clients.Add(newClient); + context.SaveChanges(); + return newClient.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new TypographyDatabase(); + 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 TypographyDatabase(); + var client = context.Clients.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + context.Clients.Remove(client); + context.SaveChanges(); + return client.GetViewModel; + } + } +} diff --git a/TypographyShopDatabaseImplements/Implements/OrderStorage.cs b/TypographyShopDatabaseImplements/Implements/OrderStorage.cs index df2a9da..0961d7c 100644 --- a/TypographyShopDatabaseImplements/Implements/OrderStorage.cs +++ b/TypographyShopDatabaseImplements/Implements/OrderStorage.cs @@ -17,19 +17,20 @@ namespace TypographyDatabaseImplement.Implements return null; } using var context = new TypographyDatabase(); - return context.Orders.Include(x => x.Printed).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + return context.Orders.Include(x => x.Printed).Include(x => x.Client).FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; } public List GetFilteredList(OrderSearchModel model) { - if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue) + if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue) { return new(); } using var context = new TypographyDatabase(); return context.Orders - .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo) + .Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo || x.ClientId == model.ClientId) .Include(x => x.Printed) + .Include(x => x.Client) .Select(x => x.GetViewModel) .ToList(); } @@ -37,7 +38,7 @@ namespace TypographyDatabaseImplement.Implements public List GetFullList() { using var context = new TypographyDatabase(); - return context.Orders.Include(x => x.Printed).Select(x => x.GetViewModel).ToList(); + return context.Orders.Include(x => x.Printed).Include(x => x.Client).Select(x => x.GetViewModel).ToList(); } public OrderViewModel? Insert(OrderBindingModel model) @@ -50,7 +51,7 @@ namespace TypographyDatabaseImplement.Implements using var context = new TypographyDatabase(); context.Orders.Add(newOrder); context.SaveChanges(); - return context.Orders.Include(x => x.Printed).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; + return context.Orders.Include(x => x.Printed).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel; } public OrderViewModel? Update(OrderBindingModel model) @@ -63,7 +64,7 @@ namespace TypographyDatabaseImplement.Implements } order.Update(model); context.SaveChanges(); - return context.Orders.Include(x => x.Printed).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + return context.Orders.Include(x => x.Printed).Include(x => x.Client).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } public OrderViewModel? Delete(OrderBindingModel model) { diff --git a/TypographyShopDatabaseImplements/Models/Client.cs b/TypographyShopDatabaseImplements/Models/Client.cs new file mode 100644 index 0000000..b1818aa --- /dev/null +++ b/TypographyShopDatabaseImplements/Models/Client.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using TypographyContracts.BindingModels; +using TypographyContracts.ViewModels; +using TypographyDatabaseImplement.Models; +using TypographyDataModels.Models; + + +namespace TypographyDatabaseImplements.Models +{ + public class Client : IClientModel + { + public int Id { get; private set; } + + [Required] + public string ClientFIO { get; private set; } = string.Empty; + + [Required] + public string Email { get; private set; } = string.Empty; + + [Required] + public string Password { get; private set; } = string.Empty; + + [ForeignKey("ClientId")] + public virtual List Orders { get; set; } = new(); + + public static Client? Create(ClientBindingModel model) + { + if (model == null) + { + return null; + } + return new() + { + 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, + }; + } +} diff --git a/TypographyShopDatabaseImplements/Models/Order.cs b/TypographyShopDatabaseImplements/Models/Order.cs index b45eaf4..5daa1d8 100644 --- a/TypographyShopDatabaseImplements/Models/Order.cs +++ b/TypographyShopDatabaseImplements/Models/Order.cs @@ -14,6 +14,8 @@ namespace TypographyDatabaseImplement.Models [Required] public int PrintedId { get; set; } + [Required] + public int ClientId { get; private set; } [Required] public int Count { get; set; } @@ -30,6 +32,7 @@ namespace TypographyDatabaseImplement.Models public DateTime? DateImplement { get; set; } public virtual Printed Printed { get; set; } + public virtual Client Client { get; set; } public static Order? Create(OrderBindingModel? model) { @@ -41,6 +44,7 @@ namespace TypographyDatabaseImplement.Models { Id = model.Id, PrintedId = model.PrintedId, + ClientId = model.ClientId, Count = model.Count, Sum = model.Sum, Status = model.Status, @@ -63,12 +67,14 @@ namespace TypographyDatabaseImplement.Models { Id = Id, PrintedId = PrintedId, + ClientId = ClientId, Count = Count, Sum = Sum, Status = Status, DateCreate = DateCreate, DateImplement = DateImplement, - PrintedName = Printed.PrintedName + PrintedName = Printed.PrintedName, + ClientFIO = Client.ClientFIO }; } } \ No newline at end of file diff --git a/TypographyShopDatabaseImplements/TypographyDatabase.cs b/TypographyShopDatabaseImplements/TypographyDatabase.cs index ad7d1b1..5e7bb8f 100644 --- a/TypographyShopDatabaseImplements/TypographyDatabase.cs +++ b/TypographyShopDatabaseImplements/TypographyDatabase.cs @@ -26,5 +26,6 @@ namespace TypographyDatabaseImplements public virtual DbSet Printeds { set; get; } public virtual DbSet PrintedComponents { set; get; } public virtual DbSet Orders { set; get; } + public virtual DbSet Clients { set; get; } } } diff --git a/TypographyView/FormClients.Designer.cs b/TypographyView/FormClients.Designer.cs new file mode 100644 index 0000000..d4ccc18 --- /dev/null +++ b/TypographyView/FormClients.Designer.cs @@ -0,0 +1,92 @@ +namespace AutomobilePlantView +{ + partial class FormClients + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(14, 16); + dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(794, 568); + dataGridView.TabIndex = 0; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(815, 55); + buttonRefresh.Margin = new Padding(3, 4, 3, 4); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(86, 31); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(815, 16); + buttonDelete.Margin = new Padding(3, 4, 3, 4); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(86, 31); + buttonDelete.TabIndex = 5; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // FormClients + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(914, 600); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); + Name = "FormClients"; + Text = "Clients"; + Load += FormClients_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + } +} \ No newline at end of file diff --git a/TypographyView/FormClients.cs b/TypographyView/FormClients.cs new file mode 100644 index 0000000..3152ffa --- /dev/null +++ b/TypographyView/FormClients.cs @@ -0,0 +1,76 @@ +using TypographyContracts.BindingModels; +using TypographyContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public FormClients(ILogger 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) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить клиента?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.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 buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/TypographyView/FormClients.resx b/TypographyView/FormClients.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/TypographyView/FormClients.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TypographyView/FormCreateOrder.Designer.cs b/TypographyView/FormCreateOrder.Designer.cs index b22e27b..8e41a06 100644 --- a/TypographyView/FormCreateOrder.Designer.cs +++ b/TypographyView/FormCreateOrder.Designer.cs @@ -36,6 +36,8 @@ textBoxSum = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); + comboBoxClient = new ComboBox(); + label1 = new Label(); SuspendLayout(); // // labelPrinted @@ -50,7 +52,7 @@ // labelCount // labelCount.AutoSize = true; - labelCount.Location = new Point(12, 65); + labelCount.Location = new Point(12, 94); labelCount.Name = "labelCount"; labelCount.Size = new Size(93, 20); labelCount.TabIndex = 1; @@ -59,7 +61,7 @@ // labelSum // labelSum.AutoSize = true; - labelSum.Location = new Point(12, 103); + labelSum.Location = new Point(12, 123); labelSum.Name = "labelSum"; labelSum.Size = new Size(58, 20); labelSum.TabIndex = 2; @@ -76,7 +78,7 @@ // // textBoxCount // - textBoxCount.Location = new Point(111, 58); + textBoxCount.Location = new Point(111, 87); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(238, 27); textBoxCount.TabIndex = 4; @@ -84,14 +86,14 @@ // // textBoxSum // - textBoxSum.Location = new Point(111, 100); + textBoxSum.Location = new Point(111, 120); textBoxSum.Name = "textBoxSum"; textBoxSum.Size = new Size(238, 27); textBoxSum.TabIndex = 5; // // buttonSave // - buttonSave.Location = new Point(111, 157); + buttonSave.Location = new Point(111, 189); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(117, 43); buttonSave.TabIndex = 6; @@ -101,7 +103,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(234, 157); + buttonCancel.Location = new Point(234, 189); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(115, 43); buttonCancel.TabIndex = 7; @@ -109,11 +111,30 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(111, 53); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(238, 28); + comboBoxClient.TabIndex = 8; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 56); + label1.Name = "label1"; + label1.Size = new Size(61, 20); + label1.TabIndex = 9; + label1.Text = "Клиент:"; + // // FormCreateOrder // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(412, 212); + ClientSize = new Size(474, 264); + Controls.Add(label1); + Controls.Add(comboBoxClient); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxSum); @@ -139,5 +160,7 @@ private TextBox textBoxSum; private Button buttonSave; private Button buttonCancel; + private ComboBox comboBoxClient; + private Label label1; } } \ No newline at end of file diff --git a/TypographyView/FormCreateOrder.cs b/TypographyView/FormCreateOrder.cs index 8491661..bb80153 100644 --- a/TypographyView/FormCreateOrder.cs +++ b/TypographyView/FormCreateOrder.cs @@ -15,13 +15,15 @@ namespace TypographyView private readonly IPrintedLogic _logicIC; private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicClient; - public FormCreateOrder(ILogger logger, IPrintedLogic logicIC, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IPrintedLogic logicIC, IOrderLogic logicO, IClientLogic logicClient) { InitializeComponent(); _logger = logger; _logicIC = logicIC; _logicO = logicO; + _logicClient = logicClient; } private void FormCreateOrder_Load(object sender, EventArgs e) @@ -43,6 +45,24 @@ namespace TypographyView _logger.LogError(ex, "Error during loading printed for order"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var list = _logicClient.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() @@ -87,12 +107,18 @@ namespace TypographyView MessageBox.Show("Выберите закуску", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Order creation"); try { var operationResult = _logicO.CreateOrder(new OrderBindingModel { PrintedId = Convert.ToInt32(comboBoxPrinted.SelectedValue), + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), Sum = Convert.ToDouble(textBoxSum.Text) }); diff --git a/TypographyView/FormMain.Designer.cs b/TypographyView/FormMain.Designer.cs index 6fc72b8..cb9672f 100644 --- a/TypographyView/FormMain.Designer.cs +++ b/TypographyView/FormMain.Designer.cs @@ -32,6 +32,7 @@ справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); изделиеToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem(); списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); @@ -58,7 +59,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделиеToolStripMenuItem, клиентыToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -66,17 +67,24 @@ // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // // изделиеToolStripMenuItem // изделиеToolStripMenuItem.Name = "изделиеToolStripMenuItem"; - изделиеToolStripMenuItem.Size = new Size(182, 26); + изделиеToolStripMenuItem.Size = new Size(224, 26); изделиеToolStripMenuItem.Text = "Изделие"; изделиеToolStripMenuItem.Click += ЗакускаToolStripMenuItem_Click; // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(224, 26); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; + // // отчётыToolStripMenuItem // отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -206,5 +214,6 @@ private ToolStripMenuItem списокКомпонентовToolStripMenuItem; private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; } } \ No newline at end of file diff --git a/TypographyView/FormMain.cs b/TypographyView/FormMain.cs index 2fa2f9e..9862bab 100644 --- a/TypographyView/FormMain.cs +++ b/TypographyView/FormMain.cs @@ -13,13 +13,13 @@ using Microsoft.Extensions.Logging; using TypographyDataModels.Enums; using AbstractShopView; using TypographyBusinessLogic.BusinessLogics; +using AutomobilePlantView; namespace TypographyView { public partial class FormMain : Form { private readonly ILogger _logger; - private readonly IOrderLogic _orderLogic; private readonly IReportLogic _reportLogic; @@ -45,6 +45,7 @@ namespace TypographyView { dataGridView.DataSource = list; dataGridView.Columns["PrintedId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["PrintedName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } _logger.LogInformation("Orders loading"); @@ -55,6 +56,14 @@ namespace TypographyView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e) { diff --git a/TypographyView/Program.cs b/TypographyView/Program.cs index 1f8a82c..b93ee90 100644 --- a/TypographyView/Program.cs +++ b/TypographyView/Program.cs @@ -8,6 +8,8 @@ using NLog.Extensions.Logging; using TypographyBusinessLogic.OfficePackage.Implements; using TypographyBusinessLogic.OfficePackage; using AbstractShopView; +using AutomobilePlantView; + namespace TypographyView { @@ -39,11 +41,13 @@ namespace TypographyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -58,6 +62,7 @@ namespace TypographyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/TypographyView/TypographyView.sln b/TypographyView/TypographyView.sln index 06f3720..3a91c43 100644 --- a/TypographyView/TypographyView.sln +++ b/TypographyView/TypographyView.sln @@ -15,7 +15,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyBusinessLogic", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyFileImplement", "..\TypographyFileImplement\TypographyFileImplement.csproj", "{DCBDF361-C514-4319-A542-5629650E7E8A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyDatabaseImplements", "..\TypographyShopDatabaseImplements\TypographyDatabaseImplements.csproj", "{53696C80-7558-41F5-AF69-73ACA345C92B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TypographyDatabaseImplements", "..\TypographyShopDatabaseImplements\TypographyDatabaseImplements.csproj", "{53696C80-7558-41F5-AF69-73ACA345C92B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TypographyRestApi", "..\TypographyRestApi\TypographyRestApi.csproj", "{855FA8ED-2B0F-4EF5-927F-FE32C2EBD962}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -51,6 +53,10 @@ Global {53696C80-7558-41F5-AF69-73ACA345C92B}.Debug|Any CPU.Build.0 = Debug|Any CPU {53696C80-7558-41F5-AF69-73ACA345C92B}.Release|Any CPU.ActiveCfg = Release|Any CPU {53696C80-7558-41F5-AF69-73ACA345C92B}.Release|Any CPU.Build.0 = Release|Any CPU + {855FA8ED-2B0F-4EF5-927F-FE32C2EBD962}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {855FA8ED-2B0F-4EF5-927F-FE32C2EBD962}.Debug|Any CPU.Build.0 = Debug|Any CPU + {855FA8ED-2B0F-4EF5-927F-FE32C2EBD962}.Release|Any CPU.ActiveCfg = Release|Any CPU + {855FA8ED-2B0F-4EF5-927F-FE32C2EBD962}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE