Перенес на MongoDB Branches(филиалы)

This commit is contained in:
Danil Markov 2023-05-08 15:25:26 +04:00
parent daafb6f99f
commit 742434cc5d
36 changed files with 952 additions and 49 deletions

View File

@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRentBusinessLogic", "Car
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRentDatabase", "CarRentDatabase\CarRentDatabase.csproj", "{01667A54-719D-414B-B05F-1B3693971136}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRent", "CarRent\CarRent.csproj", "{19934FD6-266C-4824-8FC8-4895095C3EDF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CarRent", "CarRent\CarRent.csproj", "{19934FD6-266C-4824-8FC8-4895095C3EDF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRentMongoDB", "CarRentMongoDB\CarRentMongoDB.csproj", "{698D9643-EA17-44DD-9D83-D623DBB6B70F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{19934FD6-266C-4824-8FC8-4895095C3EDF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{19934FD6-266C-4824-8FC8-4895095C3EDF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{19934FD6-266C-4824-8FC8-4895095C3EDF}.Release|Any CPU.Build.0 = Release|Any CPU
{698D9643-EA17-44DD-9D83-D623DBB6B70F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{698D9643-EA17-44DD-9D83-D623DBB6B70F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{698D9643-EA17-44DD-9D83-D623DBB6B70F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{698D9643-EA17-44DD-9D83-D623DBB6B70F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -20,6 +20,7 @@
<ProjectReference Include="..\CarRentBusinessLogic\CarRentBusinessLogic.csproj" />
<ProjectReference Include="..\CarRentContracts\CarRentContracts.csproj" />
<ProjectReference Include="..\CarRentDatabase\CarRentDatabase.csproj" />
<ProjectReference Include="..\CarRentMongoDB\CarRentMongoDB.csproj" />
</ItemGroup>
</Project>

View File

@ -34,10 +34,10 @@ namespace CarRent
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ObjectId"].Visible = false;
}
}
catch (Exception ex)
{ }
catch (Exception){ }
}
private void FormBranches_Load(object sender, EventArgs e)
{
@ -81,14 +81,14 @@ namespace CarRent
{
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
int? id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
string? objectId = dataGridView.SelectedRows[0].Cells["Id"].Value.ToString();
try
{
if (!_branchLogic.Delete(new BranchBindingModel
{
Id = id
}))
if (Program.CURRENT_DATABASE.Equals("PostgreSQL")
&& !_branchLogic.Delete(new BranchBindingModel{ Id = id ?? 0})
|| !_branchLogic.Delete(new BranchBindingModel { ObjectId = objectId ?? string.Empty }))
{
throw new Exception("Ошибка при удалении.");
}

View File

@ -33,7 +33,9 @@ namespace CarRent
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ObjectId"].Visible = false;
dataGridView.Columns["BranchId"].Visible = false;
dataGridView.Columns["BranchStringId"].Visible = false;
}
}
catch (Exception ex)

View File

@ -32,6 +32,7 @@ namespace CarRent
{
dataGridView.DataSource = list;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ObjectId"].Visible = false;
}
}
catch (Exception ex)

View File

@ -2,6 +2,7 @@
using CarRentContracts.BindingModels;
using CarRentContracts.BusinessLogicContracts;
using CarRentContracts.SearchModels;
using CarRentContracts.ViewModels;
using ClientRentBusinessLogic.BusinessLogics;
using System;
using System.Collections.Generic;
@ -22,6 +23,9 @@ namespace CarRent
private int? _id;
public int Id { set { _id = value; } }
private string? _objectId;
public string ObjectId { set { _objectId = value; } }
public FormCreateBranch(IBranchLogic branchLogic)
{
InitializeComponent();
@ -47,13 +51,28 @@ namespace CarRent
}
try
{
var model = new BranchBindingModel
BranchBindingModel model;
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
{
Id = _id ?? 0,
Name = textBoxName.Text,
PhoneNumber = textBoxPhoneNumber.Text,
Address = textBoxAddress.Text,
};
model = new BranchBindingModel
{
Id = _id ?? 0,
Name = textBoxName.Text,
PhoneNumber = textBoxPhoneNumber.Text,
Address = textBoxAddress.Text,
};
}
else
{
model = new BranchBindingModel
{
ObjectId = _objectId ?? string.Empty,
Name = textBoxName.Text,
PhoneNumber = textBoxPhoneNumber.Text,
Address = textBoxAddress.Text,
};
}
var operationResult = _id.HasValue ? _branchLogic.Update(model) : _branchLogic.Create(model);
@ -85,7 +104,15 @@ namespace CarRent
{
try
{
var view = _branchLogic.ReadElement(new BranchSearchModel { Id = _id.Value });
BranchViewModel? view;
if (Program.CURRENT_DATABASE.Equals("PostgreSQL"))
{
view = _branchLogic.ReadElement(new BranchSearchModel { Id = _id });
}
else
{
view = _branchLogic.ReadElement(new BranchSearchModel { ObjectId = _objectId });
}
if (view != null)
{

View File

@ -133,7 +133,7 @@ namespace CarRent
textBoxModel.Text = view.Model;
textBoxRentalCost.Text = view.RentalCostPerHour.ToString();
dateTimePicker.Value = view.YearOfManuf;
comboBoxBranch.SelectedIndex = view.BranchId;
comboBoxBranch.SelectedIndex = view.BranchId ?? 0;
}
}
catch (Exception ex)

View File

@ -51,13 +51,15 @@ namespace CarRent
{
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ClientStringId"].Visible = false;
dataGridView.Columns["CarId"].Visible = false;
dataGridView.Columns["CarStringId"].Visible = false;
dataGridView.Columns["Id"].Visible = false;
dataGridView.Columns["ObjectId"].Visible = false;
}
}
catch (Exception ex)
{}
catch (Exception) { }
}
private void LoadData(int id)
{
@ -66,9 +68,6 @@ namespace CarRent
ClientId = id,
});
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["CarId"].Visible = false;
dataGridView.Columns["Id"].Visible = false;
}
private void филиалыToolStripMenuItem_Click(object sender, EventArgs e)
{
@ -211,7 +210,7 @@ namespace CarRent
_carLogic.ClearEntity();
_rentalLogic.ClearEntity();
}
catch (Exception ex) { }
catch (Exception) { }
}
}
}

