diff --git a/SushiBar/SushiBar.sln b/SushiBar/SushiBar.sln index f6ebf78..4798d73 100644 --- a/SushiBar/SushiBar.sln +++ b/SushiBar/SushiBar.sln @@ -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 diff --git a/SushiBar/SushiBar/FormCreateTask.cs b/SushiBar/SushiBar/FormCreateTask.cs index 9db435f..d009f0a 100644 --- a/SushiBar/SushiBar/FormCreateTask.cs +++ b/SushiBar/SushiBar/FormCreateTask.cs @@ -176,16 +176,23 @@ namespace SushiBarView } try { + List ids = new List(); + 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) diff --git a/SushiBar/SushiBar/Program.cs b/SushiBar/SushiBar/Program.cs index a05c4ed..5ae1313 100644 --- a/SushiBar/SushiBar/Program.cs +++ b/SushiBar/SushiBar/Program.cs @@ -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 diff --git a/SushiBar/SushiBar/SushiBarView.csproj b/SushiBar/SushiBar/SushiBarView.csproj index 1b30b29..8bd9784 100644 --- a/SushiBar/SushiBar/SushiBarView.csproj +++ b/SushiBar/SushiBar/SushiBarView.csproj @@ -23,6 +23,7 @@ + \ No newline at end of file diff --git a/SushiBar/SushiBarContracts/BindingModels/TaskBindingModel.cs b/SushiBar/SushiBarContracts/BindingModels/TaskBindingModel.cs index 1eb4e5d..c58205a 100644 --- a/SushiBar/SushiBarContracts/BindingModels/TaskBindingModel.cs +++ b/SushiBar/SushiBarContracts/BindingModels/TaskBindingModel.cs @@ -23,6 +23,8 @@ namespace SushiBarContracts.BindingModels public int BuyerId { get; set; } + public List MenuIds { get; set; } = new List(); + public Dictionary TaskMenus { get; set; } = new(); } diff --git a/SushiBar/SushiBarMongoDB/Implements/BuyerStorage.cs b/SushiBar/SushiBarMongoDB/Implements/BuyerStorage.cs new file mode 100644 index 0000000..4fb29c3 --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Implements/BuyerStorage.cs @@ -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("Buyers") + .DeleteMany(Builders.Filter.Empty); + } + + public List GetFullList() + { + using var context = new SushiBarMongoDB(); + var buyers = context.GetCollection("Buyers"); + return buyers.Find(Builders.Filter.Empty) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(BuyerSearchModel model) + { + if(string.IsNullOrEmpty(model.BuyerName)) return new List(); + using var context = new SushiBarMongoDB(); + var buyers = context.GetCollection("Buyers"); + + var filterBuilder = Builders.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("Buyers"); + + var filterBuilder = Builders.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("Buyers"); + + model.Id = (int)buyers.CountDocuments(FilterDefinition.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("Buyers"); + + var filter = Builders.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("Buyers"); + + var filter = Builders.Filter.Eq(x => x.Id, model.Id); + var category = categories.FindOneAndDelete(filter); + return category?.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarMongoDB/Implements/CookStorage.cs b/SushiBar/SushiBarMongoDB/Implements/CookStorage.cs new file mode 100644 index 0000000..c74f5cc --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Implements/CookStorage.cs @@ -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 GetFullList() + { + using var context = new SushiBarMongoDB(); + var cooks = context.GetCollection("Cooks"); + return cooks.Find(Builders.Filter.Empty) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + public List GetFilteredList(CookSearchModel model) + { + if (string.IsNullOrEmpty(model.CookName)) + { + return new List(); + } + using var context = new SushiBarMongoDB(); + var cooks = context.GetCollection("Cooks"); + + var filterBuilder = Builders.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("Cooks"); + + var filterBuilder = Builders.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("Cooks"); + + model.Id = (int)cooks.CountDocuments(FilterDefinition.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("Cooks"); + + var filter = Builders.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("Cooks"); + + var filter = Builders.Filter.Eq(x => x.Id, model.Id); + var cook = cooks.FindOneAndDelete(filter); + return cook?.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarMongoDB/Implements/MenuStorage.cs b/SushiBar/SushiBarMongoDB/Implements/MenuStorage.cs new file mode 100644 index 0000000..84e748c --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Implements/MenuStorage.cs @@ -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("Menus") + .DeleteMany(Builders.Filter.Empty); + } + public MenuViewModel? GetElement(MenuSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using (var context = new SushiBarMongoDB()) + { + var menus = context.GetCollection("Menus"); + + var filterBuilder = Builders.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 GetFilteredList(MenuSearchModel model) + { + if (string.IsNullOrEmpty(model.FoodName)) + { + return new List(); + } + using var context = new SushiBarMongoDB(); + var menus = context.GetCollection("Menus"); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder + .Regex(x => x.FoodName, new BsonRegularExpression(model.FoodName)); + return menus + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SushiBarMongoDB(); + var menus = context.GetCollection("Menus"); + return menus.Find(Builders.Filter.Empty) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public MenuViewModel? Insert(MenuBindingModel model) + { + using var context = new SushiBarMongoDB(); + + var menus = context.GetCollection("Menus"); + + model.Id = (int)menus.CountDocuments(FilterDefinition.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("Menus"); + + var filter = Builders.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("Menus"); + + var filter = Builders.Filter.Eq(x => x.Id, model.Id); + var menu = menus.FindOneAndDelete(filter); + return menu?.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarMongoDB/Implements/PlaceStorage.cs b/SushiBar/SushiBarMongoDB/Implements/PlaceStorage.cs new file mode 100644 index 0000000..b7e3a61 --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Implements/PlaceStorage.cs @@ -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("Places") + .DeleteMany(Builders.Filter.Empty); + } + + public PlaceViewModel? GetElement(PlaceSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + using (var context = new SushiBarMongoDB()) + { + var places = context.GetCollection("Places"); + + var filterBuilder = Builders.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 GetFilteredList(PlaceSearchModel model) + { + if (!model.PlaceNumber.HasValue) + { + return new List(); + } + using var context = new SushiBarMongoDB(); + var places = context.GetCollection("Places"); + + var filter = Builders.Filter.Eq(x => x.Id, model.Id); + return places + .Find(filter) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFullList() + { + using var context = new SushiBarMongoDB(); + var places = context.GetCollection("Places"); + return places.Find(Builders.Filter.Empty) + .ToList() + .Select(x => x.GetViewModel) + .ToList(); + } + + public PlaceViewModel? Insert(PlaceBindingModel model) + { + using var context = new SushiBarMongoDB(); + + var places = context.GetCollection("Places"); + + model.Id = (int)places.CountDocuments(FilterDefinition.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("Places"); + + var filter = Builders.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("Places"); + + var filter = Builders.Filter.Eq(x => x.Id, model.Id); + var place = places.FindOneAndDelete(filter); + return place?.GetViewModel; + } + } +} diff --git a/SushiBar/SushiBarMongoDB/Implements/TaskStorage.cs b/SushiBar/SushiBarMongoDB/Implements/TaskStorage.cs new file mode 100644 index 0000000..edb98a6 --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Implements/TaskStorage.cs @@ -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("Tasks") + .DeleteMany(Builders.Filter.Empty); + } + + public List GetFullList() + { + using var context = new SushiBarMongoDB(); + var tasks = context.GetCollection("Tasks").Find(Builders.Filter.Empty).ToList(); + + return tasks.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(TaskSearchModel model) + { + using var context = new SushiBarMongoDB(); + if(!model.Id.HasValue) return new List(); + + var filterBuilder = Builders.Filter; + var filter = filterBuilder.Empty; + filter = filterBuilder.Eq("Id", model.Id); + + var tasks = context.GetCollection("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("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("Tasks"); + + model.Id = (int)tasks.CountDocuments(FilterDefinition.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("Tasks").Find(x => x.Id == model.Id).FirstOrDefault(); + if (task == null) return null; + task.Update(model); + context.GetCollection("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("Tasks").Find(x => x.Id == model.Id).FirstOrDefault(); + if (element != null) + { + context.GetCollection("Tasks").DeleteOne(x => x.Id == model.Id); + return element.GetViewModel; + } + return null; + } + } +} diff --git a/SushiBar/SushiBarMongoDB/Models/Buyer.cs b/SushiBar/SushiBarMongoDB/Models/Buyer.cs new file mode 100644 index 0000000..2e068f0 --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Models/Buyer.cs @@ -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, + }; + } +} diff --git a/SushiBar/SushiBarMongoDB/Models/Cook.cs b/SushiBar/SushiBarMongoDB/Models/Cook.cs new file mode 100644 index 0000000..7a11a5b --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Models/Cook.cs @@ -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 + }; + } +} diff --git a/SushiBar/SushiBarMongoDB/Models/Menu.cs b/SushiBar/SushiBarMongoDB/Models/Menu.cs new file mode 100644 index 0000000..cda3d69 --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Models/Menu.cs @@ -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, + }; + } +} diff --git a/SushiBar/SushiBarMongoDB/Models/Place.cs b/SushiBar/SushiBarMongoDB/Models/Place.cs new file mode 100644 index 0000000..c3f2c1b --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Models/Place.cs @@ -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, + }; + } +} diff --git a/SushiBar/SushiBarMongoDB/Models/Task.cs b/SushiBar/SushiBarMongoDB/Models/Task.cs new file mode 100644 index 0000000..02a7a4d --- /dev/null +++ b/SushiBar/SushiBarMongoDB/Models/Task.cs @@ -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 MenuIds { get; set; } = new List(); + + [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 Menus { get; set; } + + [BsonIgnore] + public Dictionary TaskMenus { get; set; } = new Dictionary(); + + 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, + }; + } +} diff --git a/SushiBar/SushiBarMongoDB/SushiBarMongoDB.cs b/SushiBar/SushiBarMongoDB/SushiBarMongoDB.cs new file mode 100644 index 0000000..51143cb --- /dev/null +++ b/SushiBar/SushiBarMongoDB/SushiBarMongoDB.cs @@ -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 GetCollection(string collectionName) + { + return _database.GetCollection(collectionName); + } + + public void Dispose() { } + } +} diff --git a/SushiBar/SushiBarMongoDB/SushiBarMongoDB.csproj b/SushiBar/SushiBarMongoDB/SushiBarMongoDB.csproj new file mode 100644 index 0000000..a4ea3b6 --- /dev/null +++ b/SushiBar/SushiBarMongoDB/SushiBarMongoDB.csproj @@ -0,0 +1,24 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + + + +