колобок повесился

This commit is contained in:
Галина Федоренко 2024-05-11 16:01:55 +04:00
parent b37b134137
commit f086f532d0
13 changed files with 533 additions and 9 deletions

View File

@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34024.191
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StorehouseView", "StorehouseView\StorehouseView.csproj", "{2A1C5191-CC20-4015-82E3-AEF00D33C09A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StorehouseView", "StorehouseView\StorehouseView.csproj", "{2A1C5191-CC20-4015-82E3-AEF00D33C09A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StorehouseDataModels", "StorehouseDataModels\StorehouseDataModels.csproj", "{B1D926C1-F37C-4530-A3C0-02EAC8113B3E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StorehouseDataModels", "StorehouseDataModels\StorehouseDataModels.csproj", "{B1D926C1-F37C-4530-A3C0-02EAC8113B3E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StorehouseContracts", "StorehouseContracts\StorehouseContracts.csproj", "{D5258E85-B904-4299-A07D-1F55B71DB0F8}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StorehouseContracts", "StorehouseContracts\StorehouseContracts.csproj", "{D5258E85-B904-4299-A07D-1F55B71DB0F8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StorehouseBusinessLogics", "StorehouseBusinessLogics\StorehouseBusinessLogics.csproj", "{3F171169-DA8D-4CE6-B100-BDD3A4FEDA77}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StorehouseBusinessLogics", "StorehouseBusinessLogics\StorehouseBusinessLogics.csproj", "{3F171169-DA8D-4CE6-B100-BDD3A4FEDA77}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StorehouseDatabase", "StorehouseDatabase\StorehouseDatabase.csproj", "{F2EA8A47-C7B6-4C2B-8AD0-0F3C0C24DF74}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StorehouseDatabaseImplement", "StorehouseDatabaseImplement\StorehouseDatabaseImplement.csproj", "{41FABDF9-049F-447C-B3D5-D9739D852E7C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -35,10 +35,10 @@ Global
{3F171169-DA8D-4CE6-B100-BDD3A4FEDA77}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F171169-DA8D-4CE6-B100-BDD3A4FEDA77}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F171169-DA8D-4CE6-B100-BDD3A4FEDA77}.Release|Any CPU.Build.0 = Release|Any CPU
{F2EA8A47-C7B6-4C2B-8AD0-0F3C0C24DF74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2EA8A47-C7B6-4C2B-8AD0-0F3C0C24DF74}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2EA8A47-C7B6-4C2B-8AD0-0F3C0C24DF74}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2EA8A47-C7B6-4C2B-8AD0-0F3C0C24DF74}.Release|Any CPU.Build.0 = Release|Any CPU
{41FABDF9-049F-447C-B3D5-D9739D852E7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41FABDF9-049F-447C-B3D5-D9739D852E7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41FABDF9-049F-447C-B3D5-D9739D852E7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41FABDF9-049F-447C-B3D5-D9739D852E7C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,80 @@
using StorehouseContracts.BindingModels;
using StorehouseContracts.SearchModels;
using StorehouseContracts.StoragesContracts;
using StorehouseContracts.ViewModels;
using StorehouseDatabaseImplement.Models;
namespace StorehouseDatabaseImplement.Implements
{
public class ClientStorage : IClientStorage
{
public ClientViewModel? GetElement(ClientSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
using var context = new StorehouseDatabase();
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 StorehouseDatabase();
return context.Clients
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ClientViewModel> GetFullList()
{
using var context = new StorehouseDatabase();
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 StorehouseDatabase();
context.Clients.Add(newClient);
context.SaveChanges();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
using var context = new StorehouseDatabase();
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 StorehouseDatabase();
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

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StorehouseDatabaseImplement.Implements
{
internal class ProductStorage
{
}
}

View File

@ -0,0 +1,80 @@
using StorehouseContracts.BindingModels;
using StorehouseContracts.SearchModels;
using StorehouseContracts.StoragesContracts;
using StorehouseContracts.ViewModels;
using StorehouseDatabaseImplement.Models;
namespace StorehouseDatabaseImplement.Implements
{
public class ProviderStorage : IProviderStorage
{
public ProviderViewModel? GetElement(ProviderSearchModel model)
{
if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue)
{
return null;
}
using var context = new StorehouseDatabase();
return context.Providers.FirstOrDefault(x =>
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email)
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<ProviderViewModel> GetFilteredList(ProviderSearchModel model)
{
if (string.IsNullOrEmpty(model.Email))
{
return new();
}
using var context = new StorehouseDatabase();
return context.Providers
.Where(x => x.Email.Contains(model.Email))
.Select(x => x.GetViewModel)
.ToList();
}
public List<ProviderViewModel> GetFullList()
{
using var context = new StorehouseDatabase();
return context.Providers.Select(x => x.GetViewModel).ToList();
}
public ProviderViewModel? Insert(ProviderBindingModel model)
{
var newProvider = Provider.Create(model);
if (newProvider == null)
{
return null;
}
using var context = new StorehouseDatabase();
context.Providers.Add(newProvider);
context.SaveChanges();
return newProvider.GetViewModel;
}
public ProviderViewModel? Update(ProviderBindingModel model)
{
using var context = new StorehouseDatabase();
var provider = context.Providers.FirstOrDefault(x => x.Id == model.Id);
if (provider == null)
{
return null;
}
provider.Update(model);
context.SaveChanges();
return provider.GetViewModel;
}
public ProviderViewModel? Delete(ProviderBindingModel model)
{
using var context = new StorehouseDatabase();
var provider = context.Providers.FirstOrDefault(x => x.Id == model.Id);
if (provider == null)
{
return null;
}
context.Providers.Remove(provider);
context.SaveChanges();
return provider.GetViewModel;
}
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StorehouseDatabaseImplement.Implements
{
internal class SaleStorage
{
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StorehouseDatabaseImplement.Implements
{
internal class SupplyStorage
{
}
}

View File

@ -0,0 +1,56 @@
using StorehouseContracts.BindingModels;
using StorehouseContracts.StoragesContracts;
using StorehouseContracts.ViewModels;
using StorehouseDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace StorehouseDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; set; }
[Required]
public string? ClientFIO { get; set; } = string.Empty;
[Required]
public string? Email { get; set; } = string.Empty;
[Required]
public string? Password { get; set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Sale> Sales { 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,58 @@
using StorehouseContracts.BindingModels;
using StorehouseContracts.ViewModels;
using StorehouseDataModels.Enums;
using StorehouseDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace StorehouseDatabaseImplement.Models
{
public class Product : IProductModel
{
public int Id { get; set; }
[Required]
public string? ProductName { get; set; } = string.Empty;
[Required]
public int ProductNum { get; set; }
[Required]
public ProductType ProductType { get; set; } = ProductType.Неизвестен;
[ForeignKey("ProductId")]
public virtual List<Sale> Sales { get; set; } = new();
[ForeignKey("ProductId")]
public virtual List<Supply> Supplys { get; set; } = new();
public static Product? Create(ProductBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ProductName = model.ProductName,
ProductNum = model.ProductNum,
ProductType = model.ProductType,
};
}
public void Update(ProductBindingModel model)
{
if (model == null)
{
return;
}
ProductName = model.ProductName;
ProductNum = model.ProductNum;
ProductType = model.ProductType;
}
public ProductViewModel GetViewModel => new()
{
Id = Id,
ProductName = ProductName,
ProductNum = ProductNum,
ProductType = ProductType,
};
}
}

View File

@ -0,0 +1,55 @@
using StorehouseContracts.BindingModels;
using StorehouseContracts.ViewModels;
using StorehouseDataModels.Models;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace StorehouseDatabaseImplement.Models
{
public class Provider : IProviderModel
{
public int Id { get; set; }
[Required]
public string? ProviderFIO { get; set; } = string.Empty;
[Required]
public string? Email { get; set; } = string.Empty;
[Required]
public string? Password { get; set; } = string.Empty;
[ForeignKey("ProviderId")]
public virtual List<Supply> Supplys { get; set; } = new();
public static Provider? Create(ProviderBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ProviderFIO = model.ProviderFIO,
Email = model.Email,
Password = model.Password
};
}
public void Update(ProviderBindingModel model)
{
if (model == null)
{
return;
}
ProviderFIO = model.ProviderFIO;
Email = model.Email;
Password = model.Password;
}
public ProviderViewModel GetViewModel => new()
{
Id = Id,
ProviderFIO = ProviderFIO,
Email = Email,
Password = Password,
};
}
}

View File

@ -0,0 +1,57 @@
using StorehouseContracts.BindingModels;
using StorehouseContracts.ViewModels;
using StorehouseDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace StorehouseDatabaseImplement.Models
{
public class Sale : ISaleModel
{
public int Id { get; set; }
[Required]
public int ClientId { get; set; }
[Required]
public int ProductId { get; set; }
[Required]
public int SaleNum { get; set; }
public virtual Client Client { get; set; }
public virtual Product Product { get; set; }
public static Sale? Create(SaleBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ClientId = model.ClientId,
ProductId = model.ProductId,
SaleNum = model.SaleNum,
};
}
public void Update(SaleBindingModel model)
{
if (model == null)
{
return;
}
ClientId = model.ClientId;
ProductId = model.ProductId;
SaleNum = model.SaleNum;
}
public SaleViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ClientFIO = Client.ClientFIO,
ProductId = ProductId,
ProductName = Product.ProductName,
SaleNum = SaleNum,
};
}
}

View File

@ -0,0 +1,57 @@
using StorehouseContracts.BindingModels;
using StorehouseContracts.ViewModels;
using StorehouseDataModels.Models;
using System.ComponentModel.DataAnnotations;
namespace StorehouseDatabaseImplement.Models
{
public class Supply : ISupplyModel
{
public int Id { get; set; }
[Required]
public int ProviderId { get; set; }
[Required]
public int ProductId { get; set; }
[Required]
public int SupplyNum { get; set; }
public virtual Provider Provider { get; set; }
public virtual Product Product { get; set; }
public static Supply? Create(SupplyBindingModel model)
{
if (model == null)
{
return null;
}
return new()
{
Id = model.Id,
ProviderId = model.ProviderId,
ProductId = model.ProductId,
SupplyNum = model.SupplyNum,
};
}
public void Update(SupplyBindingModel model)
{
if (model == null)
{
return;
}
ProviderId = model.ProviderId;
ProductId = model.ProductId;
SupplyNum = model.SupplyNum;
}
public SupplyViewModel GetViewModel => new()
{
Id = Id,
ProviderId = ProviderId,
ProviderFIO = Provider.ProviderFIO,
ProductId = ProductId,
ProductName = Product.ProductName,
SupplyNum = SupplyNum,
};
}
}

View File

@ -0,0 +1,22 @@
using Microsoft.EntityFrameworkCore;
using StorehouseDatabaseImplement.Models;
namespace StorehouseDatabaseImplement
{
public class StorehouseDatabase : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=StorehouseDatabaseFull;Integrated Security=True;MultipleActiveResultSets=True;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}
public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<Product> Products { set; get; }
public virtual DbSet<Provider> Providers { set; get; }
public virtual DbSet<Sale> Sales { set; get; }
public virtual DbSet<Supply> Supplys { set; get; }
}
}

View File

@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.18" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.18" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.18">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\StorehouseContracts\StorehouseContracts.csproj" />
<ProjectReference Include="..\StorehouseDataModels\StorehouseDataModels.csproj" />
</ItemGroup>
</Project>