diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyDatabase.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyDatabase.cs index 68b5574..67a30d2 100644 --- a/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyDatabase.cs +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyDatabase.cs @@ -83,6 +83,12 @@ namespace ConstructionCompanyMongoDBImplement } return _instance; } + public BsonDocument ReadDocument(BsonDocument filter, string collectionName) + { + var collection = client.GetDatabase(databaseName).GetCollection(collectionName); + BsonDocument result = collection.Find(filter).ToList()[0]; + return result; + } public void InsertDocument(BsonDocument bson, string collectionName) { @@ -168,7 +174,8 @@ namespace ConstructionCompanyMongoDBImplement } string? customerNumber = order[5].ToString(); DateTime dateBegin = order[6].ToUniversalTime(); - DateTime dateEnd = order[7].ToUniversalTime(); + DateTime? dateEnd = null; + if (order[7].ToString().Length > 5) dateEnd = order[7].ToUniversalTime(); Order? newOrder = Order.Create(new OrderBindingModel { Id = id, Description = description, Adress = adress, Price = price, Status = orderStatus, CustomerNumber = customerNumber, DateBegin = dateBegin, DateEnd = dateEnd }); if (newOrder != null) _orders.Add(newOrder); @@ -186,6 +193,7 @@ namespace ConstructionCompanyMongoDBImplement int materialId = material[0].ToInt32(); int quantity = material[1].ToInt32(); MaterialOrder? materialOrder = MaterialOrder.Create(new MaterialOrderBindingModel { MaterialId = materialId, OrderId = id, Quantity = quantity }, _materials, _orders); + if (materialOrder != null) _materialOrders.Add(materialOrder); } } } diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyMongoDBImplement.csproj b/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyMongoDBImplement.csproj index 2c6cff1..3564930 100644 --- a/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyMongoDBImplement.csproj +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/ConstructionCompanyMongoDBImplement.csproj @@ -6,10 +6,6 @@ enable - - - - diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/EmployeeOrderStorage.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/EmployeeOrderStorage.cs new file mode 100644 index 0000000..33afb08 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/EmployeeOrderStorage.cs @@ -0,0 +1,111 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using ConstructionCompanyMongoDBImplement.Models; +using MongoDB.Bson; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyMongoDBImplement.Implements +{ + public class EmployeeOrderStorage : IEmployeeOrderStorage + { + private readonly ConstructionCompanyDatabase _source; + public EmployeeOrderStorage() + { + _source = ConstructionCompanyDatabase.GetInstance(); + } + public List GetFullList() + { + List result = new List(); + foreach (var material in _source.EmployeeOrders) + { + result.Add(material.GetViewModel); + } + return result; + } + + public List GetFilteredList(EmployeeOrderSearchModel model) + { + if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue) + { + return new(); + } + List result = new List(); + foreach (var material in _source.EmployeeOrders) + { + if (material.EmployeeId == model.EmployeeId && material.OrderId == model.OrderId) result.Add(material.GetViewModel); + } + return result; + } + + public EmployeeOrderViewModel? GetElement(EmployeeOrderSearchModel model) + { + if (model == null || !model.OrderId.HasValue || !model.EmployeeId.HasValue) + { + return new(); + } + return _source.EmployeeOrders.FirstOrDefault(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId)?.GetViewModel; + } + + public EmployeeOrderViewModel? Insert(EmployeeOrderBindingModel model) + { + var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders"); + var employeeIds = order[8].AsBsonArray; + var materials = order[9].AsBsonArray; + employeeIds.Add(model.EmployeeId); + var orderView = _source.Orders.First(x => x.Id == model.OrderId); + OrderBindingModel orderModel = new OrderBindingModel + { + Id = orderView.Id, + Description = orderView.Description, + Adress = orderView.Adress, + Price = orderView.Price, + Status = orderView.Status, + CustomerNumber = orderView.CustomerNumber, + DateBegin = orderView.DateBegin, + DateEnd = orderView.DateEnd, + }; + var document = Order.UpdateBSON(orderModel, employeeIds, materials); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId} }, "Orders"); + var newEmployeeOrder = _source.EmployeeOrders[_source.EmployeeOrders.Count - 1]; + return newEmployeeOrder.GetViewModel; + } + + public EmployeeOrderViewModel? Delete(EmployeeOrderBindingModel model) + { + var deletedEmployeeOrder = _source.EmployeeOrders.First(x => x.EmployeeId == model.EmployeeId && x.OrderId == model.OrderId).GetViewModel; + var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders"); + var employeeIds = order[8].AsBsonArray; + var materials = order[9].AsBsonArray; + employeeIds.Remove(model.EmployeeId); + var orderView = _source.Orders.First(x => x.Id == model.OrderId); + OrderBindingModel orderModel = new OrderBindingModel + { + Id = orderView.Id, + Description = orderView.Description, + Adress = orderView.Adress, + Price = orderView.Price, + Status = orderView.Status, + CustomerNumber = orderView.CustomerNumber, + DateBegin = orderView.DateBegin, + DateEnd = orderView.DateEnd, + }; + var document = Order.UpdateBSON(orderModel, employeeIds, materials); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId } }, "Orders"); + return deletedEmployeeOrder; + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/EmployeeStorage.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/EmployeeStorage.cs new file mode 100644 index 0000000..6f5584d --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/EmployeeStorage.cs @@ -0,0 +1,102 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using ConstructionCompanyMongoDBImplement.Models; +using MongoDB.Bson; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyMongoDBImplement.Implements +{ + public class EmployeeStorage : IEmployeeStorage + { + private readonly ConstructionCompanyDatabase _source; + private readonly IPositionStorage _positionStorage; + public EmployeeStorage(IPositionStorage positionStorage) + { + _source = ConstructionCompanyDatabase.GetInstance(); + _positionStorage = positionStorage; + } + public List GetFullList() + { + List result = new List(); + foreach (var material in _source.Employees) + { + result.Add(material.GetViewModel); + } + return result; + } + + public List GetFilteredList(EmployeeSearchModel model) + { + if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.EmployeeName)) + { + return new(); + } + List result = new List(); + if (!string.IsNullOrEmpty(model.EmployeeName)) + { + foreach (var material in _source.Employees) + { + if (material.EmployeeName.Equals(model.EmployeeName)) result.Add(material.GetViewModel); + } + return result; + } + else + { + foreach (var material in _source.Employees) + { + if (material.Id == model.Id) result.Add(material.GetViewModel); + } + return result; + } + } + + public EmployeeViewModel? GetElement(EmployeeSearchModel model) + { + if (model == null || !model.Id.HasValue) + { + return new(); + } + return _source.Employees.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public EmployeeViewModel? Insert(EmployeeBindingModel model) + { + model.Id = _source.Employees.Count > 0 ? _source.Employees.Max(x => x.Id) + 1 : 0; + var document = Employee.CreateBSON(model); + if (document == null) + { + return null; + } + _source.InsertDocument(document, "Employees"); + var newEmployee = _source.Employees[_source.Employees.Count - 1]; + return newEmployee.GetViewModel; + } + + public EmployeeViewModel? Update(EmployeeBindingModel model) + { + var document = Employee.UpdateBSON(model); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { { "_id", model.Id } }, "Employees"); + var position = _source.Positions.First(x => x.Id == model.PositionID); + _positionStorage.Update(new PositionBindingModel { Id = position.Id, PositionName = position.PositionName, Salary = position.Salary }); + var updatedEmployee = _source.Employees.First(x => x.Id == model.Id); + return updatedEmployee.GetViewModel; + } + + public EmployeeViewModel? Delete(EmployeeBindingModel model) + { + var deletedEmployee = _source.Employees.First(x => x.Id == model.Id).GetViewModel; + _source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Employees"); + return deletedEmployee; + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/MaterialOrderStorage.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/MaterialOrderStorage.cs new file mode 100644 index 0000000..4c2ed5d --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/MaterialOrderStorage.cs @@ -0,0 +1,111 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using ConstructionCompanyMongoDBImplement.Models; +using MongoDB.Bson; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyMongoDBImplement.Implements +{ + public class MaterialOrderStorage : IMaterialOrderStorage + { + private readonly ConstructionCompanyDatabase _source; + public MaterialOrderStorage() + { + _source = ConstructionCompanyDatabase.GetInstance(); + } + public List GetFullList() + { + List result = new List(); + foreach (var material in _source.MaterialOrders) + { + result.Add(material.GetViewModel); + } + return result; + } + + public List GetFilteredList(MaterialOrderSearchModel model) + { + if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue) + { + return new(); + } + List result = new List(); + foreach (var material in _source.MaterialOrders) + { + if (material.MaterialId == model.MaterialId && material.OrderId == model.OrderId) result.Add(material.GetViewModel); + } + return result; + } + + public MaterialOrderViewModel? GetElement(MaterialOrderSearchModel model) + { + if (model == null || !model.OrderId.HasValue || !model.MaterialId.HasValue) + { + return new(); + } + return _source.MaterialOrders.FirstOrDefault(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId)?.GetViewModel; + } + + public MaterialOrderViewModel? Insert(MaterialOrderBindingModel model) + { + var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders"); + var employeeIds = order[8].AsBsonArray; + var materials = order[9].AsBsonArray; + materials.Add(new BsonDocument {{"materialId", model.MaterialId}, {"quantity", model.Quantity}}); + var orderView = _source.Orders.First(x => x.Id == model.OrderId); + OrderBindingModel orderModel = new OrderBindingModel + { + Id = orderView.Id, + Description = orderView.Description, + Adress = orderView.Adress, + Price = orderView.Price, + Status = orderView.Status, + CustomerNumber = orderView.CustomerNumber, + DateBegin = orderView.DateBegin, + DateEnd = orderView.DateEnd, + }; + var document = Order.UpdateBSON(orderModel, employeeIds, materials); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId } }, "Orders"); + var newMaterialOrder = _source.MaterialOrders[_source.MaterialOrders.Count - 1]; + return newMaterialOrder.GetViewModel; + } + + public MaterialOrderViewModel? Delete(MaterialOrderBindingModel model) + { + var deletedMaterialOrder = _source.MaterialOrders.First(x => x.MaterialId == model.MaterialId && x.OrderId == model.OrderId).GetViewModel; + var order = _source.ReadDocument(new BsonDocument { { "_id", model.OrderId } }, "Orders"); + var employeeIds = order[8].AsBsonArray; + var materials = order[9].AsBsonArray; + employeeIds.Remove(new BsonDocument {{"materialId", model.MaterialId}, {"quantity", model.Quantity}}); + var orderView = _source.Orders.First(x => x.Id == model.OrderId); + OrderBindingModel orderModel = new OrderBindingModel + { + Id = orderView.Id, + Description = orderView.Description, + Adress = orderView.Adress, + Price = orderView.Price, + Status = orderView.Status, + CustomerNumber = orderView.CustomerNumber, + DateBegin = orderView.DateBegin, + DateEnd = orderView.DateEnd, + }; + var document = Order.UpdateBSON(orderModel, employeeIds, materials); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { { "_id", model.OrderId } }, "Orders"); + return deletedMaterialOrder; + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/MaterialStorage.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/MaterialStorage.cs new file mode 100644 index 0000000..d988169 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/MaterialStorage.cs @@ -0,0 +1,113 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using ConstructionCompanyMongoDBImplement.Models; +using MongoDB.Bson; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyMongoDBImplement.Implements +{ + public class MaterialStorage : IMaterialStorage + { + private readonly ConstructionCompanyDatabase _source; + public MaterialStorage() + { + _source = ConstructionCompanyDatabase.GetInstance(); + } + public List GetFullList() + { + List result = new List(); + foreach (var material in _source.Materials) + { + result.Add(material.GetViewModel); + } + return result; + } + + public List GetFilteredList(MaterialSearchModel model) + { + if (model == null || !model.Id.HasValue || string.IsNullOrEmpty(model.MaterialName)) + { + return new(); + } + List result = new List(); + if (!string.IsNullOrEmpty(model.MaterialName)) + { + foreach (var material in _source.Materials) + { + if (material.MaterialName.Equals(model.MaterialName)) result.Add(material.GetViewModel); + } + return result; + } + else + { + foreach (var material in _source.Materials) + { + if (material.Id == model.Id) result.Add(material.GetViewModel); + } + return result; + } + } + + public MaterialViewModel? GetElement(MaterialSearchModel model) + { + if (model == null || !model.Id.HasValue) + { + return new(); + } + return _source.Materials.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public MaterialViewModel? Insert(MaterialBindingModel model) + { + model.Id = _source.Materials.Count > 0 ? _source.Materials.Max(x => x.Id) + 1 : 0; + var document = Material.CreateBSON(model); + if (document == null) + { + return null; + } + _source.InsertDocument(document, "Materials"); + var newMaterial = _source.Materials[_source.Materials.Count - 1]; + return newMaterial.GetViewModel; + } + + public MaterialViewModel? Update(MaterialBindingModel model) + { + var document = Material.UpdateBSON(model); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { { "_id", model.Id } }, "Materials"); + var updatedMaterial = _source.Materials.First(x => x.Id == model.Id); + return updatedMaterial.GetViewModel; + } + + public MaterialViewModel? Delete(MaterialBindingModel model) + { + var deletedMaterial = _source.Materials.First(x => x.Id == model.Id).GetViewModel; + _source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Materials"); + return deletedMaterial; + } + public List? GetEmployeesUsingMaterial(MaterialBindingModel model) + { + //var command = Material.GetEmployeeCommand(model); + //if (string.IsNullOrEmpty(command)) + //{ + // return null; + //} + //var employeesId = _source.ExecuteReader(command, 1); + List employees = new List(); + //foreach (var id in employeesId) + //{ + // employees.Add(_source.Employees.First(x => x.Id == Convert.ToInt32(id[0])).GetViewModel); + //} + return employees; + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/OrderStorage.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..43b62fd --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/OrderStorage.cs @@ -0,0 +1,90 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using ConstructionCompanyMongoDBImplement.Models; +using MongoDB.Bson; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyMongoDBImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly ConstructionCompanyDatabase _source; + public OrderStorage() + { + _source = ConstructionCompanyDatabase.GetInstance(); + } + public List GetFullList() + { + List result = new List(); + foreach (var material in _source.Orders) + { + result.Add(material.GetViewModel); + } + return result; + } + + public List GetFilteredList(OrderSearchModel model) + { + if (model == null || !model.Id.HasValue) + { + return new(); + } + List result = new List(); + foreach (var material in _source.Orders) + { + if (material.Id == model.Id) result.Add(material.GetViewModel); + } + return result; + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (model == null || !model.Id.HasValue) + { + return new(); + } + return _source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = _source.Orders.Count > 0 ? _source.Orders.Max(x => x.Id) + 1 : 0; + var document = Order.CreateBSON(model); + if (document == null) + { + return null; + } + _source.InsertDocument(document, "Orders"); + var newOrder = _source.Orders[_source.Orders.Count - 1]; + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = _source.ReadDocument(new BsonDocument { { "_id", model.Id } }, "Orders"); + var employeeIds = order[8].AsBsonArray; + var materials = order[9].AsBsonArray; + var document = Order.UpdateBSON(model, employeeIds, materials); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { { "_id", model.Id} }, "Orders"); + var updatedOrder = _source.Orders.First(x => x.Id == model.Id); + return updatedOrder.GetViewModel; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + var deletedOrder = _source.Orders.First(x => x.Id == model.Id).GetViewModel; + _source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Orders"); + return deletedOrder; + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/PositionStorage.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/PositionStorage.cs new file mode 100644 index 0000000..84e2902 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Implements/PositionStorage.cs @@ -0,0 +1,117 @@ +using Amazon.Auth.AccessControlPolicy; +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.SearchModels; +using ConstructionCompanyContracts.StorageContracts; +using ConstructionCompanyContracts.ViewModels; +using ConstructionCompanyMongoDBImplement.Models; +using MongoDB.Bson; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyMongoDBImplement.Implements +{ + public class PositionStorage : IPositionStorage + { + private readonly ConstructionCompanyDatabase _source; + public PositionStorage() + { + _source = ConstructionCompanyDatabase.GetInstance(); + } + public List GetFullList() + { + List result = new List(); + foreach (var material in _source.Positions) + { + result.Add(material.GetViewModel); + } + return result; + } + + public List GetFilteredList(PositionSearchModel model) + { + if (model == null || !model.Id.HasValue && string.IsNullOrEmpty(model.PositionName)) + { + return new(); + } + List result = new List(); + if (!string.IsNullOrEmpty(model.PositionName)) + { + foreach (var material in _source.Positions) + { + if (material.PositionName.Equals(model.PositionName)) result.Add(material.GetViewModel); + } + return result; + } + else + { + foreach (var material in _source.Positions) + { + if (material.Id == model.Id) result.Add(material.GetViewModel); + } + return result; + } + } + + public PositionViewModel? GetElement(PositionSearchModel model) + { + if (model == null || !model.Id.HasValue) + { + return new(); + } + return _source.Positions.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + + public PositionViewModel? Insert(PositionBindingModel model) + { + model.Id = _source.Positions.Count > 0 ? _source.Positions.Max(x => x.Id) + 1 : 0; + var document = Position.CreateBSON(model); + if (document == null) + { + return null; + } + _source.InsertDocument(document, "Positions"); + var newPosition = _source.Positions[_source.Positions.Count - 1]; + return newPosition.GetViewModel; + } + + public PositionViewModel? Update(PositionBindingModel model) + { + List ids = new List(); + foreach (var employee in _source.Employees) + { + if (employee.PositionID == model.Id) ids.Add(employee.Id); + } + var document = Position.UpdateBSON(model, ids); + if (document == null) + { + return null; + } + _source.ReplaceDocument(document, new BsonDocument { {"_id" , model.Id} }, "Positions"); + var updatedPosition = _source.Positions.First(x => x.Id == model.Id); + return updatedPosition.GetViewModel; + } + + public PositionViewModel? Delete(PositionBindingModel model) + { + var deletedPosition = _source.Positions.First(x => x.Id == model.Id).GetViewModel; + _source.DeleteDocument(new BsonDocument { { "_id", model.Id } }, "Positions"); + return deletedPosition; + } + + public List GetPositionsAverage(DateTime dateFrom, DateTime dateTo) + { + //var command = Position.PositionsAVGCommnad(dateFrom, dateTo); + //var result = _source.ExecuteReader(command, 2); + List positionsAverages = new List(); + //foreach (var posAvgPair in result) + //{ + // string positionName = _source.Positions.First(x => x.Id == Convert.ToInt32(posAvgPair[0])).PositionName; + // positionsAverages.Add(new BrigadeReportViewModel { PositionId = Convert.ToInt32(posAvgPair[0]), PositionName = positionName, materialAvg = Convert.ToDouble(posAvgPair[1]) }); + //} + return positionsAverages; + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Employee.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Employee.cs index 48c1b0e..8d8f60f 100644 --- a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Employee.cs +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Employee.cs @@ -1,4 +1,5 @@ using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.ViewModels; using ConstructionCompanyDataModels.Models; using MongoDB.Bson; using System; @@ -59,5 +60,12 @@ namespace ConstructionCompanyMongoDBImplement.Models {"positionId", $"{model.PositionID}" } }; } + public EmployeeViewModel GetViewModel => new() + { + Id = Id, + EmployeeName = EmployeeName, + PositionID = PositionID, + PositionName = Position.PositionName + }; } } diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Material.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Material.cs index 42a44ac..50f56b6 100644 --- a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Material.cs +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Material.cs @@ -1,4 +1,5 @@ using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.ViewModels; using ConstructionCompanyDataModels.Models; using MongoDB.Bson; using System; @@ -57,5 +58,12 @@ namespace ConstructionCompanyMongoDBImplement.Models {"quantity", $"{model.Quantity}" } }; } + + public MaterialViewModel GetViewModel => new() + { + Id = Id, + MaterialName = MaterialName, + Quantity = Quantity + }; } } diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Order.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Order.cs index b916f82..d56bdf5 100644 --- a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Order.cs +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Order.cs @@ -1,4 +1,5 @@ using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.ViewModels; using ConstructionCompanyDataModels.Enums; using MongoDB.Bson; using MongoDB.Driver; @@ -54,11 +55,11 @@ namespace ConstructionCompanyMongoDBImplement.Models {"_id", model.Id}, {"description", $"{model.Description}"}, {"adress", $"{model.Adress}"}, - {"customerNumber", $"{model.CustomerNumber}"}, {"price", $"{model.Price}"}, {"status", $"{model.Status}"}, - {"dateBegin", $"{model.DateBegin}"}, - {"dateEnd", $"{model.DateEnd}"}, + {"customerNumber", $"{model.CustomerNumber}"}, + {"dateBegin", new BsonDateTime(model.DateBegin)}, + {"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""}, {"employeesId", new BsonArray() }, {"materials", new BsonArray()} }; @@ -75,14 +76,26 @@ namespace ConstructionCompanyMongoDBImplement.Models {"_id", model.Id}, {"description", $"{model.Description}"}, {"adress", $"{model.Adress}"}, - {"customerNumber", $"{model.CustomerNumber}"}, {"price", $"{model.Price}"}, {"status", $"{model.Status}"}, - {"dateBegin", $"{model.DateBegin}"}, - {"dateEnd", $"{model.DateEnd}"}, + {"customerNumber", $"{model.CustomerNumber}"}, + {"dateBegin", new BsonDateTime(model.DateBegin)}, + {"dateEnd", model.DateEnd.HasValue ? new BsonDateTime(model.DateEnd.Value) : ""}, {"employeesId", employeesId }, {"materials", materials} }; } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + Description = Description, + Adress = Adress, + CustomerNumber = CustomerNumber, + Price = Price, + Status = Status, + DateBegin = DateBegin, + DateEnd = DateEnd + }; } } diff --git a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Position.cs b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Position.cs index a375379..0d9fe55 100644 --- a/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Position.cs +++ b/ConstructionCompany/ConstructionCompanyMongoDBImplement/Models/Position.cs @@ -48,7 +48,7 @@ namespace ConstructionCompanyMongoDBImplement.Models }; } - public static BsonDocument? UpdateBSON(PositionBindingModel? model, List ids) + public static BsonDocument? UpdateBSON(PositionBindingModel? model, List ids) { if (model == null) { diff --git a/ConstructionCompany/ConstructionCompanyView/Program.cs b/ConstructionCompany/ConstructionCompanyView/Program.cs index d0d191f..4647445 100644 --- a/ConstructionCompany/ConstructionCompanyView/Program.cs +++ b/ConstructionCompany/ConstructionCompanyView/Program.cs @@ -1,7 +1,7 @@ using ConstructionCompanyBusinessLogic.BusinessLogics; using ConstructionCompanyContracts.BusinessLogicContracts; using ConstructionCompanyContracts.StorageContracts; -using ConstructionCompanyPsqlImplement.Implements; +using ConstructionCompanyMongoDBImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging;