Арбайтен
This commit is contained in:
parent
63cc7ab010
commit
7f8a42d8db
@ -9,9 +9,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarberShopContracts", "Barb
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarberShopBusinessLogic", "BarberShopBusinessLogic\BarberShopBusinessLogic.csproj", "{0BA98D0D-1658-4553-8A5E-B1B0D70E57F8}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarberShopBusinessLogic", "BarberShopBusinessLogic\BarberShopBusinessLogic.csproj", "{0BA98D0D-1658-4553-8A5E-B1B0D70E57F8}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarberShopDatabaseImplement", "BarberShopDatabaseImplement\BarberShopDatabaseImplement.csproj", "{DC52AF5A-EB87-450B-830B-FFB687A7C648}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarberShopDatabaseImplement", "BarberShopDatabaseImplement\BarberShopDatabaseImplement.csproj", "{DC52AF5A-EB87-450B-830B-FFB687A7C648}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarberShop", "BarberShop\BarberShop.csproj", "{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BarberShop", "BarberShop\BarberShop.csproj", "{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BarberShopMongoDBImplement", "BarberShopMongoDBImplement\BarberShopMongoDBImplement.csproj", "{5294E6AD-6F62-4954-BECD-6CA058047D5C}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -39,6 +41,10 @@ Global
|
|||||||
{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{2B918C3D-6A78-41FE-866C-6C884E0A0C5E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{5294E6AD-6F62-4954-BECD-6CA058047D5C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5294E6AD-6F62-4954-BECD-6CA058047D5C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5294E6AD-6F62-4954-BECD-6CA058047D5C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5294E6AD-6F62-4954-BECD-6CA058047D5C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0-windows</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\BarberShopContracts\BarberShopContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\BarberShopDatabaseImplement\BarberShopDatabaseImplement.csproj" />
|
||||||
|
<ProjectReference Include="..\BArberShopDataModels\BarberShopDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,21 @@
|
|||||||
|
using MongoDB.Driver;
|
||||||
|
|
||||||
|
namespace BarberShopMongoDBImplement
|
||||||
|
{
|
||||||
|
public class BarberShopMongoDatabase
|
||||||
|
{
|
||||||
|
public static BarberShopMongoDatabase? instance;
|
||||||
|
public MongoClient client;
|
||||||
|
private BarberShopMongoDatabase()
|
||||||
|
{ client = new MongoClient("mongodb://localhost:27017"); }
|
||||||
|
|
||||||
|
public static BarberShopMongoDatabase getInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new BarberShopMongoDatabase();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
109
BarberShop/BarberShopMongoDBImplement/clientStorage.cs
Normal file
109
BarberShop/BarberShopMongoDBImplement/clientStorage.cs
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
using BarberShopContracts.BindingModels;
|
||||||
|
using BarberShopContracts.SearchModels;
|
||||||
|
using BarberShopContracts.StorageContracts;
|
||||||
|
using BarberShopContracts.ViewModels;
|
||||||
|
using BarberShopDatabaseImplement.Models;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace BarberShopMongoDBImplement
|
||||||
|
{
|
||||||
|
public class clientStorage : IClientStorage
|
||||||
|
{
|
||||||
|
readonly IMongoCollection<Client> _collection;
|
||||||
|
public MongoClient context;
|
||||||
|
|
||||||
|
public clientStorage()
|
||||||
|
{
|
||||||
|
context = BarberShopMongoDatabase.getInstance().client;
|
||||||
|
_collection = context.GetDatabase("Lab7").GetCollection<Client>("client");
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ClientViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var client = _collection.Find(_ => true)
|
||||||
|
.ToList()
|
||||||
|
.Select(a => a.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return client;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
var filter = Builders<Client>.Filter.Empty;
|
||||||
|
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
{
|
||||||
|
filter &= Builders<Client>.Filter.Eq(a => a.Id, model.Id.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new List<ClientViewModel>();
|
||||||
|
}
|
||||||
|
|
||||||
|
var answers = _collection.Find(filter)
|
||||||
|
.ToList()
|
||||||
|
.Select(a => a.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return answers;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
return null;
|
||||||
|
var client = _collection.Find(x => x.Id == model.Id.Value).FirstOrDefault();
|
||||||
|
if (client == null)
|
||||||
|
return null;
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var client = Client.Create(model);
|
||||||
|
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_collection.InsertOne(client);
|
||||||
|
|
||||||
|
return client.GetViewModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var filter = Builders<Client>.Filter.Eq(a => a.Id, model.Id);
|
||||||
|
var athlete = _collection.Find(filter).FirstOrDefault();
|
||||||
|
|
||||||
|
athlete.Update(model);
|
||||||
|
_collection.ReplaceOne(filter, athlete);
|
||||||
|
|
||||||
|
return athlete.GetViewModel;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
var filter = Builders<Client>.Filter.Eq(a => a.Id, model.Id);
|
||||||
|
var client = _collection.FindOneAndDelete(filter);
|
||||||
|
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return client.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user