View File

@ -1,7 +1,7 @@
using CarRentBusinessLogic.BusinessLogics;
using CarRentContracts.BusinessLogicContracts;
using CarRentContracts.StoragesContracts;
using CarRentDatabase.Implements;
using CarRentMongoDB.Implements;
using ClientRentBusinessLogic.BusinessLogics;
using Microsoft.Extensions.DependencyInjection;
using System;
@ -10,6 +10,7 @@ namespace CarRent
{
internal static class Program
{
public static string CURRENT_DATABASE = "MongoDB";
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>

View File

@ -15,6 +15,8 @@ namespace CarRentContracts.BindingModels
public string PhoneNumber { get; set; } = string.Empty;
public int Id { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -20,7 +20,9 @@ namespace CarRentContracts.BindingModels
public string LicensePlate { get; set; } = string.Empty;
public double RentalCostPerHour { get; set; }
public int BranchId { get; set; }
public int Id { get; set; }
public int? BranchId { get; set; }
public string? BranchStringId { get; set; } = string.Empty;
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -19,6 +19,7 @@ namespace CarRentContracts.BindingModels
public string DriveLicenseNumber { get; set; } = string.Empty;
public int Id { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -18,9 +18,11 @@ namespace CarRentContracts.BindingModels
public string? ReviewText { get; set; } = string.Empty;
public int? ReviewRating { get; set; }
public int ClientId { get; set; }
public int CarId { get; set; }
public int Id { get; set; }
public int? ClientId { get; set; }
public string? ClientStringId { get; set; } = string.Empty;
public int? CarId { get; set; }
public string? CarStringId { get; set; } = string.Empty;
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -15,5 +15,7 @@ namespace CarRentContracts.SearchModels
public string? PhoneNumber { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; }
}
}

View File

@ -21,5 +21,6 @@ namespace CarRentContracts.SearchModels
public double? RentalCostPerHour { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; }
}
}

View File

@ -19,5 +19,6 @@ namespace CarRentContracts.SearchModels
public string? DriveLicenseNumber { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; }
}
}

View File

@ -20,5 +20,6 @@ namespace CarRentContracts.SearchModels
public int? ClientId { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; }
}
}

View File

@ -16,6 +16,7 @@ namespace CarRentContracts.ViewModels
public string Address { get; set; } = string.Empty;
[DisplayName("Номер телефона")]
public string PhoneNumber { get; set; } = string.Empty;
public int Id { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -1,4 +1,5 @@
using CarRentDataModels.Models;
using CarRentDataModels;
using CarRentDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -24,7 +25,9 @@ namespace CarRentContracts.ViewModels
public string LicensePlate { get; set; } = string.Empty;
[DisplayName("Цена аренды за час")]
public double RentalCostPerHour { get; set; }
public int BranchId { get; set; }
public int Id { get; set; }
public int? BranchId { get; set; }
public string? BranchStringId { get; set; } = string.Empty;
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -20,7 +20,7 @@ namespace CarRentContracts.ViewModels
public string Email { get; set; } = string.Empty;
[DisplayName("Номер водительских прав")]
public string DriveLicenseNumber { get; set; } = string.Empty;
public int Id { get; set; }
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -26,9 +26,11 @@ namespace CarRentContracts.ViewModels
public string? ReviewText { get; set; } = string.Empty;
[DisplayName("Оценка аренды")]
public int? ReviewRating { get; set; }
public int ClientId { get; set; }
public int CarId { get; set; }
public int Id { get; set; }
public int? ClientId { get; set; }
public string? ClientStringId { get; set; } = string.Empty;
public int? CarId { get; set; }
public string? CarStringId { get; set; } = string.Empty;
public int? Id { get; set; }
public string? ObjectId { get; set; } = string.Empty;
}
}

View File

@ -2,6 +2,7 @@
{
public interface IId
{
int Id { get; }
int? Id { get; }
string? ObjectId { get; }
}
}

View File

@ -15,13 +15,14 @@ namespace CarRentDatabase.Models
{
public class Branch : IBranchModel
{
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Address { get; set; } = string.Empty;
[Required]
public string PhoneNumber { get; set; } = string.Empty;
public int Id { get; private set; }
public int? Id { get; private set; }
[ForeignKey("BranchId")]
public virtual List<Car> Cars { get; set; } = new();
@ -56,5 +57,7 @@ namespace CarRentDatabase.Models
Address = Address,
PhoneNumber = PhoneNumber,
};
public string ObjectId => throw new NotImplementedException();
}
}

View File

@ -29,9 +29,9 @@ namespace CarRentDatabase.Models
public double RentalCostPerHour { get; set; }
[Required]
public int BranchId { get; set; }
public int? BranchId { get; set; }
public int Id { get; private set; }
public int? Id { get; private set; }
[ForeignKey("CarId")]
List<Rental> RentalCars { get; set; } = new();
@ -79,5 +79,7 @@ namespace CarRentDatabase.Models
BranchId = BranchId,
BranchName = Branch == null ? string.Empty : Branch.Name,
};
public string ObjectId => throw new NotImplementedException();
}
}

View File

@ -26,7 +26,7 @@ namespace CarRentDatabase.Models
public string DriveLicenseNumber { get; set; } = string.Empty;
[Required]
public int Id { get; private set; }
public int? Id { get; private set; }
[ForeignKey("ClientId")]
List<Rental> RentalClients { get; set; } = new();
@ -67,5 +67,7 @@ namespace CarRentDatabase.Models
Email = Email,
DriveLicenseNumber = DriveLicenseNumber,
};
public string ObjectId => throw new NotImplementedException();
}
}

View File

@ -22,11 +22,11 @@ namespace CarRentDatabase.Models
public string? ReviewText { get; set; }
public int? ReviewRating { get ; set; }
[Required]
public int ClientId { get; set; }
public int? ClientId { get; set; }
[Required]
public int CarId { get; set; }
public int? CarId { get; set; }
public int Id { get; private set; }
public int? Id { get; private set; }
public virtual Car Car { get; set; }
public virtual Client Client { get; set; }
@ -74,5 +74,7 @@ namespace CarRentDatabase.Models
ClientId = ClientId,
CarId = CarId,
};
public string ObjectId => throw new NotImplementedException();
}
}

