diff --git a/FishFactory/FishFactory.sln b/FishFactory/FishFactory.sln index a986a5c..fcde0e8 100644 --- a/FishFactory/FishFactory.sln +++ b/FishFactory/FishFactory.sln @@ -13,9 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDataModel", "..\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryListImplement", "..\FishFactoryListImplement\FishFactoryListImplement.csproj", "{A507DACE-7D8D-4C0F-AB5D-764FE1A61EDC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryFileImplement", "..\FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{4EB943AB-67A8-4386-8874-FA0E3E98159C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryFileImplement", "..\FishFactoryFileImplement\FishFactoryFileImplement.csproj", "{4EB943AB-67A8-4386-8874-FA0E3E98159C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryDatabaseImplement", "..\FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj", "{5744376D-B7D8-4FFD-B6D9-F53C169B056C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FishFactoryDatabaseImplement", "..\FishFactoryDatabaseImplement\FishFactoryDatabaseImplement.csproj", "{5744376D-B7D8-4FFD-B6D9-F53C169B056C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FishFactoryRestApi", "..\FishFactoryRestApi\FishFactoryRestApi.csproj", "{AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -81,6 +83,14 @@ Global {5744376D-B7D8-4FFD-B6D9-F53C169B056C}.Release|Any CPU.Build.0 = Release|Any CPU {5744376D-B7D8-4FFD-B6D9-F53C169B056C}.Release|x86.ActiveCfg = Release|Any CPU {5744376D-B7D8-4FFD-B6D9-F53C169B056C}.Release|x86.Build.0 = Release|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Debug|Any CPU.Build.0 = Debug|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Debug|x86.ActiveCfg = Debug|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Debug|x86.Build.0 = Debug|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Release|Any CPU.ActiveCfg = Release|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Release|Any CPU.Build.0 = Release|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Release|x86.ActiveCfg = Release|Any CPU + {AB6068FA-9FA7-40E9-9A2F-2BF7B97AD621}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FishFactory/Forms/FormClients.Designer.cs b/FishFactory/Forms/FormClients.Designer.cs new file mode 100644 index 0000000..cb5a6bd --- /dev/null +++ b/FishFactory/Forms/FormClients.Designer.cs @@ -0,0 +1,39 @@ +namespace FishFactory.Forms +{ + 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() + { + this.components = new System.ComponentModel.Container(); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(800, 450); + this.Text = "FormClients"; + } + + #endregion + } +} \ No newline at end of file diff --git a/FishFactory/Forms/FormClients.cs b/FishFactory/Forms/FormClients.cs new file mode 100644 index 0000000..a937e31 --- /dev/null +++ b/FishFactory/Forms/FormClients.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FishFactory.Forms +{ + public partial class FormClients : Form + { + public FormClients() + { + InitializeComponent(); + } + } +} diff --git a/FishFactory/Forms/FormClients.resx b/FishFactory/Forms/FormClients.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/FishFactory/Forms/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/FishFactoryBusinessLogic/BusinessLogic/ClientLogic.cs b/FishFactoryBusinessLogic/BusinessLogic/ClientLogic.cs new file mode 100644 index 0000000..ab5aa55 --- /dev/null +++ b/FishFactoryBusinessLogic/BusinessLogic/ClientLogic.cs @@ -0,0 +1,110 @@ + +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.StoragesContracts; +using FishFactoryContracts.ViewModels; +using Microsoft.Extensions.Logging; + +namespace FishFactoryBusinessLogic.BusinessLogic +{ + public class ClientLogic : IClientLogic + { + private readonly ILogger _logger; + private readonly IClientStorage _ClientStorage; + public ClientLogic(ILogger logger, IClientStorage + ClientStorage) + { + _logger = logger; + _ClientStorage = ClientStorage; + } + 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; + } + + 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 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.Email)) + { + throw new ArgumentNullException("Нет логина пользователя", nameof(model.Email)); + } + _logger.LogInformation("Client. ClientFIO:{ClientFIO}. Email:{Email}. Id:{Id}", model.ClientFIO, model.Email, model.Id); + var element = _ClientStorage.GetElement(new ClientSearchModel + { + Email = model.Email + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Пользователь с таким логином уже есть"); + } + } + } +} \ No newline at end of file diff --git a/FishFactoryContracts/BindingModels/ClientBindingModel.cs b/FishFactoryContracts/BindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..bb46e93 --- /dev/null +++ b/FishFactoryContracts/BindingModels/ClientBindingModel.cs @@ -0,0 +1,13 @@ + +using FishFactoryDataModel.Models; + +namespace FishFactoryContracts.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/FishFactoryContracts/BusinessLogicsContracts/IClientLogic.cs b/FishFactoryContracts/BusinessLogicsContracts/IClientLogic.cs new file mode 100644 index 0000000..427e266 --- /dev/null +++ b/FishFactoryContracts/BusinessLogicsContracts/IClientLogic.cs @@ -0,0 +1,16 @@ +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactoryContracts/SearchModels/ClientSearchModel.cs b/FishFactoryContracts/SearchModels/ClientSearchModel.cs new file mode 100644 index 0000000..2daed78 --- /dev/null +++ b/FishFactoryContracts/SearchModels/ClientSearchModel.cs @@ -0,0 +1,9 @@ + +namespace FishFactoryContracts.SearchModels +{ + public class ClientSearchModel + { + public int? Id { get; set; } + public string? Email { get; set; } + } +} diff --git a/FishFactoryContracts/StoragesContracts/IClientStorage.cs b/FishFactoryContracts/StoragesContracts/IClientStorage.cs new file mode 100644 index 0000000..ccd1683 --- /dev/null +++ b/FishFactoryContracts/StoragesContracts/IClientStorage.cs @@ -0,0 +1,18 @@ + +using FishFactoryContracts.BindingModels; +using FishFactoryContracts.SearchModels; +using FishFactoryContracts.ViewModels; + +namespace FishFactoryContracts.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/FishFactoryContracts/ViewModels/ClientViewModel.cs b/FishFactoryContracts/ViewModels/ClientViewModel.cs new file mode 100644 index 0000000..8f1ed41 --- /dev/null +++ b/FishFactoryContracts/ViewModels/ClientViewModel.cs @@ -0,0 +1,17 @@ +using FishFactoryDataModel.Models; +using System.ComponentModel; + +namespace FishFactoryContracts.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/FishFactoryDataModels/FishFactoryDataModel.csproj b/FishFactoryDataModels/FishFactoryDataModel.csproj index e30cfc1..4e12194 100644 --- a/FishFactoryDataModels/FishFactoryDataModel.csproj +++ b/FishFactoryDataModels/FishFactoryDataModel.csproj @@ -7,8 +7,4 @@ AnyCPU;x86 - - - - diff --git a/FishFactoryDataModels/Models/IClientModel.cs b/FishFactoryDataModels/Models/IClientModel.cs new file mode 100644 index 0000000..38839d9 --- /dev/null +++ b/FishFactoryDataModels/Models/IClientModel.cs @@ -0,0 +1,9 @@ +namespace FishFactoryDataModel.Models +{ + public interface IClientModel + { + string ClientFIO { get; } + string Email { get; } + string Password { get; } + } +} diff --git a/FishFactoryRestApi/Controllers/WeatherForecastController.cs b/FishFactoryRestApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..014a41f --- /dev/null +++ b/FishFactoryRestApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace FishFactoryRestApi.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 = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/FishFactoryRestApi/FishFactoryRestApi.csproj b/FishFactoryRestApi/FishFactoryRestApi.csproj new file mode 100644 index 0000000..86c56cd --- /dev/null +++ b/FishFactoryRestApi/FishFactoryRestApi.csproj @@ -0,0 +1,20 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + + + diff --git a/FishFactoryRestApi/Program.cs b/FishFactoryRestApi/Program.cs new file mode 100644 index 0000000..024c6fd --- /dev/null +++ b/FishFactoryRestApi/Program.cs @@ -0,0 +1,42 @@ +using FishFactoryBusinessLogic.BusinessLogic; +using FishFactoryContracts.BusinessLogicsContracts; +using FishFactoryContracts.StoragesContracts; +using FishFactoryDatabaseImplement.Implements; +using Microsoft.OpenApi.Models; + +var builder = WebApplication.CreateBuilder(args); +builder.Logging.SetMinimumLevel(LogLevel.Trace); +builder.Logging.AddLog4Net("log4net.config"); + +// Add services to the container. +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddTransient(); +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at +https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(c => +{ + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "FishFactoryRestApi", + 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", + "FishFactoryRestApi v1")); +} +app.UseHttpsRedirection(); +app.UseAuthorization(); +app.MapControllers(); +app.Run(); \ No newline at end of file diff --git a/FishFactoryRestApi/Properties/launchSettings.json b/FishFactoryRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..b94ec1e --- /dev/null +++ b/FishFactoryRestApi/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:6044", + "sslPort": 44358 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5284", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7012;http://localhost:5284", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/FishFactoryRestApi/WeatherForecast.cs b/FishFactoryRestApi/WeatherForecast.cs new file mode 100644 index 0000000..7a703d8 --- /dev/null +++ b/FishFactoryRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace FishFactoryRestApi +{ + public class WeatherForecast + { + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/FishFactoryRestApi/appsettings.Development.json b/FishFactoryRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/FishFactoryRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/FishFactoryRestApi/appsettings.json b/FishFactoryRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/FishFactoryRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}