Монга работает ⸜(。˃ ᵕ ˂)⸝
This commit is contained in:
parent
cb96c3be39
commit
8682baa376
@ -3,15 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34714.143
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarView", "SushiBar\SushiBarView.csproj", "{2B4A5A98-6D06-4461-8D41-363CED12B9C2}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarView", "SushiBar\SushiBarView.csproj", "{2B4A5A98-6D06-4461-8D41-363CED12B9C2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{C373ED9F-747E-47D0-9B7C-B65E062CD537}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDataModels", "SushiBarDataModels\SushiBarDataModels.csproj", "{C373ED9F-747E-47D0-9B7C-B65E062CD537}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1FD289B3-1422-4535-8969-2F320754517B}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarContracts", "SushiBarContracts\SushiBarContracts.csproj", "{1FD289B3-1422-4535-8969-2F320754517B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarBusinessLogic", "SushiBarBusinessLogic\SushiBarBusinessLogic.csproj", "{9CB0FFA6-FA25-440C-8B6A-B6DF2F0639F5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{E62F051D-30D6-4F1C-B02E-C814B7D03F86}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SushiBarDatabaseImplement", "SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj", "{E62F051D-30D6-4F1C-B02E-C814B7D03F86}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SushiBarMongoDB", "SushiBarMongoDB\SushiBarMongoDB.csproj", "{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -39,6 +41,10 @@ Global
|
||||
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E62F051D-30D6-4F1C-B02E-C814B7D03F86}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5D2CA124-F7FE-4654-B3F2-D9A09EB079EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -176,16 +176,23 @@ namespace SushiBarView
|
||||
}
|
||||
try
|
||||
{
|
||||
List<int> ids = new List<int>();
|
||||
foreach (int id in _taskMenu.Keys)
|
||||
{
|
||||
ids.Add(id);
|
||||
}
|
||||
|
||||
var model = new TaskBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
TaskDate = DateTime.Now,
|
||||
Status = SushiBarDataModels.Enum.TaskStatus.Принят,
|
||||
FullPrice = CalcPrice(),
|
||||
CookId = comboBoxCook.SelectedIndex+1,
|
||||
BuyerId = comboBoxBuyer.SelectedIndex+1,
|
||||
PlaceId = comboBoxPlace.SelectedIndex + 1,
|
||||
TaskMenus = _taskMenu
|
||||
CookId = comboBoxCook.SelectedIndex,
|
||||
BuyerId = comboBoxBuyer.SelectedIndex,
|
||||
PlaceId = comboBoxPlace.SelectedIndex,
|
||||
TaskMenus = _taskMenu,
|
||||
MenuIds = ids,
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logicT.Update(model) : _logicT.Create(model);
|
||||
if (!operationResult)
|
||||
|
@ -3,7 +3,8 @@ using Microsoft.Extensions.Logging;
|
||||
using SushiBarBusinessLogic.BusinessLogics;
|
||||
using SushiBarContracts.BusinessLogicContracts;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarDatabaseImplement.Implements;
|
||||
//using SushiBarDatabaseImplement.Implements;
|
||||
using SushiBarMongoDB.Implements;
|
||||
using SushiBarView;
|
||||
|
||||
namespace SushiBar
|
||||
|
@ -23,6 +23,7 @@
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
<ProjectReference Include="..\SushiBarDatabaseImplement\SushiBarDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
|
||||
<ProjectReference Include="..\SushiBarMongoDB\SushiBarMongoDB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -23,6 +23,8 @@ namespace SushiBarContracts.BindingModels
|
||||
|
||||
public int BuyerId { get; set; }
|
||||
|
||||
public List<int> MenuIds { get; set; } = new List<int>();
|
||||
|
||||
public Dictionary<int, (IMenuModel, int)> TaskMenus { get; set; } = new();
|
||||
|
||||
}
|
||||
|
110
SushiBar/SushiBarMongoDB/Implements/BuyerStorage.cs
Normal file
110
SushiBar/SushiBarMongoDB/Implements/BuyerStorage.cs
Normal file
@ -0,0 +1,110 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarMongoDB.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarMongoDB.Implements
|
||||
{
|
||||
public class BuyerStorage : IBuyerStorage
|
||||
{
|
||||
|
||||
public void ClearEntity()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
context.GetCollection<Buyer>("Buyers")
|
||||
.DeleteMany(Builders<Buyer>.Filter.Empty);
|
||||
}
|
||||
|
||||
public List<BuyerViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var buyers = context.GetCollection<Buyer>("Buyers");
|
||||
return buyers.Find(Builders<Buyer>.Filter.Empty)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<BuyerViewModel> GetFilteredList(BuyerSearchModel model)
|
||||
{
|
||||
if(string.IsNullOrEmpty(model.BuyerName)) return new List<BuyerViewModel>();
|
||||
using var context = new SushiBarMongoDB();
|
||||
var buyers = context.GetCollection<Buyer>("Buyers");
|
||||
|
||||
var filterBuilder = Builders<Buyer>.Filter;
|
||||
var filter = filterBuilder.Regex(x => x.BuyerName, new BsonRegularExpression(model.BuyerName));
|
||||
return buyers
|
||||
.Find(filter)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public BuyerViewModel? GetElement(BuyerSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new SushiBarMongoDB())
|
||||
{
|
||||
var buyers = context.GetCollection<Buyer>("Buyers");
|
||||
|
||||
var filterBuilder = Builders<Buyer>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.Id, model.Id);
|
||||
}
|
||||
|
||||
return buyers.Find(filter)
|
||||
.FirstOrDefault()
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
public BuyerViewModel? Insert(BuyerBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
|
||||
var buyers = context.GetCollection<Buyer>("Buyers");
|
||||
|
||||
model.Id = (int)buyers.CountDocuments(FilterDefinition<Buyer>.Empty);
|
||||
|
||||
var buyer = Buyer.Create(model);
|
||||
buyers.InsertOne(buyer);
|
||||
return buyer.GetViewModel;
|
||||
}
|
||||
public BuyerViewModel? Update(BuyerBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var buyers = context.GetCollection<Buyer>("Buyers");
|
||||
|
||||
var filter = Builders<Buyer>.Filter.Eq(x => x.Id, model.Id);
|
||||
var buyer = buyers.Find(filter).FirstOrDefault();
|
||||
if (buyer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
buyer.Update(model);
|
||||
buyers.ReplaceOne(filter, buyer);
|
||||
return buyer.GetViewModel;
|
||||
}
|
||||
public BuyerViewModel? Delete(BuyerBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var categories = context.GetCollection<Buyer>("Buyers");
|
||||
|
||||
var filter = Builders<Buyer>.Filter.Eq(x => x.Id, model.Id);
|
||||
var category = categories.FindOneAndDelete(filter);
|
||||
return category?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
106
SushiBar/SushiBarMongoDB/Implements/CookStorage.cs
Normal file
106
SushiBar/SushiBarMongoDB/Implements/CookStorage.cs
Normal file
@ -0,0 +1,106 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarMongoDB.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarMongoDB.Implements
|
||||
{
|
||||
public class CookStorage : ICookStorage
|
||||
{
|
||||
public List<CookViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var cooks = context.GetCollection<Cook>("Cooks");
|
||||
return cooks.Find(Builders<Cook>.Filter.Empty)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<CookViewModel> GetFilteredList(CookSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.CookName))
|
||||
{
|
||||
return new List<CookViewModel>();
|
||||
}
|
||||
using var context = new SushiBarMongoDB();
|
||||
var cooks = context.GetCollection<Cook>("Cooks");
|
||||
|
||||
var filterBuilder = Builders<Cook>.Filter;
|
||||
var filter = filterBuilder
|
||||
.Regex(x => x.CookName, new BsonRegularExpression(model.CookName));
|
||||
return cooks
|
||||
.Find(filter)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CookViewModel? GetElement(CookSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new SushiBarMongoDB())
|
||||
{
|
||||
var cooks = context.GetCollection<Cook>("Cooks");
|
||||
|
||||
var filterBuilder = Builders<Cook>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.Id, model.Id);
|
||||
}
|
||||
|
||||
return cooks.Find(filter)
|
||||
.FirstOrDefault()
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
public CookViewModel? Insert(CookBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
|
||||
var cooks = context.GetCollection<Cook>("Cooks");
|
||||
|
||||
model.Id = (int)cooks.CountDocuments(FilterDefinition<Cook>.Empty);
|
||||
|
||||
var cook = Cook.Create(model);
|
||||
cooks.InsertOne(cook);
|
||||
return cook.GetViewModel;
|
||||
}
|
||||
public CookViewModel? Update(CookBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var cooks = context.GetCollection<Cook>("Cooks");
|
||||
|
||||
var filter = Builders<Cook>.Filter.Eq(x => x.Id, model.Id);
|
||||
var cook = cooks.Find(filter).FirstOrDefault();
|
||||
if (cook == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
cook.Update(model);
|
||||
cooks.ReplaceOne(filter, cook);
|
||||
return cook.GetViewModel;
|
||||
}
|
||||
public CookViewModel? Delete(CookBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var cooks = context.GetCollection<Cook>("Cooks");
|
||||
|
||||
var filter = Builders<Cook>.Filter.Eq(x => x.Id, model.Id);
|
||||
var cook = cooks.FindOneAndDelete(filter);
|
||||
return cook?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
116
SushiBar/SushiBarMongoDB/Implements/MenuStorage.cs
Normal file
116
SushiBar/SushiBarMongoDB/Implements/MenuStorage.cs
Normal file
@ -0,0 +1,116 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarMongoDB.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarMongoDB.Implements
|
||||
{
|
||||
public class MenuStorage : IMenuStorage
|
||||
{
|
||||
public void ClearEntity()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
context.GetCollection<Menu>("Menus")
|
||||
.DeleteMany(Builders<Menu>.Filter.Empty);
|
||||
}
|
||||
public MenuViewModel? GetElement(MenuSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new SushiBarMongoDB())
|
||||
{
|
||||
var menus = context.GetCollection<Menu>("Menus");
|
||||
|
||||
var filterBuilder = Builders<Menu>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.Id, model.Id);
|
||||
}
|
||||
|
||||
return menus.Find(filter)
|
||||
.FirstOrDefault()
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<MenuViewModel> GetFilteredList(MenuSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.FoodName))
|
||||
{
|
||||
return new List<MenuViewModel>();
|
||||
}
|
||||
using var context = new SushiBarMongoDB();
|
||||
var menus = context.GetCollection<Menu>("Menus");
|
||||
|
||||
var filterBuilder = Builders<Menu>.Filter;
|
||||
var filter = filterBuilder
|
||||
.Regex(x => x.FoodName, new BsonRegularExpression(model.FoodName));
|
||||
return menus
|
||||
.Find(filter)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MenuViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var menus = context.GetCollection<Menu>("Menus");
|
||||
return menus.Find(Builders<Menu>.Filter.Empty)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MenuViewModel? Insert(MenuBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
|
||||
var menus = context.GetCollection<Menu>("Menus");
|
||||
|
||||
model.Id = (int)menus.CountDocuments(FilterDefinition<Menu>.Empty);
|
||||
|
||||
var menu = Menu.Create(model);
|
||||
menus.InsertOne(menu);
|
||||
return menu.GetViewModel;
|
||||
}
|
||||
|
||||
public MenuViewModel? Update(MenuBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var menus = context.GetCollection<Menu>("Menus");
|
||||
|
||||
var filter = Builders<Menu>.Filter.Eq(x => x.Id, model.Id);
|
||||
var menu = menus.Find(filter).FirstOrDefault();
|
||||
if (menu == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
menu.Update(model);
|
||||
menus.ReplaceOne(filter, menu);
|
||||
return menu.GetViewModel;
|
||||
}
|
||||
|
||||
public MenuViewModel? Delete(MenuBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var menus = context.GetCollection<Menu>("Menus");
|
||||
|
||||
var filter = Builders<Menu>.Filter.Eq(x => x.Id, model.Id);
|
||||
var menu = menus.FindOneAndDelete(filter);
|
||||
return menu?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
115
SushiBar/SushiBarMongoDB/Implements/PlaceStorage.cs
Normal file
115
SushiBar/SushiBarMongoDB/Implements/PlaceStorage.cs
Normal file
@ -0,0 +1,115 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarMongoDB.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarMongoDB.Implements
|
||||
{
|
||||
public class PlaceStorage : IPlaceStorage
|
||||
{
|
||||
public void ClearEntity()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
context.GetCollection<Place>("Places")
|
||||
.DeleteMany(Builders<Place>.Filter.Empty);
|
||||
}
|
||||
|
||||
public PlaceViewModel? GetElement(PlaceSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using (var context = new SushiBarMongoDB())
|
||||
{
|
||||
var places = context.GetCollection<Place>("Places");
|
||||
|
||||
var filterBuilder = Builders<Place>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
filter &= filterBuilder.Eq(x => x.Id, model.Id);
|
||||
}
|
||||
|
||||
return places.Find(filter)
|
||||
.FirstOrDefault()
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public List<PlaceViewModel> GetFilteredList(PlaceSearchModel model)
|
||||
{
|
||||
if (!model.PlaceNumber.HasValue)
|
||||
{
|
||||
return new List<PlaceViewModel>();
|
||||
}
|
||||
using var context = new SushiBarMongoDB();
|
||||
var places = context.GetCollection<Place>("Places");
|
||||
|
||||
var filter = Builders<Place>.Filter.Eq(x => x.Id, model.Id);
|
||||
return places
|
||||
.Find(filter)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PlaceViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var places = context.GetCollection<Place>("Places");
|
||||
return places.Find(Builders<Place>.Filter.Empty)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public PlaceViewModel? Insert(PlaceBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
|
||||
var places = context.GetCollection<Place>("Places");
|
||||
|
||||
model.Id = (int)places.CountDocuments(FilterDefinition<Place>.Empty);
|
||||
|
||||
var place = Place.Create(model);
|
||||
places.InsertOne(place);
|
||||
return place.GetViewModel;
|
||||
}
|
||||
|
||||
public PlaceViewModel? Update(PlaceBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var places = context.GetCollection<Place>("Places");
|
||||
|
||||
var filter = Builders<Place>.Filter.Eq(x => x.Id, model.Id);
|
||||
var place = places.Find(filter).FirstOrDefault();
|
||||
if (place == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
place.Update(model);
|
||||
places.ReplaceOne(filter, place);
|
||||
return place.GetViewModel;
|
||||
}
|
||||
|
||||
public PlaceViewModel? Delete(PlaceBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var places = context.GetCollection<Place>("Places");
|
||||
|
||||
var filter = Builders<Place>.Filter.Eq(x => x.Id, model.Id);
|
||||
var place = places.FindOneAndDelete(filter);
|
||||
return place?.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
89
SushiBar/SushiBarMongoDB/Implements/TaskStorage.cs
Normal file
89
SushiBar/SushiBarMongoDB/Implements/TaskStorage.cs
Normal file
@ -0,0 +1,89 @@
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Driver;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.SearchModels;
|
||||
using SushiBarContracts.StoragesContracts;
|
||||
using SushiBarContracts.ViewModels;
|
||||
using SushiBarMongoDB.Models;
|
||||
using System.Xml;
|
||||
using Task = SushiBarMongoDB.Models.Task;
|
||||
|
||||
namespace SushiBarMongoDB.Implements
|
||||
{
|
||||
public class TaskStorage : ITaskStorage
|
||||
{
|
||||
|
||||
public void ClearEntity()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
context.GetCollection<Task>("Tasks")
|
||||
.DeleteMany(Builders<Task>.Filter.Empty);
|
||||
}
|
||||
|
||||
public List<TaskViewModel> GetFullList()
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var tasks = context.GetCollection<Task>("Tasks").Find(Builders<Task>.Filter.Empty).ToList();
|
||||
|
||||
return tasks.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<TaskViewModel> GetFilteredList(TaskSearchModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
if(!model.Id.HasValue) return new List<TaskViewModel>();
|
||||
|
||||
var filterBuilder = Builders<Task>.Filter;
|
||||
var filter = filterBuilder.Empty;
|
||||
filter = filterBuilder.Eq("Id", model.Id);
|
||||
|
||||
var tasks = context.GetCollection<Task>("Tasks").Find(filter).ToList();
|
||||
|
||||
return tasks.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public TaskViewModel? GetElement(TaskSearchModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var tasks = context.GetCollection<Task>("Tasks");
|
||||
if (!model.Id.HasValue) return null;
|
||||
return tasks.Find(x => x.Id == model.Id).FirstOrDefault()?.GetViewModel;
|
||||
}
|
||||
public TaskViewModel? Insert(TaskBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
|
||||
|
||||
var tasks = context.GetCollection<Task>("Tasks");
|
||||
|
||||
model.Id = (int)tasks.CountDocuments(FilterDefinition<Task>.Empty);
|
||||
|
||||
var newTask = Task.Create(model);
|
||||
|
||||
if (newTask == null) return null;
|
||||
|
||||
|
||||
tasks.InsertOne(newTask);
|
||||
return newTask.GetViewModel;
|
||||
}
|
||||
public TaskViewModel? Update(TaskBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var task = context.GetCollection<Task>("Tasks").Find(x => x.Id == model.Id).FirstOrDefault();
|
||||
if (task == null) return null;
|
||||
task.Update(model);
|
||||
context.GetCollection<Task>("Tasks").ReplaceOne(x => x.Id == model.Id, task);
|
||||
return task.GetViewModel;
|
||||
}
|
||||
public TaskViewModel? Delete(TaskBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarMongoDB();
|
||||
var element = context.GetCollection<Task>("Tasks").Find(x => x.Id == model.Id).FirstOrDefault();
|
||||
if (element != null)
|
||||
{
|
||||
context.GetCollection<Task>("Tasks").DeleteOne(x => x.Id == model.Id);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
53
SushiBar/SushiBarMongoDB/Models/Buyer.cs
Normal file
53
SushiBar/SushiBarMongoDB/Models/Buyer.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using SushiBarDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarMongoDB.Models
|
||||
{
|
||||
public class Buyer : IBuyerModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public string BuyerName { get; set; } = string.Empty;
|
||||
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public DateTime? BuyerBirthDate { get; set; }
|
||||
|
||||
public static Buyer? Create(BuyerBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Buyer()
|
||||
{
|
||||
Id = model.Id,
|
||||
BuyerName = model.BuyerName,
|
||||
BuyerBirthDate = model.BuyerBirthDate,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(BuyerBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
Id = model.Id;
|
||||
BuyerName = model.BuyerName;
|
||||
BuyerBirthDate = model.BuyerBirthDate;
|
||||
}
|
||||
|
||||
public BuyerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
BuyerName = BuyerName,
|
||||
BuyerBirthDate = BuyerBirthDate,
|
||||
};
|
||||
}
|
||||
}
|
70
SushiBar/SushiBarMongoDB/Models/Cook.cs
Normal file
70
SushiBar/SushiBarMongoDB/Models/Cook.cs
Normal file
@ -0,0 +1,70 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using SushiBarDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarMongoDB.Models
|
||||
{
|
||||
public class Cook : ICookModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public string CookName { get; set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
public string CookSurname { get; set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
public int Experience { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public string PhoneNumber { get; set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
public string Passport { get; set; } = string.Empty;
|
||||
|
||||
public static Cook? Create(CookBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Cook()
|
||||
{
|
||||
Id = model.Id,
|
||||
CookName = model.CookName,
|
||||
CookSurname = model.CookSurname,
|
||||
Experience = model.Experience,
|
||||
PhoneNumber = model.PhoneNumber,
|
||||
Passport = model.Passport,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(CookBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
Id = model.Id;
|
||||
CookName = model.CookName;
|
||||
CookSurname = model.CookSurname;
|
||||
Experience = model.Experience;
|
||||
PhoneNumber = model.PhoneNumber;
|
||||
Passport = model.Passport;
|
||||
}
|
||||
|
||||
public CookViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
CookName = CookName,
|
||||
CookSurname = CookSurname,
|
||||
Experience = Experience,
|
||||
PhoneNumber = PhoneNumber,
|
||||
Passport = Passport
|
||||
};
|
||||
}
|
||||
}
|
58
SushiBar/SushiBarMongoDB/Models/Menu.cs
Normal file
58
SushiBar/SushiBarMongoDB/Models/Menu.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using SushiBarDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarMongoDB.Models
|
||||
{
|
||||
public class Menu : IMenuModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public string FoodName { get; set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
public string Description { get; set; } = string.Empty;
|
||||
|
||||
[BsonRequired]
|
||||
public double Price { get; set; }
|
||||
|
||||
public static Menu? Create(MenuBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Menu()
|
||||
{
|
||||
Id = model.Id,
|
||||
FoodName = model.FoodName,
|
||||
Description = model.Description,
|
||||
Price = model.Price,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(MenuBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
Id = model.Id;
|
||||
FoodName = model.FoodName;
|
||||
Description = model.Description;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public MenuViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
FoodName = FoodName,
|
||||
Description = Description,
|
||||
Price = Price,
|
||||
};
|
||||
}
|
||||
}
|
52
SushiBar/SushiBarMongoDB/Models/Place.cs
Normal file
52
SushiBar/SushiBarMongoDB/Models/Place.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using SushiBarDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarMongoDB.Models
|
||||
{
|
||||
public class Place : IPlaceModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public int PlaceNumber { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public int CountPlaces { get; set; }
|
||||
|
||||
public static Place? Create(PlaceBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Place()
|
||||
{
|
||||
Id = model.Id,
|
||||
PlaceNumber = model.PlaceNumber,
|
||||
CountPlaces = model.CountPlaces,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(PlaceBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
Id = model.Id;
|
||||
PlaceNumber = model.PlaceNumber;
|
||||
CountPlaces = model.CountPlaces;
|
||||
}
|
||||
|
||||
public PlaceViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PlaceNumber = PlaceNumber,
|
||||
CountPlaces = CountPlaces,
|
||||
};
|
||||
}
|
||||
}
|
95
SushiBar/SushiBarMongoDB/Models/Task.cs
Normal file
95
SushiBar/SushiBarMongoDB/Models/Task.cs
Normal file
@ -0,0 +1,95 @@
|
||||
using MongoDB.Bson.Serialization.Attributes;
|
||||
using MongoDB.Bson;
|
||||
using SushiBarDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SushiBarContracts.BindingModels;
|
||||
using SushiBarContracts.ViewModels;
|
||||
|
||||
namespace SushiBarMongoDB.Models
|
||||
{
|
||||
public class Task : ITaskModel
|
||||
{
|
||||
[BsonId]
|
||||
[BsonElement("_id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public DateTime TaskDate { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public SushiBarDataModels.Enum.TaskStatus Status { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
public double FullPrice { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("place_id")]
|
||||
public int PlaceId { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("cook_id")]
|
||||
public int CookId { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("buyer_id")]
|
||||
public int BuyerId { get; set; }
|
||||
|
||||
[BsonRequired]
|
||||
[BsonElement("menu_ids")]
|
||||
public List<int> MenuIds { get; set; } = new List<int>();
|
||||
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public virtual Place Place { get; set; }
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public virtual Cook Cook { get; set; }
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public virtual Buyer Buyer { get; set; }
|
||||
[BsonIgnoreIfNull]
|
||||
[BsonIgnoreIfDefault]
|
||||
public virtual List<Menu> Menus { get; set; }
|
||||
|
||||
[BsonIgnore]
|
||||
public Dictionary<int, (IMenuModel, int)> TaskMenus { get; set; } = new Dictionary<int, (IMenuModel, int)>();
|
||||
|
||||
public static Task? Create(TaskBindingModel model)
|
||||
{
|
||||
if (model == null) return null;
|
||||
return new Task()
|
||||
{
|
||||
Id = model.Id,
|
||||
TaskDate = model.TaskDate,
|
||||
Status = model.Status,
|
||||
FullPrice = model.FullPrice,
|
||||
PlaceId = model.PlaceId,
|
||||
CookId = model.CookId,
|
||||
BuyerId = model.BuyerId,
|
||||
MenuIds = model.MenuIds,
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(TaskBindingModel model)
|
||||
{
|
||||
if (model == null) return;
|
||||
Status = model.Status;
|
||||
|
||||
}
|
||||
|
||||
public TaskViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
TaskDate = TaskDate,
|
||||
Status = Status,
|
||||
FullPrice = FullPrice,
|
||||
PlaceId = PlaceId,
|
||||
CookId = CookId,
|
||||
BuyerId = BuyerId,
|
||||
};
|
||||
}
|
||||
}
|
28
SushiBar/SushiBarMongoDB/SushiBarMongoDB.cs
Normal file
28
SushiBar/SushiBarMongoDB/SushiBarMongoDB.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SushiBarMongoDB
|
||||
{
|
||||
public class SushiBarMongoDB : IDisposable
|
||||
{
|
||||
private readonly MongoClient _client;
|
||||
private readonly IMongoDatabase _database;
|
||||
|
||||
public SushiBarMongoDB(string connectionString = "mongodb://localhost:27017", string databaseName = "lab8SUBD")
|
||||
{
|
||||
_client = new MongoClient(connectionString);
|
||||
_database = _client.GetDatabase(databaseName);
|
||||
}
|
||||
|
||||
public IMongoCollection<T> GetCollection<T>(string collectionName)
|
||||
{
|
||||
return _database.GetCollection<T>(collectionName);
|
||||
}
|
||||
|
||||
public void Dispose() { }
|
||||
}
|
||||
}
|
24
SushiBar/SushiBarMongoDB/SushiBarMongoDB.csproj
Normal file
24
SushiBar/SushiBarMongoDB/SushiBarMongoDB.csproj
Normal file
@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Bogus" Version="35.5.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.2" />
|
||||
<PackageReference Include="MongoDB.Bson" Version="2.25.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
|
||||
<PackageReference Include="MongoDB.Driver.Core" Version="2.25.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SushiBarBusinessLogic\SushiBarBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\SushiBarContracts\SushiBarContracts.csproj" />
|
||||
<ProjectReference Include="..\SushiBarDataModels\SushiBarDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user