View File

@ -0,0 +1,34 @@
using CarRentMongoDB.Models;
using Microsoft.Extensions.Options;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarRentMongoDB
{
public class CarRentMongoDB : IDisposable
{
private readonly MongoClient _client;
private readonly IMongoDatabase _database;
public CarRentMongoDB(string connectionString = "mongodb://localhost:27017",
string databaseName = "lab7SUBD")
{
_client = new MongoClient(connectionString);
_database = _client.GetDatabase(databaseName);
}
public IMongoCollection<T> GetCollection<T>(string collectionName)
{
return _database.GetCollection<T>(collectionName);
}
public void Dispose()
{
}
}
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
<PackageReference Include="MongoDB.Bson" Version="2.19.1" />
<PackageReference Include="MongoDB.Driver" Version="2.19.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CarRentContracts\CarRentContracts.csproj" />
<ProjectReference Include="..\CarRentDataModels\CarRentDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,129 @@
using Bogus;
using CarRentContracts.BindingModels;
using CarRentContracts.SearchModels;
using CarRentContracts.StoragesContracts;
using CarRentContracts.ViewModels;
using CarRentMongoDB.Models;
using MongoDB.Bson;
using MongoDB.Driver;
namespace CarRentMongoDB.Implements
{
public class BranchStorage : IBranchStorage
{
public void ClearEntity()
{
using var context = new CarRentMongoDB();
context.GetCollection<Branch>("Branches")
.DeleteMany(Builders<Branch>.Filter.Empty);
}
public void BranchInsertList(int num)
{
using var context = new CarRentMongoDB();
var faker = new Faker("ru");
for (int i = 0; i < num; ++i)
{
var model = new BranchBindingModel
{
ObjectId = string.Empty,
Name = faker.Company.CompanyName(),
Address = faker.Address.FullAddress(),
PhoneNumber = faker.Phone.PhoneNumber(),
};
context.GetCollection<Branch>("Branches")
.InsertOne(Branch.Create(model));
}
}
public BranchViewModel? GetElement(BranchSearchModel model)
{
if (string.IsNullOrEmpty(model.Name) && !model.ObjectId.Equals(string.Empty))
{
return null;
}
using (var context = new CarRentMongoDB())
{
var _branches = context.GetCollection<Branch>("Branches");
var filterBuilder = Builders<Branch>.Filter;
var filter = filterBuilder.Empty;
if (!string.IsNullOrEmpty(model.Name))
{
filter &= filterBuilder.Eq(x => x.Name, model.Name);
}
if (model.ObjectId.Equals(string.Empty))
{
filter &= filterBuilder.Eq(x => x.ObjectId, model.ObjectId);
}
return _branches.Find(filter)
.FirstOrDefault()
?.GetViewModel;
}
}
public List<BranchViewModel> GetFilteredList(BranchSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new List<BranchViewModel>();
}
using var context = new CarRentMongoDB();
var _branches = context.GetCollection<Branch>("Branches");
var filterBuilder = Builders<Branch>.Filter;
var filter = filterBuilder
.Regex(x => x.Name, new BsonRegularExpression(model.Name));
var branches = _branches
.Find(filter)
.ToList();
return branches.Select(x => x.GetViewModel).ToList();
}
public List<BranchViewModel> GetFullList()
{
using var context = new CarRentMongoDB();
var _branches = context.GetCollection<Branch>("Branches");
return _branches.Find(Builders<Branch>.Filter.Empty)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
public BranchViewModel? Insert(BranchBindingModel model)
{
using (var context = new CarRentMongoDB())
{
var _branches = context.GetCollection<Branch>("Branches");
var branch = Branch.Create(model);
_branches.InsertOne(branch);
return branch.GetViewModel;
}
}
public BranchViewModel? Update(BranchBindingModel model)
{
using var context = new CarRentMongoDB();
var _branches = context.GetCollection<Branch>("Branches");
var filter = Builders<Branch>.Filter.Eq(x => x.ObjectId, model.ObjectId);
var branch = _branches.Find(filter).FirstOrDefault();
if (branch == null)
{
return null;
}
branch.Update(model);
_branches.ReplaceOne(filter, branch);
return branch.GetViewModel;
}
public BranchViewModel? Delete(BranchBindingModel model)
{
using var context = new CarRentMongoDB();
var _branches = context.GetCollection<Branch>("Branches");
var filter = Builders<Branch>.Filter.Eq(x => x.ObjectId, model.ObjectId);
var branch = _branches.FindOneAndDelete(filter);
return branch?.GetViewModel;
}
}
}

View File

@ -0,0 +1,92 @@
using Bogus;
using CarRentContracts.BindingModels;
using CarRentContracts.SearchModels;
using CarRentContracts.StoragesContracts;
using CarRentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarRentMongoDB.Implements
{
public class CarStorage : ICarStorage
{
/*public void ClearEntity()
{
}
public CarViewModel? GetElement(CarSearchModel model)
{
}
public void CarInsertList(int num, List<BranchViewModel> branches)
{
}
public List<CarViewModel> GetFilteredList(CarSearchModel model)
{
}
public List<CarViewModel> GetFullList()
{
}
public CarViewModel? Insert(CarBindingModel model)
{
}
public CarViewModel? Update(CarBindingModel model)
{
}
public CarViewModel? Delete(CarBindingModel model)
{
}*/
public void CarInsertList(int num, List<BranchViewModel> branches)
{
throw new NotImplementedException();
}
public void ClearEntity()
{
throw new NotImplementedException();
}
public CarViewModel? Delete(CarBindingModel model)
{
throw new NotImplementedException();
}
public CarViewModel? GetElement(CarSearchModel model)
{
throw new NotImplementedException();
}
public List<CarViewModel> GetFilteredList(CarSearchModel model)
{
throw new NotImplementedException();
}
public List<CarViewModel> GetFullList()
{
throw new NotImplementedException();
}
public CarViewModel? Insert(CarBindingModel model)
{
throw new NotImplementedException();
}
public CarViewModel? Update(CarBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,93 @@
using CarRentContracts.BindingModels;
using CarRentContracts.SearchModels;
using CarRentContracts.StoragesContracts;
using CarRentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bogus;
namespace CarRentMongoDB.Implements
{
public class ClientStorage : IClientStorage
{
/*public void ClearEntity()
{
}
public void ClientInsertList(int num)
{
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
}
public List<ClientViewModel> GetFullList()
{
}
public ClientViewModel? Insert(ClientBindingModel model)
{
}
public ClientViewModel? Update(ClientBindingModel model)
{
}
public ClientViewModel? Delete(ClientBindingModel model)
{
}*/
public void ClearEntity()
{
throw new NotImplementedException();
}
public void ClientInsertList(int num)
{
throw new NotImplementedException();
}
public ClientViewModel? Delete(ClientBindingModel model)
{
throw new NotImplementedException();
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
throw new NotImplementedException();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
throw new NotImplementedException();
}
public List<ClientViewModel> GetFullList()
{
throw new NotImplementedException();
}
public ClientViewModel? Insert(ClientBindingModel model)
{
throw new NotImplementedException();
}
public ClientViewModel? Update(ClientBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,114 @@
using Bogus;
using CarRentContracts.BindingModels;
using CarRentContracts.SearchModels;
using CarRentContracts.StoragesContracts;
using CarRentContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarRentMongoDB.Implements
{
public class RentalStorage : IRentalStorage
{
/*public void ClearEntity()
{
}
public string TestInsertList(int num,
List<ClientViewModel> clients,
List<CarViewModel> cars)
{
}
public string TestReadList(int num)
{
}
public string TestJoinReadList(int num)
{
}
public RentalViewModel? GetElement(RentalSearchModel model)
{
}
public List<RentalViewModel> GetFilteredList(RentalSearchModel model)
{
}
public List<RentalViewModel> GetFullList()
{
}
public RentalViewModel? Insert(RentalBindingModel model)
{
}
public RentalViewModel? Update(RentalBindingModel model)
{
}
public RentalViewModel? Delete(RentalBindingModel model)
{
}*/
public void ClearEntity()
{
throw new NotImplementedException();
}
public RentalViewModel? Delete(RentalBindingModel model)
{
throw new NotImplementedException();
}
public RentalViewModel? GetElement(RentalSearchModel model)
{
throw new NotImplementedException();
}
public List<RentalViewModel> GetFilteredList(RentalSearchModel model)
{
throw new NotImplementedException();
}
public List<RentalViewModel> GetFullList()
{
throw new NotImplementedException();
}
public RentalViewModel? Insert(RentalBindingModel model)
{
throw new NotImplementedException();
}
public string TestInsertList(int num, List<ClientViewModel> clients, List<CarViewModel> cars)
{
throw new NotImplementedException();
}
public string TestJoinReadList(int num)
{
throw new NotImplementedException();
}
public string TestReadList(int num)
{
throw new NotImplementedException();
}
public RentalViewModel? Update(RentalBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -0,0 +1,70 @@
using CarRentContracts.BindingModels;
using CarRentContracts.ViewModels;
using CarRentDataModels.Models;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace CarRentMongoDB.Models
{
public class Branch : IBranchModel
{
[BsonId]
[BsonElement("_id")]
[BsonRepresentation(BsonType.ObjectId)]
public string? ObjectId { get; set; } = string.Empty;
[BsonRequired]
public string Name { get; set; } = string.Empty;
[BsonRequired]
public string Address { get; set; } = string.Empty;
[BsonRequired]
public string PhoneNumber { get; set; } = string.Empty;
public List<Car> Cars { get; set; } = new();
public static Branch? Create(BranchBindingModel model)
{
if (model == null)
{
return null;
}
return new Branch()
{
Name = model.Name,
Address = model.Address,
PhoneNumber = model.PhoneNumber,
};
}
public void Update(BranchBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Address = model.Address;
PhoneNumber = model.PhoneNumber;
}
public BranchViewModel GetViewModel => new()
{
ObjectId = ObjectId ?? string.Empty,
Name = Name,
Address = Address,
PhoneNumber = PhoneNumber,
};
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,105 @@
using CarRentContracts.BindingModels;
using CarRentContracts.ViewModels;
using CarRentDataModels.Models;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace CarRentMongoDB.Models
{
public class Car : ICarModel
{
[BsonId]
[BsonElement("_id")]
[BsonRepresentation(BsonType.ObjectId)]
public string? ObjectId { get; set; }
[BsonRequired]
public string Brand { get; set; } = string.Empty;
[BsonRequired]
public string Model { get; set; } = string.Empty;
[BsonRequired]
[BsonDateTimeOptions(Kind = DateTimeKind.Utc)]
public DateTime YearOfManuf { get; set; } = DateTime.MinValue.ToUniversalTime();
[BsonRequired]
public string Color { get; set; } = string.Empty;
[BsonRequired]
public string LicensePlate { get; set; } = string.Empty;
[BsonRequired]
public double RentalCostPerHour { get; set; }
[BsonRequired]
[BsonElement("branch_id")]
public string BranchStringId { get; set; }
[BsonRequired]
[BsonIgnoreIfNull]
public List<Rental> RentalCars { get; set; } = new List<Rental>();
[BsonRequired]
[BsonIgnoreIfNull]
public virtual Branch Branch { get; set; }
public static Car? Create(CarBindingModel model)
{
if (model == null)
{
return null;
}
return new Car()
{
Brand = model.Brand,
Model = model.Model,
YearOfManuf = model.YearOfManuf.ToUniversalTime(),
Color = model.Color,
LicensePlate = model.LicensePlate,
RentalCostPerHour = model.RentalCostPerHour,
BranchStringId = model.BranchStringId,
};
}
public void Update(CarBindingModel model)
{
if (model == null)
{
return;
}
Brand = model.Brand;
Model = model.Model;
YearOfManuf = model.YearOfManuf.ToUniversalTime();
Color = model.Color;
LicensePlate = model.LicensePlate;
RentalCostPerHour = model.RentalCostPerHour;
}
public CarViewModel GetViewModel => new()
{
ObjectId = ObjectId ?? string.Empty,
Brand = Brand,
Model = Model,
YearOfManuf = YearOfManuf,
Color = Color,
LicensePlate = LicensePlate,
RentalCostPerHour = RentalCostPerHour,
BranchStringId = BranchStringId,
BranchName = Branch?.Name ?? string.Empty,
};
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CarRentDataModels.Models;
using CarRentContracts.BindingModels;
using CarRentContracts.ViewModels;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
namespace CarRentMongoDB.Models
{
public class Client : IClientModel
{
[BsonId]
[BsonElement("_id")]
[BsonRepresentation(BsonType.ObjectId)]
public string? ObjectId { get; set; }
[BsonRequired]
public string Name { get; set; } = string.Empty;
[BsonRequired]
public string Surname { get; set; } = string.Empty;
[BsonRequired]
public string PhoneNumber { get; set; } = string.Empty;
[BsonRequired]
public string Email { get; set; } = string.Empty;
[BsonRequired]
public string DriveLicenseNumber { get; set; } = string.Empty;
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public List<Rental> RentalClients { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
{
return null;
}
return new Client()
{
Name = model.Name,
Surname = model.Surname,
PhoneNumber = model.PhoneNumber,
Email = model.Email,
DriveLicenseNumber = model.DriveLicenseNumber,
};
}
public void Update(ClientBindingModel model)
{
if (model == null)
{
return;
}
Name = model.Name;
Surname = model.Surname;
PhoneNumber = model.PhoneNumber;
Email = model.Email;
DriveLicenseNumber = model.DriveLicenseNumber;
}
public ClientViewModel GetViewModel => new()
{
ObjectId = ObjectId ?? string.Empty,
Name = Name,
Surname = Surname,
PhoneNumber = PhoneNumber,
Email = Email,
DriveLicenseNumber = DriveLicenseNumber,
};
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public int? Id { get; set; }
}
}

View File

@ -0,0 +1,98 @@
using CarRentContracts.BindingModels;
using CarRentContracts.BusinessLogicContracts;
using CarRentContracts.ViewModels;
using CarRentDataModels.Models;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CarRentMongoDB.Models
{
public class Rental : IRentalModel
{
[BsonId]
[BsonElement("_id")]
[BsonRepresentation(BsonType.ObjectId)]
public string? ObjectId { get; set; }
[BsonRequired]
[BsonElement("start_date")]
public DateTime StartDate { get; set; }
[BsonRequired]
[BsonElement("end_date")]
public DateTime? EndDate { get; set; }
[BsonRequired]
[BsonElement("rental_cost")]
public double RentalCost { get; set; }
[BsonElement("review_text")]
public string? ReviewText { get; set; }
[BsonElement("review_rating")]
public int? ReviewRating { get; set; }
[BsonRequired]
[BsonElement("client_id")]
public string? ClientStringId { get; set; }
[BsonRequired]
[BsonElement("car_id")]
public string? CarStringId { get; set; }
public virtual Car Car { get; set; }
public virtual Client Client { get; set; }
public static Rental? Create(RentalBindingModel? model)
{
if (model == null)
{
return null;
}
return new Rental()
{
StartDate = model.StartDate,
EndDate = model.EndDate,
RentalCost = model.RentalCost,
ReviewText = model.ReviewText,
ReviewRating = model.ReviewRating,
CarStringId = model.CarStringId,
ClientStringId = model.ClientStringId,
};
}
public void Update(RentalBindingModel? model)
{
if (model == null)
{
return;
}
ReviewText = model.ReviewText;
ReviewRating = model.ReviewRating;
}
public RentalViewModel GetViewModel => new()
{
ObjectId = ObjectId ?? string.Empty,
ClientName = Client == null ? string.Empty : Client.Name,
ClientSurname = Client == null ? string.Empty : Client.Surname,
LicensePlate = Car == null ? string.Empty : Car.LicensePlate,
StartDate = StartDate,
EndDate = EndDate,
RentalCost = RentalCost,
ReviewText = ReviewText,
ReviewRating = ReviewRating,
ClientStringId = ClientStringId,
CarStringId = CarStringId,
};
[BsonIgnoreIfNull]
[BsonIgnoreIfDefault]
public int? Id { get; set; }
}
}