diff --git a/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs new file mode 100644 index 0000000..50f82c3 --- /dev/null +++ b/ComputerShopProvider/ComputerShopBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -0,0 +1,16 @@ +using ComputerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopBusinessLogic.OfficePackage.HelperModels +{ + public class WordInfo + { + public string FileName { get; set; } = string.Empty; + public string Title { get; set; } = string.Empty; + public List EquipmentReceivings { get; set; } = new(); + } +} diff --git a/ComputerShopProvider/ComputerShopContracts/BindingModels/ClientBindingModel.cs b/ComputerShopProvider/ComputerShopContracts/BindingModels/ClientBindingModel.cs new file mode 100644 index 0000000..107b672 --- /dev/null +++ b/ComputerShopProvider/ComputerShopContracts/BindingModels/ClientBindingModel.cs @@ -0,0 +1,17 @@ +using ComputerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.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/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IClientLogic.cs b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IClientLogic.cs new file mode 100644 index 0000000..6c1697e --- /dev/null +++ b/ComputerShopProvider/ComputerShopContracts/BusinessLogicContracts/IClientLogic.cs @@ -0,0 +1,20 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.BusinessLogicContracts +{ + 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/ComputerShopProvider/ComputerShopContracts/SearchModels/ClientSearchModel.cs b/ComputerShopProvider/ComputerShopContracts/SearchModels/ClientSearchModel.cs new file mode 100644 index 0000000..f20ab75 --- /dev/null +++ b/ComputerShopProvider/ComputerShopContracts/SearchModels/ClientSearchModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.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/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs b/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs index bcefd64..526cd2e 100644 --- a/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/SearchModels/EquipmentReceivingSearchModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,5 +12,6 @@ namespace ComputerShopContracts.SearchModels public int? Id { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public SupplySearchModel? Supply { get; set; } } } diff --git a/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs b/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs index 753a162..f611347 100644 --- a/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs +++ b/ComputerShopProvider/ComputerShopContracts/SearchModels/SupplySearchModel.cs @@ -11,5 +11,6 @@ namespace ComputerShopContracts.SearchModels public int? Id { get; set; } public DateTime? DateFrom { get; set; } public DateTime? DateTo { get; set; } + public ComponentSearchModel? Component { get; set; } } } diff --git a/ComputerShopProvider/ComputerShopContracts/StorageContracts/IClientStorage.cs b/ComputerShopProvider/ComputerShopContracts/StorageContracts/IClientStorage.cs new file mode 100644 index 0000000..c1c2e90 --- /dev/null +++ b/ComputerShopProvider/ComputerShopContracts/StorageContracts/IClientStorage.cs @@ -0,0 +1,21 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.StorageContracts +{ + 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/ComputerShopProvider/ComputerShopContracts/ViewModels/ClientViewModel.cs b/ComputerShopProvider/ComputerShopContracts/ViewModels/ClientViewModel.cs new file mode 100644 index 0000000..3b26224 --- /dev/null +++ b/ComputerShopProvider/ComputerShopContracts/ViewModels/ClientViewModel.cs @@ -0,0 +1,21 @@ +using ComputerShopDataModels.Models; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopContracts.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/ComputerShopProvider/ComputerShopDataModels/Models/IClientModel.cs b/ComputerShopProvider/ComputerShopDataModels/Models/IClientModel.cs new file mode 100644 index 0000000..d851be2 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDataModels/Models/IClientModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopDataModels.Models +{ + public interface IClientModel : IId + { + string ClientFIO { get; } + string Email { get; } + string Password { get; } + } +} diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs index 62462a4..69a127f 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/ComputerShopDatabase.cs @@ -29,5 +29,6 @@ namespace ComputerShopDatabaseImplement public virtual DbSet EquipmentReceivings { set; get; } public virtual DbSet ComponentSupplies { set; get; } public virtual DbSet AssemblyOrders { set; get; } + public virtual DbSet Clients { set; get; } } } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/ClientStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/ClientStorage.cs new file mode 100644 index 0000000..5ed7274 --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/ClientStorage.cs @@ -0,0 +1,85 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.SearchModels; +using ComputerShopContracts.StorageContracts; +using ComputerShopContracts.ViewModels; +using ComputerShopDatabaseImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ComputerShopDatabaseImplement.Implements +{ + public class ClientStorage : IClientStorage + { + public ClientViewModel? GetElement(ClientSearchModel model) + { + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + { + return null; + } + using var context = new ComputerShopDatabase(); + 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 ComputerShopDatabase(); + return context.Clients + .Where(x => x.Email.Contains(model.Email)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new ComputerShopDatabase(); + 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 ComputerShopDatabase(); + context.Clients.Add(newClient); + context.SaveChanges(); + return newClient.GetViewModel; + } + + public ClientViewModel? Update(ClientBindingModel model) + { + using var context = new ComputerShopDatabase(); + 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 ComputerShopDatabase(); + 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/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs index 0099af8..c43ea87 100644 --- a/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Implements/EquipmentReceivingStorage.cs @@ -47,7 +47,7 @@ namespace ComputerShopDatabaseImplement.Implements } using var context = new ComputerShopDatabase(); return context.EquipmentReceivings - .Where(x => x.Id == model.Id) + .Where(x => x.Id == model.Supply.Component.Id) .Select(x => x.GetViewModel) .ToList(); } diff --git a/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Client.cs b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Client.cs new file mode 100644 index 0000000..cad2e9e --- /dev/null +++ b/ComputerShopProvider/ComputerShopDatabaseImplement/Models/Client.cs @@ -0,0 +1,72 @@ +using ComputerShopContracts.BindingModels; +using ComputerShopContracts.ViewModels; +using ComputerShopDataModels.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 ComputerShopDatabaseImplement.Models +{ + internal 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(); + [ForeignKey("ClientId")] + public virtual List Assemblies { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List Supplies { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List EquipmentReceivings { get; set; } = new(); + [ForeignKey("ClientId")] + public virtual List Purchases { 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/ComputerShopProvider/ComputerShopRestApi/ComputerShopRestApi.csproj b/ComputerShopProvider/ComputerShopRestApi/ComputerShopRestApi.csproj new file mode 100644 index 0000000..64e76d1 --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/ComputerShopRestApi.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + + + + + + + + + + + + + + diff --git a/ComputerShopProvider/ComputerShopRestApi/Controllers/WeatherForecastController.cs b/ComputerShopProvider/ComputerShopRestApi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..3ff8085 --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace ComputerShopRestApi.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(); + } + } +} \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopRestApi/Program.cs b/ComputerShopProvider/ComputerShopRestApi/Program.cs new file mode 100644 index 0000000..487ee71 --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/Program.cs @@ -0,0 +1,47 @@ +using ComputerShopContracts.BusinessLogicContracts; +using ComputerShopContracts.StorageContracts; +using ComputerShopDatabaseImplement.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.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 = "ComputerShopRestApi", + 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", +"ComputerShopRestApi v1")); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopRestApi/Properties/launchSettings.json b/ComputerShopProvider/ComputerShopRestApi/Properties/launchSettings.json new file mode 100644 index 0000000..b2c876c --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:47569", + "sslPort": 44371 + } + }, + "profiles": { + "ComputerShopRestApi": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7216;http://localhost:5216", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/ComputerShopProvider/ComputerShopRestApi/WeatherForecast.cs b/ComputerShopProvider/ComputerShopRestApi/WeatherForecast.cs new file mode 100644 index 0000000..b0cfe84 --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace ComputerShopRestApi +{ + 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; } + } +} \ No newline at end of file diff --git a/ComputerShopProvider/ComputerShopRestApi/appsettings.Development.json b/ComputerShopProvider/ComputerShopRestApi/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/ComputerShopProvider/ComputerShopRestApi/appsettings.json b/ComputerShopProvider/ComputerShopRestApi/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/ComputerShopProvider/ComputerShopRestApi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/ComputerShopProvider/ComputerShopView/ComputerShopView.sln b/ComputerShopProvider/ComputerShopView/ComputerShopView.sln index 7c004d2..c5d61ba 100644 --- a/ComputerShopProvider/ComputerShopView/ComputerShopView.sln +++ b/ComputerShopProvider/ComputerShopView/ComputerShopView.sln @@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.3.32819.101 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopView", "ComputerShopView.csproj", "{A1CA9942-BF79-4E2D-A6DE-318A308B7101}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopView", "ComputerShopView.csproj", "{A1CA9942-BF79-4E2D-A6DE-318A308B7101}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopDataModels", "..\ComputerShopDataModels\ComputerShopDataModels.csproj", "{737F54AA-A6AF-4B6B-B692-44098F3F73C3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopDataModels", "..\ComputerShopDataModels\ComputerShopDataModels.csproj", "{737F54AA-A6AF-4B6B-B692-44098F3F73C3}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopBusinessLogic", "..\ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj", "{9D02C28B-9F01-4DD4-B53A-89EE456B4B04}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopBusinessLogic", "..\ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj", "{9D02C28B-9F01-4DD4-B53A-89EE456B4B04}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopContracts", "..\ComputerShopContracts\ComputerShopContracts.csproj", "{5D5A014D-835C-4D5A-A235-D2734F18D692}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopContracts", "..\ComputerShopContracts\ComputerShopContracts.csproj", "{5D5A014D-835C-4D5A-A235-D2734F18D692}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopDatabaseImplement", "..\ComputerShopDatabaseImplement\ComputerShopDatabaseImplement.csproj", "{4A783C3D-2198-4F2C-9EC1-8C1E28201AC5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerShopDatabaseImplement", "..\ComputerShopDatabaseImplement\ComputerShopDatabaseImplement.csproj", "{4A783C3D-2198-4F2C-9EC1-8C1E28201AC5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComputerShopRestApi", "..\ComputerShopRestApi\ComputerShopRestApi.csproj", "{86F98FAF-7879-46E2-B505-EB1D819D30C9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -39,6 +41,10 @@ Global {4A783C3D-2198-4F2C-9EC1-8C1E28201AC5}.Debug|Any CPU.Build.0 = Debug|Any CPU {4A783C3D-2198-4F2C-9EC1-8C1E28201AC5}.Release|Any CPU.ActiveCfg = Release|Any CPU {4A783C3D-2198-4F2C-9EC1-8C1E28201AC5}.Release|Any CPU.Build.0 = Release|Any CPU + {86F98FAF-7879-46E2-B505-EB1D819D30C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {86F98FAF-7879-46E2-B505-EB1D819D30C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {86F98FAF-7879-46E2-B505-EB1D819D30C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {86F98FAF-7879-46E2-B505-EB1D819D30C9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE