This commit is contained in:
the 2023-04-07 17:53:57 +04:00
parent aef57c1f55
commit 9f9aa560c3
21 changed files with 460 additions and 6 deletions

View File

@ -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<EquipmentReceivingViewModel> EquipmentReceivings { get; set; } = new();
}
}

View File

@ -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;
}
}

View File

@ -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<ClientViewModel>? ReadList(ClientSearchModel? model);
ClientViewModel? ReadElement(ClientSearchModel model);
bool Create(ClientBindingModel model);
bool Update(ClientBindingModel model);
bool Delete(ClientBindingModel model);
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -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<ClientViewModel> GetFullList();
List<ClientViewModel> GetFilteredList(ClientSearchModel model);
ClientViewModel? GetElement(ClientSearchModel model);
ClientViewModel? Insert(ClientBindingModel model);
ClientViewModel? Update(ClientBindingModel model);
ClientViewModel? Delete(ClientBindingModel model);
}
}

View File

@ -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;
}
}

View File

@ -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; }
}
}

View File

@ -29,5 +29,6 @@ namespace ComputerShopDatabaseImplement
public virtual DbSet<EquipmentReceiving> EquipmentReceivings { set; get; }
public virtual DbSet<ComponentSupply> ComponentSupplies { set; get; }
public virtual DbSet<AssemblyOrder> AssemblyOrders { set; get; }
public virtual DbSet<Client> Clients { set; get; }
}
}

View File

@ -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<ClientViewModel> 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<ClientViewModel> 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;
}
}
}

View File

@ -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();
}

View File

@ -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<Order> Orders { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Assembly> Assemblies { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Supply> Supplies { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<EquipmentReceiving> EquipmentReceivings { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Purchase> 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,
};
}
}

View File

@ -0,0 +1,20 @@
<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="..\ComputerShopBusinessLogic\ComputerShopBusinessLogic.csproj" />
<ProjectReference Include="..\ComputerShopContracts\ComputerShopContracts.csproj" />
<ProjectReference Include="..\ComputerShopDatabaseImplement\ComputerShopDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -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<WeatherForecastController> _logger;
public WeatherForecastController(ILogger<WeatherForecastController> logger)
{
_logger = logger;
}
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> 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();
}
}
}

View File

@ -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<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IPurchaseStorage, PurchaseStorage>();
builder.Services.AddTransient<IComponentStorage, ComponentStorage>();
builder.Services.AddTransient<IAssemblyStorage, AssemblyStorage>();
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();

View File

@ -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"
}
}
}
}

View File

@ -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; }
}
}

View File

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

View File

@ -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